From: g0dil Date: Thu, 19 Mar 2009 18:03:55 +0000 (+0000) Subject: Scheduler: Add senf::scheduler::now() X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=659d27600cc35c7ab211716b709f5e0b1325f10f;p=senf.git Scheduler: Add senf::scheduler::now() PPI: Fix bad EventManager::eventTime() values before launching the scheduler git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@1159 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/PPI/EventManager.cci b/PPI/EventManager.cci index bc3f5e0..d88db89 100644 --- a/PPI/EventManager.cci +++ b/PPI/EventManager.cci @@ -42,7 +42,7 @@ prefix_ senf::ppi::EventManager & senf::ppi::EventManager::instance() prefix_ senf::ClockService::clock_type senf::ppi::EventManager::now() { - return scheduler::eventTime(); + return scheduler::now(); } prefix_ senf::ClockService::clock_type senf::ppi::EventManager::time() diff --git a/Scheduler/FdManager.cci b/Scheduler/FdManager.cci index 7fa9583..79001fe 100644 --- a/Scheduler/FdManager.cci +++ b/Scheduler/FdManager.cci @@ -64,6 +64,7 @@ prefix_ senf::ClockService::clock_type senf::scheduler::detail::FdManager::event return eventTime_; } + /////////////////////////////////////////////////////////////////////////// // senf::scheduler::detail::FdManager::Event diff --git a/Scheduler/FdManager.hh b/Scheduler/FdManager.hh index bf54420..ce34bfa 100644 --- a/Scheduler/FdManager.hh +++ b/Scheduler/FdManager.hh @@ -70,7 +70,7 @@ namespace detail { /**< This call waits until at least one event is posted but no longer than the current timeout(). */ ClockService::clock_type eventTime() const; ///< Time of last event - + protected: private: diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index 9457743..9ea0e48 100644 --- a/Scheduler/Scheduler.cc +++ b/Scheduler/Scheduler.cc @@ -41,6 +41,7 @@ namespace { bool terminate_ (false); + bool running_ (false); } prefix_ void senf::scheduler::terminate() @@ -48,6 +49,16 @@ prefix_ void senf::scheduler::terminate() terminate_ = true; } +prefix_ bool senf::scheduler::running() +{ + return running_; +} + +prefix_ senf::ClockService::clock_type senf::scheduler::now() +{ + return running() ? eventTime() : ClockService::now(); +} + namespace { // We don't want try { } catch(...) { ... throw; } since that will make debugging more @@ -59,6 +70,7 @@ namespace { senf::scheduler::detail::FIFORunner::instance().startWatchdog(); senf::scheduler::detail::SignalDispatcher::instance().unblockSignals(); senf::scheduler::detail::TimerDispatcher::instance().enable(); + running_ = true; } ~SchedulerScopedInit() @@ -66,6 +78,7 @@ namespace { senf::scheduler::detail::TimerDispatcher::instance().disable(); senf::scheduler::detail::SignalDispatcher::instance().blockSignals(); senf::scheduler::detail::FIFORunner::instance().stopWatchdog(); + running_ = false; } }; } @@ -74,6 +87,7 @@ prefix_ void senf::scheduler::process() { SchedulerScopedInit initScheduler; terminate_ = false; + running_ = true; detail::TimerDispatcher::instance().reschedule(); while(! terminate_ && ! (detail::FdDispatcher::instance().empty() && detail::TimerDispatcher::instance().empty() && diff --git a/Scheduler/Scheduler.hh b/Scheduler/Scheduler.hh index 779e04b..9f3d3cd 100644 --- a/Scheduler/Scheduler.hh +++ b/Scheduler/Scheduler.hh @@ -233,7 +233,10 @@ namespace scheduler { \li a callback calls terminate() \li the run queue becomes empty. */ - void process(); + void process(); + + /** \brief \c true, if scheduler is running, \c false otherwise */ + bool running(); /** \brief Called by callbacks to terminate the main loop @@ -249,6 +252,15 @@ namespace scheduler { */ ClockService::clock_type eventTime(); + /** \brief Return (approximate) current time + + This call will return the current time as far as it is already known to the scheduler. If + the scheduler is running, this will return eventTime(), otherwise it will return + ClockService::now(). While the scheduler is running, this will reduce the number of system + calls. + */ + ClockService::clock_type now(); + /** \brief Set watchdog timeout to \a ms milliseconds. Setting the watchdog timeout to 0 will disable the watchdog.