Run ccnx interest and data callback in executor
Run scheduler task in executor
diff --git a/scheduler/scheduler.cc b/scheduler/scheduler.cc
index 02b6431..1e9aee7 100644
--- a/scheduler/scheduler.cc
+++ b/scheduler/scheduler.cc
@@ -56,6 +56,7 @@
Scheduler::Scheduler()
: m_running(false)
+ , m_executor(1)
{
event_set_fatal_callback(errorCallback);
evthread_use_pthreads();
@@ -113,12 +114,19 @@
}
void
+Scheduler::execute(Executor::Job job)
+{
+ m_executor.execute(job);
+}
+
+void
Scheduler::start()
{
ScopedLock lock(m_mutex);
if (!m_running)
{
m_thread = boost::thread(&Scheduler::eventLoop, this);
+ m_executor.start();
m_running = true;
}
}
@@ -139,6 +147,7 @@
if (breakAndWait)
{
event_base_loopbreak(m_base);
+ m_executor.shutdown();
m_thread.join();
}
}
diff --git a/scheduler/scheduler.h b/scheduler/scheduler.h
index 18bd9bd..096be98 100644
--- a/scheduler/scheduler.h
+++ b/scheduler/scheduler.h
@@ -39,6 +39,7 @@
#include "task.h"
#include "interval-generator.h"
+#include "executor.h"
class Scheduler;
typedef boost::shared_ptr<Scheduler> SchedulerPtr;
@@ -110,6 +111,9 @@
rescheduleTaskAt (TaskPtr task, double time);
void
+ execute(Executor::Job);
+
+ void
eventLoop();
event_base *
@@ -135,6 +139,7 @@
event_base *m_base;
event *m_ev;
boost::thread m_thread;
+ Executor m_executor;
};
struct SchedulerException : virtual boost::exception, virtual std::exception { };
diff --git a/scheduler/task.cc b/scheduler/task.cc
index 0d09199..4702906 100644
--- a/scheduler/task.cc
+++ b/scheduler/task.cc
@@ -26,7 +26,7 @@
eventCallback(evutil_socket_t fd, short what, void *arg)
{
Task *task = static_cast<Task *>(arg);
- task->run();
+ task->execute();
task = NULL;
}
@@ -68,3 +68,9 @@
m_tv->tv_sec = static_cast<int>(intPart);
m_tv->tv_usec = static_cast<int>((fraction * 1000000));
}
+
+void
+Task::execute()
+{
+ m_scheduler->execute(boost::bind(&Task::run, this));
+}
diff --git a/scheduler/task.h b/scheduler/task.h
index 8289c57..41e4438 100644
--- a/scheduler/task.h
+++ b/scheduler/task.h
@@ -86,6 +86,9 @@
void
setTv(double delay);
+ void
+ execute();
+
protected:
Callback m_callback;
Tag m_tag;