mirror of
https://github.com/YACReader/yacreader
synced 2025-05-28 03:10:27 -04:00
Make ConcurrentQueue::waitAll() const
This member function does not affect the logical state of the class. Making std::condition_variable and std::mutex data members mutable is idiomatic as these classes are thread-safe synchronization primitives.
This commit is contained in:
parent
72c78d0164
commit
05b384ed6d
@ -59,7 +59,7 @@ std::size_t ConcurrentQueue::cancelPending()
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConcurrentQueue::waitAll()
|
void ConcurrentQueue::waitAll() const
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(jobsLeftMutex);
|
std::unique_lock<std::mutex> lock(jobsLeftMutex);
|
||||||
_waitVar.wait(lock, [this] { return jobsLeft == 0; });
|
_waitVar.wait(lock, [this] { return jobsLeft == 0; });
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
std::size_t cancelPending();
|
std::size_t cancelPending();
|
||||||
|
|
||||||
//! @brief Blocks the current thread until all enqueued jobs are completed.
|
//! @brief Blocks the current thread until all enqueued jobs are completed.
|
||||||
void waitAll();
|
void waitAll() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//! @invariant all worker threads are joinable until the destructor is called.
|
//! @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()
|
std::size_t jobsLeft = 0; //!< @invariant jobsLeft >= _queue.size()
|
||||||
bool bailout = false; //!< @invariant is false until the destructor is called.
|
bool bailout = false; //!< @invariant is false until the destructor is called.
|
||||||
std::condition_variable jobAvailableVar;
|
std::condition_variable jobAvailableVar;
|
||||||
std::condition_variable _waitVar;
|
mutable std::condition_variable _waitVar;
|
||||||
std::mutex jobsLeftMutex;
|
mutable std::mutex jobsLeftMutex;
|
||||||
std::mutex queueMutex;
|
std::mutex queueMutex;
|
||||||
|
|
||||||
void nextJob();
|
void nextJob();
|
||||||
|
@ -202,7 +202,7 @@ std::size_t cancelAndPrint(ConcurrentQueue &queue, const QueueControlMessagePrin
|
|||||||
return canceledCount;
|
return canceledCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitAndPrint(ConcurrentQueue &queue, const QueueControlMessagePrinter &printer)
|
void waitAndPrint(const ConcurrentQueue &queue, const QueueControlMessagePrinter &printer)
|
||||||
{
|
{
|
||||||
printer.printBeginWaitingMessage();
|
printer.printBeginWaitingMessage();
|
||||||
queue.waitAll();
|
queue.waitAll();
|
||||||
|
Loading…
Reference in New Issue
Block a user