diff options
author | Pixel <pixel@nobis-crew.org> | 2009-11-12 18:22:55 -0800 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-11-12 18:22:55 -0800 |
commit | c12806450806909177058eb8e7f85dcbd24cbf1c (patch) | |
tree | 4ec38604a93380699405558065d2fd746edd14ca /include/Task.h | |
parent | 47c0bfe9012306aafb79ea63098383581a5f1fcd (diff) |
BigClean; Task pass - getting it more threadsafe
Diffstat (limited to 'include/Task.h')
-rw-r--r-- | include/Task.h | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/include/Task.h b/include/Task.h index d976124..32cbf85 100644 --- a/include/Task.h +++ b/include/Task.h @@ -29,6 +29,7 @@ #include <vector> #include <Exceptions.h> #include <Handle.h> +#include <TaskMan.h> #undef E_HANDLE #undef Yield @@ -41,42 +42,47 @@ class Task : public Base { EVT_PROCESS, EVT_TIMEOUT, EVT_TASK, + EVT_IDLE, }; enum { TASK_ON_HOLD = 0, TASK_DONE, TASK_BURST, + TASK_IDLE, + TASK_IDLE_REST, }; enum { W4_STICKY = 1, W4_READING = 2, W4_WRITING = 4, }; - Task(); + Task() : current(0), state(TASK_ON_HOLD), stopped(false), suspended(false), yielded(false), wbta(0), wta(0), BurstHandle(0) { TaskMan::AddTask(this); } virtual ~Task(); - virtual String GetName(); + virtual String GetName() { return "Unknow Task"; } int Run(); int DryRun(); - int GetState(); + int GetState() { return state; } void Suspend(int = -1) throw (GeneralException); - void WaitFor(Task *); - void WaitFor(Handle *, int = 0); - void WaitFor(pid_t); - void WaitFor(const timeval &, int = 0); - void Yield(); - bool Yielded(); - void Unyield(); - Task * WaitedBy(); - void SetBurst(); - void Stop(); - void Restart(); - bool IsStopped(); - void RemoveFromWatches(); - void RemoveTimeout(); + void WaitFor(Task * t) { t->wbta = this; wta = t; } + void WaitFor(Handle * h, int flags = 0) { h->SetNonBlock(); TaskMan::WaitFor(h, this, flags); } + void WaitFor(pid_t p) { TaskMan::WaitFor(p, this); } + void WaitFor(const timeval & t, int flags = 0) { TaskMan::WaitFor(t, this, flags); } + void Yield() { yielded = true; Suspend(TASK_ON_HOLD); } + bool Yielded() { return yielded; } + void Unyield() { yielded = false; SetBurst(); } + Task * WaitedBy() { return wbta; } + void SetBurst() { state = TASK_BURST; } + void SetIdle() { state = TASK_IDLE; } + void IdleRest() { state = TASK_IDLE_REST; } + void Stop() { stopped = true; } + void Restart() { stopped = false; } + bool IsStopped() { return stopped; } + void RemoveFromWatches() { wbta = 0; } + void RemoveTimeout() { TaskMan::RemoveTimeout(this); } Handle * BurstHandle; protected: - virtual int Do() throw (GeneralException); + virtual int Do() throw (GeneralException) { return TASK_ON_HOLD; } int current; private: |