X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FFIFORunner.cc;h=b57c66b845501ce8dfd98d6a60c4beff1aa78d2d;hb=bd9f9d3fd6fbcff0112a7bf48ab9284da9576b11;hp=545b4ae208a5419456606f9adf1ad0d3df181203;hpb=3c3f12e715cd474208351347316f59fdaf19ef81;p=senf.git diff --git a/Scheduler/FIFORunner.cc b/Scheduler/FIFORunner.cc index 545b4ae..b57c66b 100644 --- a/Scheduler/FIFORunner.cc +++ b/Scheduler/FIFORunner.cc @@ -29,8 +29,10 @@ // Custom includes #include #include +#include #include "../Utils/Exception.hh" #include "../Utils/senfassert.hh" +#include "../Utils/ScopeExit.hh" //#include "FIFORunner.mpp" #define prefix_ @@ -38,7 +40,7 @@ prefix_ senf::scheduler::detail::FIFORunner::FIFORunner() : tasks_ (), next_ (tasks_.end()), watchdogRunning_ (false), watchdogMs_ (1000), - watchdogCount_(0), hangCount_ (0) + watchdogAbort_ (false), watchdogCount_(0), hangCount_ (0), yield_ (false) { struct sigevent ev; ::memset(&ev, 0, sizeof(ev)); @@ -73,18 +75,22 @@ prefix_ senf::scheduler::detail::FIFORunner::~FIFORunner() prefix_ void senf::scheduler::detail::FIFORunner::startWatchdog() { - struct itimerspec timer; - ::memset(&timer, 0, sizeof(timer)); + if (watchdogMs_ > 0) { + struct itimerspec timer; + ::memset(&timer, 0, sizeof(timer)); - timer.it_interval.tv_sec = watchdogMs_ / 1000; - timer.it_interval.tv_nsec = (watchdogMs_ % 1000) * 1000000ul; - timer.it_value.tv_sec = timer.it_interval.tv_sec; - timer.it_value.tv_nsec = timer.it_interval.tv_nsec; - - if (timer_settime(watchdogId_, 0, &timer, 0) < 0) - SENF_THROW_SYSTEM_EXCEPTION("timer_settime()"); + timer.it_interval.tv_sec = watchdogMs_ / 1000; + timer.it_interval.tv_nsec = (watchdogMs_ % 1000) * 1000000ul; + timer.it_value.tv_sec = timer.it_interval.tv_sec; + timer.it_value.tv_nsec = timer.it_interval.tv_nsec; + + if (timer_settime(watchdogId_, 0, &timer, 0) < 0) + SENF_THROW_SYSTEM_EXCEPTION("timer_settime()"); - watchdogRunning_ = true; + watchdogRunning_ = true; + } + else + stopWatchdog(); } prefix_ void senf::scheduler::detail::FIFORunner::stopWatchdog() @@ -130,20 +136,34 @@ prefix_ void senf::scheduler::detail::FIFORunner::dequeue(TaskInfo * task) prefix_ void senf::scheduler::detail::FIFORunner::run() { - TaskList::iterator f (tasks_.begin()); - TaskList::iterator l (TaskList::current(highPriorityEnd_)); - run(f, l); + for(;;) { + TaskList::iterator f (tasks_.begin()); + TaskList::iterator l (TaskList::current(highPriorityEnd_)); + run(f, l); + if (yield_) { + yield_ = false; + continue; + } - f = l; ++f; - l = TaskList::current(normalPriorityEnd_); - run(f, l); - - f = l; ++f; - l = tasks_.end(); - run(f, l); + f = l; ++f; + l = TaskList::current(normalPriorityEnd_); + run(f, l); + if (yield_) { + yield_ = false; + continue; + } + + f = l; ++f; + l = tasks_.end(); + run(f, l); + if (yield_) { + yield_ = false; + continue; + } + break; + } } - prefix_ void senf::scheduler::detail::FIFORunner::run(TaskList::iterator f, TaskList::iterator l) { if (f == l) @@ -164,32 +184,33 @@ prefix_ void senf::scheduler::detail::FIFORunner::run(TaskList::iterator f, Task tasks_.insert(l, null); TaskList::iterator end (TaskList::current(null)); next_ = f; - try { - while (next_ != end) { - TaskInfo & task (*next_); - if (task.runnable_) { - task.runnable_ = false; - runningName_ = task.name(); -# ifdef SENF_DEBUG - runningBacktrace_ = task.backtrace_; -# endif - TaskList::iterator i (next_); - ++ next_; - tasks_.splice(l, tasks_, i); - watchdogCount_ = 1; - task.run(); - } - else - ++ next_; + + using namespace boost::lambda; + ScopeExit atExit (( + var(watchdogCount_) = 0, + var(next_) = l + )); + + while (next_ != end) { + TaskInfo & task (*next_); + if (task.runnable_) { + task.runnable_ = false; + runningName_ = task.name(); +# ifdef SENF_DEBUG + runningBacktrace_ = task.backtrace_; +# endif + TaskList::iterator i (next_); + ++ next_; + tasks_.splice(l, tasks_, i); + watchdogCount_ = 1; + yield_ = false; + task.run(); + if (yield_) + return; } + else + ++ next_; } - catch (...) { - watchdogCount_ = 0; - next_ = l; - throw; - } - watchdogCount_ = 0; - next_ = l; } prefix_ senf::scheduler::detail::FIFORunner::TaskList::iterator @@ -221,6 +242,8 @@ prefix_ void senf::scheduler::detail::FIFORunner::watchdog(int, siginfo_t * si, write(1, runner.runningBacktrace_.c_str(), runner.runningBacktrace_.size()); #endif write(1, "\n", 1); + if (runner.watchdogAbort_) + assert(false); } } }