Simplifications and clean-ups
[invirt/third/libt4.git] / rpc / fifo.h
index e3f0c38..f8a7224 100644 (file)
@@ -8,8 +8,29 @@ template<class T>
 class fifo {
     public:
         fifo(size_t limit=0) : max_(limit) {}
-        bool enq(T, bool blocking=true);
-        void deq(T *);
+
+        bool enq(T e, bool blocking=true) {
+            lock ml(m_);
+            while (max_ && q_.size() >= max_) {
+                if (!blocking)
+                    return false;
+                has_space_c_.wait(ml);
+            }
+            q_.push_back(e);
+            non_empty_c_.notify_one();
+            return true;
+        }
+
+        void deq(T * e) {
+            lock ml(m_);
+            while(q_.empty())
+                non_empty_c_.wait(ml);
+            *e = q_.front();
+            q_.pop_front();
+            if (max_ && q_.size() < max_)
+                has_space_c_.notify_one();
+        }
+
         bool size() {
             lock ml(m_);
             return q_.size();
@@ -23,30 +44,4 @@ class fifo {
         size_t max_; // maximum capacity of the queue, block enq threads if exceeds this limit
 };
 
-template<class T> bool
-fifo<T>::enq(T e, bool blocking)
-{
-    lock ml(m_);
-    while (max_ && q_.size() >= max_) {
-        if (!blocking)
-            return false;
-        has_space_c_.wait(ml);
-    }
-    q_.push_back(e);
-    non_empty_c_.notify_one();
-    return true;
-}
-
-template<class T> void
-fifo<T>::deq(T *e)
-{
-    lock ml(m_);
-    while(q_.empty())
-        non_empty_c_.wait(ml);
-    *e = q_.front();
-    q_.pop_front();
-    if (max_ && q_.size() < max_)
-        has_space_c_.notify_one();
-}
-
 #endif