diff options
Diffstat (limited to 'includes')
-rw-r--r-- | includes/Local.h | 4 | ||||
-rw-r--r-- | includes/Printer.h | 8 | ||||
-rw-r--r-- | includes/Task.h | 4 | ||||
-rw-r--r-- | includes/TaskMan.h | 13 |
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; }; }; |