summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-14 08:52:01 -0700
committerPixel <pixel@nobis-crew.org>2011-10-14 08:52:01 -0700
commit20124b259c408a3ad4427df5176553298907106c (patch)
tree968d0521577a66da5805fe1a5a2f27f6ca7ded19 /includes
parent4a792414fbc28e81a4742cb916c0f8cfe2c4b6cf (diff)
Tweaking the Task class a bit.
-) setPreemptible now returns the previous state -) Events may now not have an owner -) Events may now have a callback (even though it still needs an owner to get into the ev_loop, for these kind of watchers...) TODO: -) think about a way to start a watcher without requireing a Task -) add a few more things in the Tasks unit tests
Diffstat (limited to 'includes')
-rw-r--r--includes/Task.h14
1 files changed, 12 insertions, 2 deletions
diff --git a/includes/Task.h b/includes/Task.h
index 1fca27e..b106e9c 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -13,9 +13,18 @@ class Task;
namespace Events {
+class BaseEvent;
+
+class Callback {
+ protected:
+ virtual void gotEvent(BaseEvent *) = 0;
+ friend class BaseEvent;
+};
+
class BaseEvent {
public:
- BaseEvent() : m_signal(false), m_task(NULL) { }
+ BaseEvent() : m_cb(NULL), m_signal(false), m_task(NULL) { }
+ virtual ~BaseEvent() { if (m_cb) delete m_cb; }
bool gotSignal() { return m_signal; }
void doSignal();
void reset() { Assert(m_task != NULL); m_signal = false; gotOwner(m_task); }
@@ -24,6 +33,7 @@ class BaseEvent {
protected:
virtual void gotOwner(Task * task) { }
private:
+ Callback * m_cb;
bool m_signal;
Task * m_task;
};
@@ -85,7 +95,7 @@ class Task {
void yield(bool override = false);
virtual void Do() = 0;
void waitFor(Events::BaseEvent * event, bool override = false);
- void setPreemptible(bool enable);
+ bool setPreemptible(bool enable);
private:
size_t stackSize() { return 128 * 1024; }
void switchTo();