summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-03 09:30:58 -0700
committerPixel <pixel@nobis-crew.org>2012-04-03 09:30:58 -0700
commit532f3e7bae955f8da4c2028bc462134ed10ff414 (patch)
tree239b1dfc5cf4694cfba375d1306dc8bbe2b5b4b8
parent37221dc091725c6fea09181b845308ab8f26c795 (diff)
Slightly more change to the Queue system, so Debug mode doesn't freak pout.
-rw-r--r--includes/LuaTask.h2
-rw-r--r--includes/Task.h20
-rw-r--r--src/LuaTask.cc2
-rw-r--r--src/Task.cc20
4 files changed, 27 insertions, 17 deletions
diff --git a/includes/LuaTask.h b/includes/LuaTask.h
index ee9d7a7..5058578 100644
--- a/includes/LuaTask.h
+++ b/includes/LuaTask.h
@@ -60,7 +60,7 @@ class LuaMainTask : public Task {
void exec(LuaExecCell * cell);
virtual void Do();
Lua L;
- Queue<LuaExecCell> m_queue;
+ TQueue<LuaExecCell> m_queue;
volatile bool m_stopping;
friend class LuaExecCell;
};
diff --git a/includes/Task.h b/includes/Task.h
index 01d5e3f..343580b 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -174,9 +174,9 @@ class QueueBase {
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);
+ ~QueueBase() { while (!isEmpty()) iPop(NULL); pthread_cond_destroy(&m_cond); }
+ void iPush(void * t, Events::Async * event);
+ void * iPop(Events::Async * event);
private:
QueueBase(const QueueBase &) = delete;
@@ -191,14 +191,22 @@ class QueueBase {
};
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); }
+ void push(T * t) { iPush(t, NULL); }
+ T * pop() { return (T *) iPop(NULL); }
+};
+
+template<class T>
+class TQueue : public QueueBase {
+ public:
+ void push(T * t) { iPush(t, &m_event); }
+ T * pop() { return (T *) iPop(&m_event); }
+ private:
+ Events::Async m_event;
};
};
diff --git a/src/LuaTask.cc b/src/LuaTask.cc
index acf63b5..80a56f6 100644
--- a/src/LuaTask.cc
+++ b/src/LuaTask.cc
@@ -32,7 +32,7 @@ void Balau::LuaMainTask::stop() {
void Balau::LuaMainTask::Do() {
while (!m_stopping) {
LuaExecCell * cell;
- while ((cell = m_queue.pop(false))) {
+ while ((cell = m_queue.pop())) {
if (dynamic_cast<LuaTaskDummy *>(cell)) {
delete cell;
break;
diff --git a/src/Task.cc b/src/Task.cc
index 1486540..644e302 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -235,7 +235,7 @@ void Balau::Task::yield(Events::BaseEvent * evt, bool interruptible) throw (Gene
}
}
-void Balau::QueueBase::iPush(void * t) {
+void Balau::QueueBase::iPush(void * t, Events::Async * event) {
ScopeLock sl(m_lock);
Cell * c = new Cell(t);
c->m_prev = m_back;
@@ -244,20 +244,22 @@ void Balau::QueueBase::iPush(void * t) {
else
m_front = c;
m_back = c;
- pthread_cond_signal(&m_cond);
- m_event.trigger();
+ if (event)
+ event->trigger();
+ else
+ pthread_cond_signal(&m_cond);
}
-void * Balau::QueueBase::iPop(bool wait) {
+void * Balau::QueueBase::iPop(Events::Async * event) {
ScopeLock sl(m_lock);
while (!m_front) {
- if (wait) {
- pthread_cond_wait(&m_cond, &m_lock.m_lock);
- } else {
- Task::prepare(&m_event);
+ if (event) {
+ Task::prepare(event);
m_lock.leave();
- Task::yield(&m_event);
+ Task::yield(event);
m_lock.enter();
+ } else {
+ pthread_cond_wait(&m_cond, &m_lock.m_lock);
}
}
Cell * c = m_front;