There was a serious bug with scheduler, related to locking.
diff --git a/scheduler/periodic-task.cc b/scheduler/periodic-task.cc
index b8fd3a7..32bae6a 100644
--- a/scheduler/periodic-task.cc
+++ b/scheduler/periodic-task.cc
@@ -22,9 +22,10 @@
#include "periodic-task.h"
#include <utility>
-PeriodicTask::PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, const IntervalGeneratorPtr &generator)
- : Task(callback, tag, scheduler)
- , m_generator(generator)
+PeriodicTask::PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler,
+ IntervalGeneratorPtr generator)
+ : Task(callback, tag, scheduler)
+ , m_generator(generator)
{
}
diff --git a/scheduler/periodic-task.h b/scheduler/periodic-task.h
index 8536b6f..f36d71a 100644
--- a/scheduler/periodic-task.h
+++ b/scheduler/periodic-task.h
@@ -32,7 +32,7 @@
// generator is needed only when this is a periodic task
// two simple generators implementation (SimpleIntervalGenerator and RandomIntervalGenerator) are provided;
// if user needs more complex pattern in the intervals between calls, extend class IntervalGenerator
- PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, const IntervalGeneratorPtr &generator);
+ PeriodicTask(const Callback &callback, const Tag &tag, const SchedulerPtr &scheduler, IntervalGeneratorPtr generator);
virtual ~PeriodicTask(){}
// invoke callback, reset self and ask scheduler to schedule self with the next delay interval
diff --git a/scheduler/scheduler.cc b/scheduler/scheduler.cc
index e4f93e4..225e484 100644
--- a/scheduler/scheduler.cc
+++ b/scheduler/scheduler.cc
@@ -56,11 +56,14 @@
{
cout << "scheduler loop break error" << endl;
}
- ReadLock lock(m_mutex);
- if (!m_running)
+
{
- cout << "scheduler loop break normal" << endl;
- break;
+ ReadLock lock(m_mutex);
+ if (!m_running)
+ {
+ cout << "scheduler loop break normal" << endl;
+ break;
+ }
}
}
}
@@ -79,13 +82,13 @@
void
Scheduler::shutdown()
{
- WriteLock lock(m_mutex);
- if (m_running)
{
- event_base_loopbreak(m_base);
- m_thread.join();
+ WriteLock lock(m_mutex);
m_running = false;
}
+
+ event_base_loopbreak(m_base);
+ m_thread.join();
}
bool
diff --git a/scheduler/task.cc b/scheduler/task.cc
index cfe48c1..0d09199 100644
--- a/scheduler/task.cc
+++ b/scheduler/task.cc
@@ -60,8 +60,11 @@
void
Task::setTv(double delay)
{
+ // Alex: when using abs function, i would recommend use it with std:: prefix, otherwise
+ // the standard one may be used, which converts everything to INT, making a lot of problems
double intPart, fraction;
- fraction = modf(abs(delay), &intPart);
+ fraction = modf(std::abs(delay), &intPart);
+
m_tv->tv_sec = static_cast<int>(intPart);
m_tv->tv_usec = static_cast<int>((fraction * 1000000));
}