From: g0dil Date: Sun, 5 Oct 2008 20:24:33 +0000 (+0000) Subject: Scheduler: Sort 'events' list by priority X-Git-Url: http://g0dil.de/git?a=commitdiff_plain;h=989a3b185a4e8854a1a1a01c5b190c9e6dcaf2af;p=senf.git Scheduler: Sort 'events' list by priority git-svn-id: https://svn.berlios.de/svnroot/repos/senf/trunk@928 270642c3-0616-0410-b53a-bc976706d245 --- diff --git a/Scheduler/EventManager.cc b/Scheduler/EventManager.cc index 0743cb6..fdea03a 100644 --- a/Scheduler/EventManager.cc +++ b/Scheduler/EventManager.cc @@ -46,24 +46,35 @@ prefix_ senf::scheduler::detail::EventManager::EventManager() prefix_ void senf::scheduler::detail::EventManager::consoleEvents(std::ostream & os) { - iterator i (begin()); - iterator const i_end (end()); - // On an 80 column display, this wraps nicely directly before the RUN column - os << boost::format("%-6s %-52s %-10s %-8s %7s %s\n") - % "TYPE" - % "NAME" - % "ADDRESS" - % "ACTIVE?" - % "RUN" - % "INFO"; - for (; i != i_end; ++i) - os << boost::format("%-6.6s %-52.52s 0x%08x %-8.8s %7d %s\n") - % i->type() - % i->name() - % reinterpret_cast(&(*i)) - % (i->enabled() ? "enabled" : "disabled") - % i->runCount() - % i->info(); + // On an 80 column display, this wraps nicely directly before the INFO column + boost::format fmt ("%s %-55.55s 0x%08x %8d %s %s\n"); + os << boost::format("%s %-55.55s %-10s %8s %s %s\n") + % "TP" % "NAME" % "ADDRESS" % "RUNCNT" % "S" % "INFO"; + { + FIFORunner::iterator i (FIFORunner::instance().begin()); + FIFORunner::iterator const i_end (FIFORunner::instance().end()); + for (; i != i_end; ++i) + os << fmt + % i->type() + % i->name() + % reinterpret_cast(&(*i)) + % i->runCount() + % (i->runnable() ? "R" : "W") + % i->info(); + } + { + iterator i (begin()); + iterator const i_end (end()); + for (; i != i_end; ++i) + if (! i->enabled()) + os << fmt + % i->type() + % i->name() + % reinterpret_cast(&(*i)) + % i->runCount() + % "-" + % i->info(); + } } ///////////////////////////////cc.e//////////////////////////////////////// diff --git a/Scheduler/EventManager.cci b/Scheduler/EventManager.cci index 010e8f2..8399ef8 100644 --- a/Scheduler/EventManager.cci +++ b/Scheduler/EventManager.cci @@ -103,14 +103,16 @@ senf::scheduler::detail::EventManager::begin() { // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added // by the FIFORunner is such an element and must be skipped. - return boost::make_filter_iterator(IteratorFilter(), events_.begin(), events_.end()); + return boost::make_filter_iterator( + IteratorFilter(), events_.begin(), events_.end()); } prefix_ senf::scheduler::detail::EventManager::iterator senf::scheduler::detail::EventManager::end() const { - return boost::make_filter_iterator(IteratorFilter(), events_.end(), events_.end()); + return boost::make_filter_iterator( + IteratorFilter(), events_.end(), events_.end()); } ///////////////////////////////cci.e/////////////////////////////////////// diff --git a/Scheduler/EventManager.hh b/Scheduler/EventManager.hh index 56a32ae..eff1fab 100644 --- a/Scheduler/EventManager.hh +++ b/Scheduler/EventManager.hh @@ -88,15 +88,16 @@ namespace detail { class EventManager : public singleton { - struct IteratorFilter { - bool operator()(Event const & e); - }; - public: using singleton::instance; using singleton::alive; - typedef boost::filter_iterator iterator; + struct IteratorFilter { + bool operator()(Event const & e); + }; + + typedef boost::filter_iterator< + IteratorFilter, EventList::const_iterator> iterator; void add(Event & event); void remove(Event & event); diff --git a/Scheduler/FIFORunner.cci b/Scheduler/FIFORunner.cci index fb08059..585bf6e 100644 --- a/Scheduler/FIFORunner.cci +++ b/Scheduler/FIFORunner.cci @@ -48,8 +48,15 @@ prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::setRunnable() prefix_ void senf::scheduler::detail::FIFORunner::TaskInfo::run() { - v_run(); countRun(); + // Be sure to run v_run last since the callback may destroy this instance + v_run(); +} + +prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::runnable() + const +{ + return runnable_; } prefix_ bool senf::scheduler::detail::FIFORunner::TaskInfo::v_enabled() @@ -85,6 +92,23 @@ prefix_ unsigned senf::scheduler::detail::FIFORunner::hangCount() return hangCount_; } +prefix_ senf::scheduler::detail::FIFORunner::iterator +senf::scheduler::detail::FIFORunner::begin() + const +{ + // We need to filter out elements with e.type() == 0 ... the NullTask temporarily added is such + // an element and must be skipped. + return boost::make_filter_iterator( + EventManager::IteratorFilter(), tasks_.begin(), tasks_.end()); +} + +prefix_ senf::scheduler::detail::FIFORunner::iterator senf::scheduler::detail::FIFORunner::end() + const +{ + return boost::make_filter_iterator( + EventManager::IteratorFilter(), tasks_.end(), tasks_.end()); +} + ///////////////////////////////cci.e/////////////////////////////////////// #undef prefix_ diff --git a/Scheduler/FIFORunner.hh b/Scheduler/FIFORunner.hh index 49d62fa..40154d3 100644 --- a/Scheduler/FIFORunner.hh +++ b/Scheduler/FIFORunner.hh @@ -66,6 +66,8 @@ namespace detail { void run(); + bool runnable() const; + protected: void setRunnable(); @@ -81,6 +83,9 @@ namespace detail { friend class FIFORunner; }; + typedef boost::filter_iterator< + EventManager::IteratorFilter, TaskList::const_iterator> iterator; + using singleton::instance; using singleton::alive; @@ -94,6 +99,9 @@ namespace detail { unsigned hangCount() const; + iterator begin() const; + iterator end() const; + protected: private: diff --git a/Scheduler/SignalEvent.cc b/Scheduler/SignalEvent.cc index d66d506..a521bd8 100644 --- a/Scheduler/SignalEvent.cc +++ b/Scheduler/SignalEvent.cc @@ -127,7 +127,7 @@ prefix_ void senf::scheduler::SignalEvent::v_run() prefix_ char const * senf::scheduler::SignalEvent::v_type() const { - return "signal"; + return "si"; } prefix_ std::string senf::scheduler::SignalEvent::v_info() diff --git a/Scheduler/TimerEvent.cc b/Scheduler/TimerEvent.cc index 572b3c1..f3113e4 100644 --- a/Scheduler/TimerEvent.cc +++ b/Scheduler/TimerEvent.cc @@ -173,7 +173,7 @@ prefix_ void senf::scheduler::TimerEvent::v_run() prefix_ char const * senf::scheduler::TimerEvent::v_type() const { - return "timer"; + return "tm"; } prefix_ std::string senf::scheduler::TimerEvent::v_info()