summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-10-07 15:36:12 -0700
committerPixel <pixel@nobis-crew.org>2011-10-07 15:36:12 -0700
commit1d9def9edae0011eeee8f83dc32fb3797ca2f46b (patch)
tree29077945287dd4b0c13269b9f3e5dc97936551f9 /includes
parent5a283e5b2b523d53e3504292c386b534dc74386a (diff)
More work in the Task manager.
Also fixing a few bugs linked with the printer and TLS. Removed flto from compilation flags: this actually creates bad code (!)
Diffstat (limited to 'includes')
-rw-r--r--includes/Local.h4
-rw-r--r--includes/Printer.h8
-rw-r--r--includes/Task.h4
-rw-r--r--includes/TaskMan.h13
4 files changed, 21 insertions, 8 deletions
diff --git a/includes/Local.h b/includes/Local.h
index a3405ca..e3d08a4 100644
--- a/includes/Local.h
+++ b/includes/Local.h
@@ -23,10 +23,10 @@ class Local : public AtStart {
void * get() { if (getTLS()) { void * l = getLocal(); return l ? l : getGlobal(); } else return getGlobal(); }
void setGlobal(void * obj) { m_globals[m_idx] = obj; }
void setLocal(void * obj) { void * r = getTLS(); reinterpret_cast<void **>(r)[m_idx] = obj; }
- void set(void * obj) { void * r = getTLS(); if (r) setGlobal(obj); else setLocal(obj); }
+ void set(void * obj) { void * r = getTLS(); if (r) setLocal(obj); else setGlobal(obj); }
int getIndex() { return m_idx; }
private:
- static void * create() { void * r = malloc(s_size * sizeof(void *)); setTLS(r); return r; }
+ static void * create() { void * r = malloc(s_size * sizeof(void *)); return r; }
static void * getTLS() { return tlsManager->getTLS(); }
static void * setTLS(void * val) { return tlsManager->setTLS(val); }
virtual void doStart();
diff --git a/includes/Printer.h b/includes/Printer.h
index b55df22..20b3b6c 100644
--- a/includes/Printer.h
+++ b/includes/Printer.h
@@ -1,5 +1,6 @@
#pragma once
+#include <stdarg.h>
#include <BString.h>
namespace Balau {
@@ -21,14 +22,15 @@ class Printer {
virtual void _print(const char * fmt, va_list ap);
private:
+ void _print(const char * fmt, ...);
void _log(uint32_t level, const char * fmt, va_list ap);
- static Printer * getPrinter();
public:
Printer();
void setLocal();
+ static Printer * getPrinter();
static void log(uint32_t level, const String & fmt, ...) { va_list ap; va_start(ap, fmt); log(level, fmt.to_charp(), ap); va_end(ap); }
static void log(uint32_t level, const char * fmt, ...) { va_list ap; va_start(ap, fmt); log(level, fmt, ap); va_end(ap); }
static void log(uint32_t level, const char * fmt, va_list ap) { getPrinter()->_log(level, fmt, ap); }
@@ -36,8 +38,8 @@ class Printer {
static void print(const char * fmt, ...) { va_list ap; va_start(ap, fmt); print(fmt, ap); va_end(ap); }
static void print(const char * fmt, va_list ap) { getPrinter()->_print(fmt, ap); }
- void enable(uint32_t levels = M_ALL) { m_verbosity |= levels; }
- void disable(uint32_t levels = M_ALL) { m_verbosity &= ~levels; }
+ static void enable(uint32_t levels = M_ALL) { getPrinter()->m_verbosity |= levels; }
+ static void disable(uint32_t levels = M_ALL) { getPrinter()->m_verbosity &= ~levels; }
uint32_t m_verbosity;
};
diff --git a/includes/Task.h b/includes/Task.h
index 314532b..fb210a2 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -17,12 +17,12 @@ class Task {
FAULTED,
};
Task();
- ~Task() { free(stack); free(tls); }
- virtual void Do() = 0;
+ virtual ~Task();
virtual const char * getName() = 0;
Status getStatus() { return status; }
protected:
void suspend();
+ virtual void Do() = 0;
private:
size_t stackSize() { return 128 * 1024; }
void switchTo();
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
index 05e5fa8..ac95f71 100644
--- a/includes/TaskMan.h
+++ b/includes/TaskMan.h
@@ -1,6 +1,10 @@
#pragma once
#include <coro.h>
+#include <ext/hash_set>
+#include <stdint.h>
+
+namespace gnu = __gnu_cxx;
namespace Balau {
@@ -11,11 +15,18 @@ class TaskMan {
TaskMan();
~TaskMan();
void mainLoop();
+ void stop() { stopped = true; }
+ static TaskMan * getTaskMan();
private:
- static TaskMan * getTaskMan();
+ void registerTask(Task * t);
+ void unregisterTask(Task * t);
coro_context returnContext;
friend class Task;
+ struct taskHash { size_t operator()(const Task * t) const { return reinterpret_cast<uintptr_t>(t); } };
+ typedef gnu::hash_set<Task *, taskHash> taskList;
+ taskList tasks, pendingAdd;
+ volatile bool stopped;
};
};