X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FFIFORunner.hh;h=40154d38f23a29834c95780d7b8690eeb277d4b2;hb=635a822c0f03d4a9107672f2d5becb4f3a195a83;hp=adf088fbeaab98db3cc4d1d64d15ac3d5821811b;hpb=ee63e5771e9d69c7fe6de6c1b53b92d1307f2fc1;p=senf.git diff --git a/Scheduler/FIFORunner.hh b/Scheduler/FIFORunner.hh index adf088f..40154d3 100644 --- a/Scheduler/FIFORunner.hh +++ b/Scheduler/FIFORunner.hh @@ -31,6 +31,8 @@ #include #include "../boost/intrusive/ilist.hpp" #include "../boost/intrusive/ilist_hook.hpp" +#include "../Utils/singleton.hh" +#include "EventManager.hh" //#include "FIFORunner.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -38,17 +40,12 @@ namespace senf { namespace scheduler { - /** \brief Task execution scheduler + void restart(); - The FIFORunner implements a simple FIFO scheduler for callback tasks. All tasks are held in - a queue. Whenever a task is run, it is moved to the end of the queue. Running the queue will - run all tasks which have been marked runnable. +namespace detail { - When running a task, it's runnable flag is always reset. The flag is set whenever an event - is posted for the task. - */ class FIFORunner - : boost::noncopyable + : public singleton { public: struct TaskInfo; @@ -56,73 +53,79 @@ namespace scheduler { private: struct TaskListTag; typedef boost::intrusive::ilist_base_hook TaskListBase; - typedef TaskListBase::value_traits TaskListType; - typedef boost::intrusive::ilist TaskList; + typedef boost::intrusive::ilist, false> TaskList; public: - /////////////////////////////////////////////////////////////////////////// - // Types - - /** \brief Task structure - - TaskInfo is the base-class for all tasks. - */ - struct TaskInfo - : public TaskListBase + class TaskInfo + : public Event, + public TaskListBase { - TaskInfo(); + public: + explicit TaskInfo(std::string const & name); virtual ~TaskInfo(); - bool runnable; ///< Runnable flag - /**< This must be set to \c true when the task is - runnable. It is reset automatically when the task is - run. */ + void run(); + + bool runnable() const; + + protected: + void setRunnable(); + + private: + virtual void v_run() = 0; + virtual bool v_enabled() const; - std::string name; ///< Descriptive task name + bool runnable_; # ifdef SENF_DEBUG - std::string backtrace; + std::string backtrace_; # endif - virtual void run() = 0; ///< Called to run the task - }; - /////////////////////////////////////////////////////////////////////////// - ///\name Structors and default members - ///@{ + friend class FIFORunner; + }; - FIFORunner(); - ~FIFORunner(); + typedef boost::filter_iterator< + EventManager::IteratorFilter, TaskList::const_iterator> iterator; - ///@} - /////////////////////////////////////////////////////////////////////////// + using singleton::instance; + using singleton::alive; - void enqueue(TaskInfo * task); ///< Add task to queue - void dequeue(TaskInfo * task); ///< Remove task from queue + void enqueue(TaskInfo * task); + void dequeue(TaskInfo * task); - void run(); ///< Run queue + void run(); - unsigned hangCount() const; ///< Number of task expirations - /**< The FIFORunner manages a watchdog which checks, that a - single task does not run continuously for a longer time - or block. If a task runs for more than 1s, a warning is - printed and the hangCount is increased. */ + void taskTimeout(unsigned ms); + unsigned taskTimeout() const; + + unsigned hangCount() const; + + iterator begin() const; + iterator end() const; protected: private: + FIFORunner(); + ~FIFORunner(); + static void watchdog(int, siginfo_t *, void *); TaskList tasks_; TaskList::iterator next_; timer_t watchdogId_; + unsigned watchdogMs_; std::string runningName_; # ifdef SENF_DEBUG std::string runningBacktrace_; # endif + unsigned watchdogCount_; unsigned hangCount_; - }; + friend void senf::scheduler::restart(); + friend class singleton; + }; -}} +}}} ///////////////////////////////hh.e//////////////////////////////////////// #include "FIFORunner.cci"