9 #ifndef pthread_synchronized_queue_hpp
10 #define pthread_synchronized_queue_hpp
14 #include "pthread/pthread.hpp"
15 #if __cplusplus < 201103L
52 void put (
const T& item);
59 void put (
const T& item,
int wait_time);
76 void get ( T& item,
int wait_time );
80 return _items.empty();
84 #if __cplusplus < 201103L
95 #if __cplusplus < 201103L
111 #if __cplusplus < 201103L
117 #if __cplusplus < 201103L
118 throw queue_exception(
"synchronized_queue's max size must be greater then 0.");
120 throw queue_exception(
"synchronized_queue's max size must be greater then 0, max_size " + std::to_string(ms) +
" is not.");
139 std::list<T> _items ;
140 #if __cplusplus < 201103L
144 std::atomic<int> _max_size ;
157 #if __cplusplus < 201103L
158 while ( (! (not_empty = !_items.empty())) && not_empty_cv.wait(_mutex) ){
161 _not_empty_cv.
wait(lck,[
this]{
return !_items.empty(); });
173 #if __cplusplus < 201103L
174 bool not_empty =
true;
175 auto delay = wait_time;
180 bool not_empty = _not_empty_cv.
wait_for(lck,wait_time, [
this]{
return !_items.empty(); });
196 #if __cplusplus < 201103L
197 bool not_full =
true;
198 while ( ! (not_full = (_items.size() < _max_size))){
199 _not_full_cv.
wait(_mutex);
202 _not_full_cv.
wait(_mutex,[
this]{
return _items.size() < _max_size; });
205 _items.push_back(item);
213 #if __cplusplus < 201103L
214 bool not_full =
true;
215 auto delay = wait_time;
221 bool not_full = _not_full_cv.
wait_for(lck, wait_time, [
this]{
return _items.size() < _max_size; });
225 _items.push_back(item);
229 throw queue_full(
"synchronized_queue::put() timeout, queue is full.");
void notify_one() noexcept
void set_max_size(size_t ms)
void notify_all() noexcept
cv_status wait_for(mutex &mtx, int millis)