// senf::scheduler::EventHook
prefix_ senf::scheduler::EventHook::EventHook(std::string const & name, Callback const & cb,
- bool initiallyEnabled,
- detail::FIFORunner::TaskInfo::Priority priority)
+ detail::FIFORunner::TaskInfo::Priority priority,
+ bool initiallyEnabled)
: detail::FIFORunner::TaskInfo(name, priority), cb_ (cb)
{
if (initiallyEnabled)
///@{
EventHook(std::string const & name, Callback const & cb,
- bool initiallyEnabled = true, Priority priority = POST);
+ Priority priority, bool initiallyEnabled = true);
///< Register an event hook
/**< Registers \a cb to be called whenever any other event
is signaled by the scheduler. If \a initiallyEnabled is
///////////////////////////////////////////////////////////////////////////
- senf::scheduler::EventHook evev ("eventCounter", eventeventhandler, true,
- senf::scheduler::EventHook::PRE);
+ senf::scheduler::EventHook evev ("eventCounter", eventeventhandler,
+ senf::scheduler::EventHook::PRE);
{
senf::scheduler::FdEvent fde1 ("testFdEvent", boost::bind(&callback, sock, _1),
unsigned count (0);
senf::ClockService::clock_type delay (0);
+ bool haveCb (false);
void jitterCb(senf::scheduler::TimerEvent & tm)
{
std::cerr << senf::scheduler::now() << ' ' << tm.timeout() << '\n';
count ++;
delay += senf::scheduler::now() - tm.timeout();
+ haveCb = true;
tm.timeout(randomDelay());
}
- void logSchedulerTime()
+ void preCb()
{
- std::cerr << senf::scheduler::now() << '\n';
+ haveCb = false;
+ }
+
+ void postCb()
+ {
+ if (! haveCb)
+ std::cerr << senf::scheduler::now() << '\n';
}
void jitterTest()
{
count = 0;
delay = 0;
+ senf::scheduler::EventHook pre ("jitterTest::preCb", &preCb,
+ senf::scheduler::EventHook::PRE);
+ senf::scheduler::EventHook post ("jitterTest::postCb", &postCb,
+ senf::scheduler::EventHook::POST);
+
senf::scheduler::TimerEvent tm1 ("jitterTest::tm1", boost::bind(&jitterCb, boost::ref(tm1)),
randomDelay());
senf::scheduler::TimerEvent tm2 ("jitterTest::tm2", boost::bind(&jitterCb, boost::ref(tm2)),
senf::scheduler::TimerEvent timeout("jitterTest::timeout", &senf::scheduler::terminate,
senf::scheduler::now() + senf::ClockService::seconds(5));
- senf::scheduler::EventHook timerCalled ("jitterTest::logSchedulerTime", &logSchedulerTime,
- senf::scheduler::EventHook::PRE);
-
senf::scheduler::process();
std::cerr << "Average scheduling delay: " << delay/count << "\n";