From 864eeb3a526b1a32c72e1f31a3e1f23dcc5c7409 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sun, 9 Oct 2011 01:12:50 -0700 Subject: More work on the Task manager. Now "Main" is a Task, among the most important changes. Introduced the notion of Events, and managed a coherent task switch. Also, renamed a lot of the variables to have a more coherent naming scheme. --- includes/Task.h | 44 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) (limited to 'includes/Task.h') diff --git a/includes/Task.h b/includes/Task.h index fb210a2..c2777fe 100644 --- a/includes/Task.h +++ b/includes/Task.h @@ -2,10 +2,37 @@ #include #include +#include +#include namespace Balau { class TaskMan; +class Task; + +namespace Events { + +class BaseEvent { + public: + BaseEvent() : m_signal(false), m_task(NULL) { } + bool gotSignal() { return m_signal; } + void doSignal() { m_signal = true; } + Task * taskWaiting() { Assert(m_task); return m_task; } + void registerOwner(Task * task) { Assert(m_task == NULL); m_task = task; } + private: + bool m_signal; + Task * m_task; +}; + +class TaskEvent : public BaseEvent { + public: + TaskEvent(Task * taskWaited); + Task * taskWaited() { return m_taskWaited; } + private: + Task * m_taskWaited; +}; + +}; class Task { public: @@ -19,20 +46,25 @@ class Task { Task(); virtual ~Task(); virtual const char * getName() = 0; - Status getStatus() { return status; } + Status getStatus() { return m_status; } + static Task * getCurrentTask(); protected: void suspend(); virtual void Do() = 0; + void waitFor(Events::BaseEvent * event); private: size_t stackSize() { return 128 * 1024; } void switchTo(); static void coroutine(void *); - void * stack; - coro_context ctx; - TaskMan * taskMan; - Status status; - void * tls; + void * m_stack; + coro_context m_ctx; + TaskMan * m_taskMan; + Status m_status; + void * m_tls; friend class TaskMan; + friend class Events::TaskEvent; + typedef std::vector waitedByList_t; + waitedByList_t m_waitedBy; }; }; -- cgit v1.2.3