summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-08 01:21:47 -0700
committerPixel <pixel@nobis-crew.org>2012-04-08 01:56:15 -0700
commit9f0431d84807e37bfa63bd144dcb4d2235fe7772 (patch)
tree2dd90832af0f4dd6692df03be45e13a8b39588f4 /includes
parente719749e399fc4490fdaf471a000dc841d576c73 (diff)
Putting the bases for stackless co-routines.
Also cleaning up some code, clarifying some concepts, and adding more exception catchers.
Diffstat (limited to 'includes')
-rw-r--r--includes/Task.h27
1 files changed, 24 insertions, 3 deletions
diff --git a/includes/Task.h b/includes/Task.h
index 3a02c55..db602f0 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -21,6 +21,11 @@ class EAgain : public GeneralException {
Events::BaseEvent * m_evt;
};
+class TaskSwitch : public GeneralException {
+ public:
+ TaskSwitch() : GeneralException("Task Switch") { }
+};
+
class TaskMan;
class Task;
@@ -120,11 +125,22 @@ class Task {
enum Status {
STARTING,
RUNNING,
- IDLE,
+ SLEEPING,
STOPPED,
FAULTED,
YIELDED,
};
+ static const char * StatusToString(enum Status status) {
+ static const char * strs[] = {
+ "STARTING",
+ "RUNNING",
+ "SLEEPING",
+ "STOPPED",
+ "FAULTED",
+ "YIELDED",
+ };
+ return strs[status];
+ };
Task();
virtual ~Task();
virtual const char * getName() const = 0;
@@ -138,7 +154,7 @@ class Task {
TaskMan * getTaskMan() const { return m_taskMan; }
struct ev_loop * getLoop();
protected:
- void yield(bool changeStatus = false);
+ void yield(bool stillRunning = false) throw (GeneralException);
virtual void Do() = 0;
void waitFor(Events::BaseEvent * event);
bool setOkayToEAgain(bool enable) {
@@ -146,6 +162,11 @@ class Task {
m_okayToEAgain = enable;
return oldValue;
}
+ void setStackless() {
+ AAssert(m_stackless, "Can't set a task to be stackless twice");
+ AAssert(m_status == STARTING, "Can't set a task to be stackless after it started. status = %s", StatusToString(m_status));
+ m_stackless = true;
+ }
private:
static size_t stackSize() { return 64 * 1024; }
void setup(TaskMan * taskMan, void * stack);
@@ -167,7 +188,7 @@ class Task {
Lock m_eventLock;
typedef std::list<Events::TaskEvent *> waitedByList_t;
waitedByList_t m_waitedBy;
- bool m_okayToEAgain;
+ bool m_okayToEAgain, m_stackless;
};
class QueueBase {