diff --git a/common/concurrent_queue.cpp b/common/concurrent_queue.cpp index fa8eba24..a762f4db 100644 --- a/common/concurrent_queue.cpp +++ b/common/concurrent_queue.cpp @@ -59,7 +59,7 @@ std::size_t ConcurrentQueue::cancelPending() return size; } -void ConcurrentQueue::waitAll() +void ConcurrentQueue::waitAll() const { std::unique_lock lock(jobsLeftMutex); _waitVar.wait(lock, [this] { return jobsLeft == 0; }); diff --git a/common/concurrent_queue.h b/common/concurrent_queue.h index 4d3c4f23..380f6d5d 100644 --- a/common/concurrent_queue.h +++ b/common/concurrent_queue.h @@ -33,7 +33,7 @@ public: std::size_t cancelPending(); //! @brief Blocks the current thread until all enqueued jobs are completed. - void waitAll(); + void waitAll() const; private: //! @invariant all worker threads are joinable until the destructor is called. @@ -42,8 +42,8 @@ private: std::size_t jobsLeft = 0; //!< @invariant jobsLeft >= _queue.size() bool bailout = false; //!< @invariant is false until the destructor is called. std::condition_variable jobAvailableVar; - std::condition_variable _waitVar; - std::mutex jobsLeftMutex; + mutable std::condition_variable _waitVar; + mutable std::mutex jobsLeftMutex; std::mutex queueMutex; void nextJob(); diff --git a/tests/concurrent_queue_test/concurrent_queue_test.cpp b/tests/concurrent_queue_test/concurrent_queue_test.cpp index 11ce55b6..b09d05f6 100644 --- a/tests/concurrent_queue_test/concurrent_queue_test.cpp +++ b/tests/concurrent_queue_test/concurrent_queue_test.cpp @@ -202,7 +202,7 @@ std::size_t cancelAndPrint(ConcurrentQueue &queue, const QueueControlMessagePrin return canceledCount; } -void waitAndPrint(ConcurrentQueue &queue, const QueueControlMessagePrinter &printer) +void waitAndPrint(const ConcurrentQueue &queue, const QueueControlMessagePrinter &printer) { printer.printBeginWaitingMessage(); queue.waitAll();