diff options
author | Pixel <pixel@nobis-crew.org> | 2011-10-09 21:42:24 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2011-10-09 21:59:27 -0700 |
commit | 4010635b9c3d74e544d37d1e9295316cff01b014 (patch) | |
tree | d7fe054af931604fcb7a7ff1f759ddd3281b81a3 /includes | |
parent | 74adacf6ec1de10b623112605b5d9610163522ec (diff) |
Starting to integrate libev; timer event works.
Diffstat (limited to 'includes')
-rw-r--r-- | includes/Task.h | 17 | ||||
-rw-r--r-- | includes/TaskMan.h | 6 |
2 files changed, 20 insertions, 3 deletions
diff --git a/includes/Task.h b/includes/Task.h index c2777fe..f0c1bbb 100644 --- a/includes/Task.h +++ b/includes/Task.h @@ -2,6 +2,7 @@ #include <stdlib.h> #include <coro.h> +#include <ev++.h> #include <Exceptions.h> #include <vector> @@ -16,14 +17,25 @@ class BaseEvent { public: BaseEvent() : m_signal(false), m_task(NULL) { } bool gotSignal() { return m_signal; } - void doSignal() { m_signal = true; } + void doSignal(); Task * taskWaiting() { Assert(m_task); return m_task; } - void registerOwner(Task * task) { Assert(m_task == NULL); m_task = task; } + void registerOwner(Task * task) { Assert(m_task == NULL); m_task = task; gotOwner(task); } + protected: + virtual void gotOwner(Task * task) { } private: bool m_signal; Task * m_task; }; +class Timeout : public BaseEvent { + public: + Timeout(ev_tstamp tstamp); + void evt_cb(ev::timer & w, int revents); + private: + virtual void gotOwner(Task * task); + ev::timer m_evt; +}; + class TaskEvent : public BaseEvent { public: TaskEvent(Task * taskWaited); @@ -48,6 +60,7 @@ class Task { virtual const char * getName() = 0; Status getStatus() { return m_status; } static Task * getCurrentTask(); + TaskMan * getTaskMan() { return m_taskMan; } protected: void suspend(); virtual void Do() = 0; diff --git a/includes/TaskMan.h b/includes/TaskMan.h index 585fb7f..d8d0c80 100644 --- a/includes/TaskMan.h +++ b/includes/TaskMan.h @@ -2,6 +2,7 @@ #include <stdint.h> #include <coro.h> +#include <ev++.h> #include <ext/hash_set> #include <vector> @@ -18,6 +19,8 @@ class TaskMan { void mainLoop(); void stop() { m_stopped = true; } static TaskMan * getTaskMan(); + struct ev_loop * getLoop() { return m_loop; } + void signalTask(Task * t); private: void registerTask(Task * t); @@ -27,9 +30,10 @@ class TaskMan { struct taskHasher { size_t operator()(const Task * t) const { return reinterpret_cast<uintptr_t>(t); } }; typedef gnu::hash_set<Task *, taskHasher> taskHash_t; typedef std::vector<Task *> taskList_t; - taskHash_t m_tasks; + taskHash_t m_tasks, m_signaledTasks; taskList_t m_pendingAdd; volatile bool m_stopped; + struct ev_loop * m_loop; }; }; |