summaryrefslogtreecommitdiff
path: root/src/Task.cc
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-17 21:18:50 -0700
committerPixel <pixel@nobis-crew.org>2011-10-17 21:18:50 -0700
commitfb01d48ff535d34773e57c2e779455fe0edb2007 (patch)
tree5a01348fb4fc6ba7597b9c9e17dd87adc0e1ffc8 /src/Task.cc
parentbc4f9afa3e19fc7f7b9fd642bf6bf170b319f5f7 (diff)
Adding the Async event, and tweaking the others a bit.
Diffstat (limited to 'src/Task.cc')
-rw-r--r--src/Task.cc31
1 files changed, 23 insertions, 8 deletions
diff --git a/src/Task.cc b/src/Task.cc
index 202d6ab..558b7de 100644
--- a/src/Task.cc
+++ b/src/Task.cc
@@ -91,17 +91,31 @@ void Balau::Events::BaseEvent::doSignal() {
}
}
-Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited) {
+Balau::Events::TaskEvent::TaskEvent(Task * taskWaited) : m_taskWaited(taskWaited), m_ack(false) {
m_taskWaited->m_waitedBy.push_back(this);
}
-Balau::Events::Timeout::Timeout(ev_tstamp tstamp) {
- set(tstamp);
+Balau::Events::TaskEvent::~TaskEvent() {
+ if (!m_ack)
+ ack();
}
-void Balau::Events::Timeout::set(ev_tstamp tstamp) {
- m_evt.set<Timeout, &Timeout::evt_cb>(this);
- m_evt.set(tstamp);
+void Balau::Events::TaskEvent::ack() {
+ Assert(!m_ack);
+ bool deleted = false;
+ Task * t = m_taskWaited;
+ Task::waitedByList_t::iterator i;
+ for (i = t->m_waitedBy.begin(); i != t->m_waitedBy.end(); i++) {
+ if (*i == this) {
+ t->m_waitedBy.erase(i);
+ deleted = true;
+ break;
+ }
+ }
+ Printer::elog(E_TASK, "TaskEvent at %p being ack; removing from the 'waited by' list of %p (%s - %s); deleted = %s", this, t, t->getName(), ClassName(t).c_str(), deleted ? "true" : "false");
+ Assert(deleted);
+ m_ack = true;
+ reset();
}
void Balau::Events::Timeout::gotOwner(Task * task) {
@@ -109,8 +123,9 @@ void Balau::Events::Timeout::gotOwner(Task * task) {
m_evt.start();
}
-void Balau::Events::Timeout::evt_cb(ev::timer & w, int revents) {
- doSignal();
+void Balau::Events::Async::gotOwner(Task * task) {
+ m_evt.set(task->getLoop());
+ m_evt.start();
}
void Balau::Events::Custom::gotOwner(Task * task) {