X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/26ade07ab0e62b98b452fbbd18edba0450035e35..c279db4240a3a3c30f069ab9dea8055cf94280da:/rpc/fifo.h diff --git a/rpc/fifo.h b/rpc/fifo.h index f8a7224..9e4933a 100644 --- a/rpc/fifo.h +++ b/rpc/fifo.h @@ -3,7 +3,6 @@ #include "types.h" -// blocks enq() and deq() when queue is FULL or EMPTY template class fifo { public: @@ -21,24 +20,20 @@ class fifo { 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 q_; - mutex m_; + std::list 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