summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/Local.h21
-rw-r--r--includes/Task.h38
-rw-r--r--includes/TaskMan.h21
3 files changed, 80 insertions, 0 deletions
diff --git a/includes/Local.h b/includes/Local.h
index f3b7250..a3405ca 100644
--- a/includes/Local.h
+++ b/includes/Local.h
@@ -8,6 +8,7 @@ class TLSManager {
public:
virtual void * getTLS();
virtual void * setTLS(void * val);
+ void * createTLS();
};
extern TLSManager * tlsManager;
@@ -32,6 +33,26 @@ class Local : public AtStart {
int m_idx;
static int s_size;
static void ** m_globals;
+
+ friend class TLSManager;
+};
+
+template<class T>
+class DefaultTmpl : public AtStart {
+ public:
+ DefaultTmpl(int pri) : AtStart(pri) { }
+ protected:
+ virtual void doStart() { new T; }
+};
+
+template<class T>
+class LocalTmpl : public Local {
+ public:
+ LocalTmpl() { }
+ T * getGlobal() { return reinterpret_cast<T *>(Local::getGlobal()); }
+ T * get() { return reinterpret_cast<T *>(Local::get()); }
+ void setGlobal(T * obj) { Local::setGlobal(obj); }
+ void set(T * obj) { Local::set(obj); }
};
};
diff --git a/includes/Task.h b/includes/Task.h
new file mode 100644
index 0000000..314532b
--- /dev/null
+++ b/includes/Task.h
@@ -0,0 +1,38 @@
+#pragma once
+
+#include <stdlib.h>
+#include <coro.h>
+
+namespace Balau {
+
+class TaskMan;
+
+class Task {
+ public:
+ enum Status {
+ STARTING,
+ RUNNING,
+ IDLE,
+ STOPPED,
+ FAULTED,
+ };
+ Task();
+ ~Task() { free(stack); free(tls); }
+ virtual void Do() = 0;
+ virtual const char * getName() = 0;
+ Status getStatus() { return status; }
+ protected:
+ void suspend();
+ private:
+ size_t stackSize() { return 128 * 1024; }
+ void switchTo();
+ static void coroutine(void *);
+ void * stack;
+ coro_context ctx;
+ TaskMan * taskMan;
+ Status status;
+ void * tls;
+ friend class TaskMan;
+};
+
+};
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
new file mode 100644
index 0000000..05e5fa8
--- /dev/null
+++ b/includes/TaskMan.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <coro.h>
+
+namespace Balau {
+
+class Task;
+
+class TaskMan {
+ public:
+ TaskMan();
+ ~TaskMan();
+ void mainLoop();
+
+ private:
+ static TaskMan * getTaskMan();
+ coro_context returnContext;
+ friend class Task;
+};
+
+};