summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2012-04-06 11:40:55 -0700
committerPixel <pixel@nobis-crew.org>2012-04-06 11:40:55 -0700
commitf2cfa1707c713c7bb01d16f4c2c4d96803ea6793 (patch)
treea722f3ad52ec471520097c5bfbbf2ab8cb4e2603 /includes
parent7fbb819bf6f590bf2337d2277f77487ef7a5ce86 (diff)
Making it simplier to register a task and wait for it. Also renamed createTask to registerTask, which makes way more sense.
Diffstat (limited to 'includes')
-rw-r--r--includes/Socket.h2
-rw-r--r--includes/Task.h3
-rw-r--r--includes/TaskMan.h9
3 files changed, 8 insertions, 6 deletions
diff --git a/includes/Socket.h b/includes/Socket.h
index f63edf0..b113e43 100644
--- a/includes/Socket.h
+++ b/includes/Socket.h
@@ -81,7 +81,7 @@ class Listener : public ListenerBase {
public:
Listener(int port, const char * local = "", void * opaque = NULL) : ListenerBase(port, local, opaque) { }
protected:
- virtual void factory(IO<Socket> & io, void * opaque) { TaskMan::createTask(new Worker(io, opaque)); }
+ virtual void factory(IO<Socket> & io, void * opaque) { TaskMan::registerTask(new Worker(io, opaque)); }
virtual void setName() { m_name = String(ClassName(this).c_str()) + " - " + m_listener->getName(); }
};
diff --git a/includes/Task.h b/includes/Task.h
index 343580b..3a02c55 100644
--- a/includes/Task.h
+++ b/includes/Task.h
@@ -73,11 +73,12 @@ class Timeout : public BaseEvent {
class TaskEvent : public BaseEvent {
public:
- TaskEvent(Task * taskWaited);
+ TaskEvent(Task * taskWaited = NULL);
virtual ~TaskEvent();
void ack();
void signal();
Task * taskWaited() { return m_taskWaited; }
+ void attachToTask(Task * taskWaited);
void evt_cb(ev::async & w, int revents) { doSignal(); }
protected:
virtual void gotOwner(Task * task);
diff --git a/includes/TaskMan.h b/includes/TaskMan.h
index 68aaaf6..35e60ed 100644
--- a/includes/TaskMan.h
+++ b/includes/TaskMan.h
@@ -20,6 +20,7 @@ class TaskScheduler;
namespace Events {
class Async;
+class TaskEvent;
};
@@ -54,10 +55,12 @@ class TaskMan {
}
bool stopped() { return m_stopped; }
template<class T>
- static T * createTask(T * t, Task * stick = NULL) { TaskMan::registerTask(t, stick); return t; }
+ static T * registerTask(T * t, Task * stick = NULL) { TaskMan::iRegisterTask(t, stick, NULL); return t; }
+ template<class T>
+ static T * registerTask(T * t, Events::TaskEvent * event) { TaskMan::iRegisterTask(t, NULL, event); return t; }
private:
- static void registerTask(Task * t, Task * stick);
+ static void iRegisterTask(Task * t, Task * stick, Events::TaskEvent * event);
void * getStack();
void freeStack(void * stack);
void addToPending(Task * t);
@@ -68,8 +71,6 @@ class TaskMan {
#endif
friend class Task;
friend class TaskScheduler;
- template<class T>
- friend T * createTask(T * t, Task * stick = NULL);
struct taskHasher { size_t operator()(const Task * t) const { return reinterpret_cast<uintptr_t>(t); } };
typedef gnu::hash_set<Task *, taskHasher> taskHash_t;
taskHash_t m_tasks, m_signaledTasks;