| | |
| | | cond_node.notify(); |
| | | return q.size(); |
| | | } |
| | | int pop(T& m, const size_t ms){ |
| | | std::unique_lock<std::mutex> l{mtx_q}; |
| | | auto d = std::chrono::milliseconds{ms}; |
| | | if(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){ |
| | | return -1; |
| | | } |
| | | m = q.front(); |
| | | q.pop_front(); |
| | | cond_spare.notify(); |
| | | return q.size(); |
| | | } |
| | | int pop(T& m){ |
| | | std::unique_lock<std::mutex> l{mtx_q}; |
| | | auto d = std::chrono::milliseconds{du}; |
| | |
| | | cond_spare.notify(); |
| | | return q.size(); |
| | | } |
| | | T pop(const size_t ms){ |
| | | std::unique_lock<std::mutex> l{mtx_q}; |
| | | auto d = std::chrono::milliseconds{ms}; |
| | | T t{}; |
| | | if(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){ |
| | | return t; |
| | | } |
| | | t = q.front(); |
| | | q.pop_front(); |
| | | cond_spare.notify(); |
| | | return t; |
| | | } |
| | | T pop(){ |
| | | std::unique_lock<std::mutex> l{mtx_q}; |
| | | auto d = std::chrono::milliseconds{du}; |
| | | T t{}; |
| | | while(!cond_node.wait_for(l, d, [this]{ return !q.empty(); })){ |
| | | if (pred()) return T{}; |
| | | if (pred()) return t; |
| | | } |
| | | auto m(move(q.front())); |
| | | t = q.front(); |
| | | q.pop_front(); |
| | | cond_spare.notify(); |
| | | return m; |
| | | return t; |
| | | } |
| | | |
| | | template<typename F> void clear(F&& f){ |