summaryrefslogtreecommitdiff
path: root/includes/TaskMan.h
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2011-11-16 17:26:28 -0800
committerPixel <pixel@nobis-crew.org>2011-11-16 17:26:28 -0800
commit1d796e6cf639354614f1152baab65d317271c357 (patch)
tree5d1e073f9d3b3c045e1c65d8ac2b658ca95a03f9 /includes/TaskMan.h
parent2718578affdfb202450e66e6b159ff634d6b28ab (diff)
Kind of a big revamp of the TaskMan / Task model, in order to introduce a TaskScheduler.
The idea is that we need to support multiple task managers from multiple threads. So that revamp means we now should be able to support that, except the TaskScheduler needs to implement a round robin system, to distribute tasks across multiple task managers. But at least, the fundamental redesign to permit this is here.
Diffstat (limited to 'includes/TaskMan.h')
-rw-r--r--includes/TaskMan.h30
1 files changed, 22 insertions, 8 deletions
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
index b4645fe..afc2b8a 100644
--- a/includes/TaskMan.h
+++ b/includes/TaskMan.h
@@ -8,40 +8,54 @@
#include <ext/hash_set>
#include <vector>
#include <Threads.h>
+#include <Exceptions.h>
namespace gnu = __gnu_cxx;
namespace Balau {
class Task;
+class TaskScheduler;
+
+namespace Events {
+
+class Async;
+
+};
class TaskMan {
public:
TaskMan();
~TaskMan();
void mainLoop();
- void stop() { m_stopped = true; }
- static TaskMan * getTaskMan();
+ static TaskMan * getDefaultTaskMan();
struct ev_loop * getLoop() { return m_loop; }
void signalTask(Task * t);
-
+ static void stop();
+ void stopMe() { m_stopped = true; }
private:
- void registerTask(Task * t);
+ static void registerTask(Task * t);
+ void addToPending(Task * t);
#ifndef _WIN32
coro_context m_returnContext;
#else
void * m_fiber;
#endif
friend class Task;
+ friend class TaskScheduler;
+ template<class T>
+ friend T * createTask(T * t);
struct taskHasher { size_t operator()(const Task * t) const { return reinterpret_cast<uintptr_t>(t); } };
typedef gnu::hash_set<Task *, taskHasher> taskHash_t;
- typedef std::vector<Task *> taskList_t;
taskHash_t m_tasks, m_signaledTasks;
- taskList_t m_pendingAdd;
- Lock m_pendingLock;
- volatile bool m_stopped;
+ Queue<Task *> m_pendingAdd;
+ bool m_stopped;
struct ev_loop * m_loop;
bool m_allowedToSignal;
+ ev::async m_evt;
};
+template<class T>
+T * createTask(T * t) { TaskMan::registerTask(t); Assert(dynamic_cast<Task *>(t)); return t; }
+
};