From 06674e57649d536cf19715524ee40c5ad4a9026d Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Sat, 1 Sep 2012 00:12:35 -0700 Subject: Adding async operations; first step towards tossing libeio out. --- includes/TaskMan.h | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'includes/TaskMan.h') diff --git a/includes/TaskMan.h b/includes/TaskMan.h index d675d75..d39598f 100644 --- a/includes/TaskMan.h +++ b/includes/TaskMan.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -17,12 +18,6 @@ namespace Balau { class Task; class TaskScheduler; -namespace Events { - -class Async; - -}; - class TaskMan { public: TaskMan(); @@ -37,9 +32,17 @@ class TaskMan { bool stopped() { return m_stopped; } private: static void registerTask(Task * t, Task * stick); + static void registerAsyncOp(AsyncOperation * op); void * getStack(); void freeStack(void * stack); void addToPending(Task * t); + static void asyncIdleReady(void * param) { + TaskMan * taskMan = (TaskMan *) param; + taskMan->asyncIdleReady(); + } + void asyncIdleReady() { + m_evt.send(); + } #ifndef _WIN32 coro_context m_returnContext; #else @@ -49,20 +52,25 @@ class TaskMan { friend class TaskScheduler; template friend T * createTask(T * t, Task * stick = NULL); + template + friend T * createAsyncOp(T * op); struct taskHasher { size_t operator()(const Task * t) const { return reinterpret_cast(t); } }; typedef gnu::hash_set taskHash_t; taskHash_t m_tasks, m_signaledTasks; Queue m_pendingAdd; - bool m_stopped = false; struct ev_loop * m_loop; - bool m_allowedToSignal = false; ev::async m_evt; std::queue m_stacks; int m_nStacks; int m_stopCode = 0; + bool m_stopped = false; + bool m_allowedToSignal = false; }; template T * createTask(T * t, Task * stick) { TaskMan::registerTask(t, stick); return t; } +template +T * createAsyncOp(T * op) { TaskMan::registerAsyncOp(op); return op; } + }; -- cgit v1.2.3