From 37221dc091725c6fea09181b845308ab8f26c795 Mon Sep 17 00:00:00 2001 From: Pixel Date: Tue, 3 Apr 2012 08:46:21 -0700 Subject: Reworking a bit the way the queues are working, and thus, the way the LuaTMainTask queue works. --- includes/Task.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'includes/Task.h') 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 Queue : public QueueBase { + public: + void push(T * t) { iPush(t); } + T * pop(bool wait = true) { return (T *) iPop(wait); } +}; + }; -- cgit v1.2.3