CppCommon 1.0.5.0
C++ Common Library
Loading...
Searching...
No Matches
wait_queue.h
Go to the documentation of this file.
1
9#ifndef CPPCOMMON_THREADS_WAIT_QUEUE_H
10#define CPPCOMMON_THREADS_WAIT_QUEUE_H
11
12#include "condition_variable.h"
13
14#include <queue>
15
16namespace CppCommon {
17
19
28template<typename T>
30{
31public:
33
36 explicit WaitQueue(size_t capacity = 0);
37 WaitQueue(const WaitQueue&) = delete;
38 WaitQueue(WaitQueue&&) = default;
39 ~WaitQueue();
40
41 WaitQueue& operator=(const WaitQueue&) = delete;
43
45 explicit operator bool() const noexcept { return !closed() && !empty(); }
46
48 bool closed() const;
49
51 bool empty() const { return (size() == 0); }
53 size_t capacity() const;
55 size_t size() const;
56
58
66 bool Enqueue(const T& item);
68
76 bool Enqueue(T&& item);
77
79
87 bool Dequeue(T& item);
88
90
93 void Close();
94
95private:
96 bool _closed;
97 const size_t _capacity;
98 mutable CriticalSection _cs;
101 std::queue<T> _queue;
102};
103
106} // namespace CppCommon
107
108#include "wait_queue.inl"
109
110#endif // CPPCOMMON_THREADS_WAIT_QUEUE_H
Condition variable synchronization primitive.
Critical section synchronization primitive.
Multiple producers / multiple consumers wait queue.
Definition wait_queue.h:30
WaitQueue & operator=(WaitQueue &&)=default
bool Enqueue(const T &item)
Enqueue an item into the wait queue.
bool empty() const
Is wait queue empty?
Definition wait_queue.h:51
bool Dequeue(T &item)
Dequeue an item from the wait queue.
void Close()
Close the wait queue.
size_t capacity() const
Get wait queue capacity.
WaitQueue(const WaitQueue &)=delete
WaitQueue(WaitQueue &&)=default
WaitQueue & operator=(const WaitQueue &)=delete
bool closed() const
Is wait queue closed?
size_t size() const
Get wait queue size.
Condition variable synchronization primitive definition.
C++ Common project definitions.
Multiple producers / multiple consumers wait queue inline implementation.