diff options
author | Pixel <pixel@nobis-crew.org> | 2012-04-03 08:46:21 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2012-04-03 08:46:21 -0700 |
commit | 37221dc091725c6fea09181b845308ab8f26c795 (patch) | |
tree | f877eb7f70f2f9ec021fd04720d7bd0c937dbab7 /includes/Task.h | |
parent | 7d5f246ae7310055d39ea13ff395d830e3c27a60 (diff) |
Reworking a bit the way the queues are working, and thus, the way the LuaTMainTask queue works.
Diffstat (limited to 'includes/Task.h')
-rw-r--r-- | includes/Task.h | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/includes/Task.h b/includes/Task.h index 592d5c3..01d5e3f 100644 --- a/includes/Task.h +++ b/includes/Task.h @@ -169,4 +169,36 @@ class Task { bool m_okayToEAgain; }; +class QueueBase { + public: + bool isEmpty() { ScopeLock sl(m_lock); return !m_front; } + protected: + QueueBase() : m_front(NULL), m_back(NULL) { pthread_cond_init(&m_cond, NULL); } + ~QueueBase() { while (!isEmpty()) iPop(false); pthread_cond_destroy(&m_cond); } + void iPush(void * t); + void * iPop(bool wait); + + private: + QueueBase(const QueueBase &) = delete; + QueueBase & operator=(const QueueBase &) = delete; + Lock m_lock; + struct Cell { + Cell(void * elem) : m_next(NULL), m_prev(NULL), m_elem(elem) { } + Cell(const Cell &) = delete; + Cell & operator=(const Cell &) = delete; + Cell * m_next, * m_prev; + void * m_elem; + }; + Cell * m_front, * m_back; + pthread_cond_t m_cond; + Events::Async m_event; +}; + +template<class T> +class Queue : public QueueBase { + public: + void push(T * t) { iPush(t); } + T * pop(bool wait = true) { return (T *) iPop(wait); } +}; + }; |