#include "types.h"
-// blocks enq() and deq() when queue is FULL or EMPTY
template<class T>
class fifo {
public:
return true;
}
- void deq(T * e) {
+ T deq() {
lock ml(m_);
while(q_.empty())
non_empty_c_.wait(ml);
- *e = q_.front();
+ T t = q_.front();
q_.pop_front();
if (max_ && q_.size() < max_)
has_space_c_.notify_one();
- }
-
- bool size() {
- lock ml(m_);
- return q_.size();
+ return t;
}
private:
- list<T> q_;
- mutex m_;
+ std::list<T> q_;
+ std::mutex m_;
cond non_empty_c_; // q went non-empty
cond has_space_c_; // q is not longer overfull
size_t max_; // maximum capacity of the queue, block enq threads if exceeds this limit