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 | |
parent | 47c0bfe9012306aafb79ea63098383581a5f1fcd (diff) |
BigClean; Task pass - getting it more threadsafe
Diffstat (limited to 'include')
-rw-r--r-- | include/Task.h | 42 | ||||
-rw-r--r-- | include/TaskMan.h | 10 |
2 files changed, 33 insertions, 19 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: diff --git a/include/TaskMan.h b/include/TaskMan.h index 59363f8..2bc7495 100644 --- a/include/TaskMan.h +++ b/include/TaskMan.h @@ -25,8 +25,11 @@ typedef int sigset_t; #endif #include <signal.h> -#include <Task.h> +#include <Atomic.h> #include <vector> +#include <Handle.h> + +class Task; class TaskMan : public Base { public: @@ -80,6 +83,8 @@ class TaskMan : public Base { Task * T; }; typedef std::vector<Task *> TaskList_t; + + static void ProcessNewTasks(); static TaskList_t TaskList; static TaskList_t Zombies; @@ -96,6 +101,9 @@ class TaskMan : public Base { static sigset_t sigchildset; static int got_sigchild; static bool CheckDead(Task *); + static Atomic::Queue<Task> new_tasks; }; +#include <Task.h> + #endif |