summaryrefslogtreecommitdiff
path: root/src/TaskMan.cc
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-09-01 00:12:35 -0700
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2012-09-01 00:12:35 -0700
commit06674e57649d536cf19715524ee40c5ad4a9026d (patch)
treed519fc72a6e3946150cc5ee21ed01cb73e82747b /src/TaskMan.cc
parentd2db92f6b5d275b3150deb7a52a8da142a7cc953 (diff)
Adding async operations; first step towards tossing libeio out.
Diffstat (limited to 'src/TaskMan.cc')
-rw-r--r--src/TaskMan.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/TaskMan.cc b/src/TaskMan.cc
index 17f0a40..49c326a 100644
--- a/src/TaskMan.cc
+++ b/src/TaskMan.cc
@@ -1,8 +1,24 @@
+#include "Async.h"
#include "TaskMan.h"
#include "Task.h"
#include "Main.h"
#include "Local.h"
+static Balau::AsyncManager s_async;
+
+namespace {
+
+class AsyncStarter : public Balau::AtStart, Balau::AtExit {
+ public:
+ AsyncStarter() : AtStart(1000), AtExit(0) { }
+ void doStart() {
+ s_async.threadStart();
+ }
+ void doExit() {
+ s_async.join();
+ }
+};
+
class Stopper : public Balau::Task {
public:
Stopper(int code) : m_code(code) { }
@@ -12,6 +28,10 @@ class Stopper : public Balau::Task {
int m_code;
};
+};
+
+static AsyncStarter s_asyncStarter;
+
void Stopper::Do() {
getTaskMan()->stopMe(m_code);
}
@@ -207,6 +227,8 @@ int Balau::TaskMan::mainLoop() {
if (t->getStatus() == Task::STARTING)
starting.insert(t);
+ s_async.setIdleReadyCallback(asyncIdleReady, this);
+
do {
bool noWait = false;
@@ -239,6 +261,9 @@ int Balau::TaskMan::mainLoop() {
ev_run(m_loop, noWait || m_stopped ? EVRUN_NOWAIT : EVRUN_ONCE);
Printer::elog(E_TASK, "TaskMan at %p Getting out of libev main loop", this);
+ // calling async's idle loop here
+ s_async.idle();
+
// let's check what task got stopped, and signal them
for (Task * t : stopped) {
IAssert((t->getStatus() == Task::STOPPED) || (t->getStatus() == Task::FAULTED), "Task %p in stopped list but isn't stopped.", t);
@@ -316,6 +341,7 @@ int Balau::TaskMan::mainLoop() {
} while (!m_stopped);
Printer::elog(E_TASK, "TaskManager at %p stopping.", this);
+ s_async.setIdleReadyCallback(NULL, NULL);
return m_stopCode;
}
@@ -329,6 +355,10 @@ void Balau::TaskMan::registerTask(Balau::Task * t, Balau::Task * stick) {
}
}
+void Balau::TaskMan::registerAsyncOp(Balau::AsyncOperation * op) {
+ s_async.queueOp(op);
+}
+
void Balau::TaskMan::addToPending(Balau::Task * t) {
m_pendingAdd.push(t);
}