From 20124b259c408a3ad4427df5176553298907106c Mon Sep 17 00:00:00 2001 From: Pixel Date: Fri, 14 Oct 2011 08:52:01 -0700 Subject: Tweaking the Task class a bit. -) setPreemptible now returns the previous state -) Events may now not have an owner -) Events may now have a callback (even though it still needs an owner to get into the ev_loop, for these kind of watchers...) TODO: -) think about a way to start a watcher without requireing a Task -) add a few more things in the Tasks unit tests --- src/Task.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Task.cc b/src/Task.cc index 938b3de..f7645e6 100644 --- a/src/Task.cc +++ b/src/Task.cc @@ -80,13 +80,15 @@ void Balau::Task::waitFor(Balau::Events::BaseEvent * e, bool override) { m_loop = loop; } -void Balau::Task::setPreemptible(bool enable) { +bool Balau::Task::setPreemptible(bool enable) { + bool wasPreemptible = !m_loop; if (!m_loop && !enable) { m_loop = ev_loop_new(EVFLAG_AUTO); } else if (m_loop) { ev_loop_destroy(m_loop); m_loop = NULL; } + return wasPreemptible; } struct ev_loop * Balau::Task::getLoop() { @@ -98,7 +100,10 @@ struct ev_loop * Balau::Task::getLoop() { void Balau::Events::BaseEvent::doSignal() { m_signal = true; - m_task->getTaskMan()->signalTask(m_task); + if (m_cb) + m_cb->gotEvent(this); + if (m_task) + m_task->getTaskMan()->signalTask(m_task); } Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited) { -- cgit v1.2.3