summaryrefslogtreecommitdiffstats
path: root/src/uscxml/concurrency/BlockingQueue.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/uscxml/concurrency/BlockingQueue.h')
-rw-r--r--src/uscxml/concurrency/BlockingQueue.h41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/uscxml/concurrency/BlockingQueue.h b/src/uscxml/concurrency/BlockingQueue.h
new file mode 100644
index 0000000..90094bf
--- /dev/null
+++ b/src/uscxml/concurrency/BlockingQueue.h
@@ -0,0 +1,41 @@
+#ifndef BLOCKINGQUEUE_H_4LEVMY0N
+#define BLOCKINGQUEUE_H_4LEVMY0N
+
+#include "uscxml/concurrency/tinythread.h"
+#include <list>
+
+namespace uscxml {
+namespace concurrency {
+
+template <class T>
+class BlockingQueue {
+public:
+ BlockingQueue() {}
+ virtual ~BlockingQueue() {
+ }
+
+ void push(T elem) {
+ tthread::lock_guard<tthread::mutex> lock(_mutex);
+ _queue.push_back(elem);
+ _cond.notify_all();
+ }
+
+ T pop() {
+ tthread::lock_guard<tthread::mutex> lock(_mutex);
+ while (_queue.empty()) {
+ _cond.wait(_mutex);
+ }
+ T ret = _queue.front();
+ _queue.pop_front();
+ return ret;
+ }
+
+ tthread::mutex _mutex;
+ tthread::condition_variable _cond;
+ std::list<T> _queue;
+};
+
+}
+}
+
+#endif /* end of include guard: BLOCKINGQUEUE_H_4LEVMY0N */