X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FScheduler.cc;h=3203d205e7f7d399ec67dc275a57575ea99bf291;hb=8057a9e389e33771aad9c78538f76d0e82ad7adb;hp=e7550bb0a1467823746837e8b10935917bdce44e;hpb=3c3f12e715cd474208351347316f59fdaf19ef81;p=senf.git diff --git a/Scheduler/Scheduler.cc b/Scheduler/Scheduler.cc index e7550bb..3203d20 100644 --- a/Scheduler/Scheduler.cc +++ b/Scheduler/Scheduler.cc @@ -48,31 +48,43 @@ prefix_ void senf::scheduler::terminate() terminate_ = true; } +namespace { + + // We don't want try { } catch(...) { ... throw; } since that will make debugging more + // difficult: the stack backtrace for an unexpected exception would always end here. + struct SchedulerScopedInit + { + SchedulerScopedInit() + { + senf::scheduler::detail::FIFORunner::instance().startWatchdog(); + senf::scheduler::detail::SignalDispatcher::instance().unblockSignals(); + senf::scheduler::detail::TimerDispatcher::instance().enable(); + } + + ~SchedulerScopedInit() + { + senf::scheduler::detail::TimerDispatcher::instance().disable(); + senf::scheduler::detail::SignalDispatcher::instance().blockSignals(); + senf::scheduler::detail::FIFORunner::instance().stopWatchdog(); + } + }; +} + prefix_ void senf::scheduler::process() { - try { - detail::FIFORunner::instance().startWatchdog(); - detail::SignalDispatcher::instance().unblockSignals(); - detail::TimerDispatcher::instance().unblockSignals(); - terminate_ = false; - while(! terminate_ && ! (detail::FdDispatcher::instance().empty() && - detail::TimerDispatcher::instance().empty() && - detail::FileDispatcher::instance().empty())) { - detail::FdManager::instance().processOnce(); - detail::FileDispatcher::instance().prepareRun(); - detail::EventHookDispatcher::instance().prepareRun(); - detail::FIFORunner::instance().run(); - } - } - catch(...) { - detail::TimerDispatcher::instance().blockSignals(); - detail::SignalDispatcher::instance().blockSignals(); - detail::FIFORunner::instance().stopWatchdog(); - throw; + SchedulerScopedInit initScheduler; + terminate_ = false; + detail::TimerDispatcher::instance().reschedule(); + while(! terminate_ && ! (detail::FdDispatcher::instance().empty() && + detail::TimerDispatcher::instance().empty() && + detail::FileDispatcher::instance().empty())) { + detail::FdManager::instance().processOnce(); + detail::FileDispatcher::instance().prepareRun(); + detail::EventHookDispatcher::instance().prepareRun(); + detail::TimerDispatcher::instance().prepareRun(); + detail::FIFORunner::instance().run(); + detail::TimerDispatcher::instance().reschedule(); } - detail::TimerDispatcher::instance().blockSignals(); - detail::SignalDispatcher::instance().blockSignals(); - detail::FIFORunner::instance().stopWatchdog(); } prefix_ void senf::scheduler::restart()