From d026050d4907b4eba02833cd6a847a361b5d7705 Mon Sep 17 00:00:00 2001 From: Igor Kushnir Date: Tue, 16 Mar 2021 18:12:13 +0200 Subject: [PATCH] ConcurrentQueue::jobsLeft: int => std::size_t This data member's type can be unsigned because its value is never negative now. Matching std::queue::size_type allows to improve type safety, get rid of a static_cast and remove two assertions. The only downside is a slight increase of sizeof(ConcurrentQueue). --- common/concurrent_queue.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/common/concurrent_queue.h b/common/concurrent_queue.h index 506530ba..8cc8bf83 100644 --- a/common/concurrent_queue.h +++ b/common/concurrent_queue.h @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -60,9 +59,8 @@ public: } const auto size = oldQueue.size(); - assert(size <= std::numeric_limits::max()); if (size != 0) - finalizeJobs(static_cast(size)); + finalizeJobs(size); return size; } @@ -79,7 +77,7 @@ public: private: std::vector threads; std::queue> _queue; - int jobsLeft; //!< @invariant jobsLeft >= _queue.size() + std::size_t jobsLeft; //!< @invariant jobsLeft >= _queue.size() bool bailout; std::condition_variable jobAvailableVar; std::condition_variable _waitVar; @@ -115,11 +113,11 @@ private: } } - void finalizeJobs(int count) + void finalizeJobs(std::size_t count) { assert(count > 0); - int remainingJobs; + std::size_t remainingJobs; { std::lock_guard lock(jobsLeftMutex); assert(jobsLeft >= count); @@ -127,7 +125,6 @@ private: remainingJobs = jobsLeft; } - assert(remainingJobs >= 0); if (remainingJobs == 0) _waitVar.notify_all(); }