X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FFIFORunner.hh;h=3887a3d3506e481fc0c1713db50dc2a5e5163a44;hb=03516e8371a90f908ce54dedb3c874eec7dd08ff;hp=3ad8d7e1850380d33531951f5e5708698f0ebca8;hpb=919e588a2c387c9a910aa8761e65155a0d205bba;p=senf.git diff --git a/Scheduler/FIFORunner.hh b/Scheduler/FIFORunner.hh index 3ad8d7e..3887a3d 100644 --- a/Scheduler/FIFORunner.hh +++ b/Scheduler/FIFORunner.hh @@ -27,20 +27,32 @@ #define HH_FIFORunner_ 1 // Custom includes +#include #include #include "../boost/intrusive/ilist.hpp" #include "../boost/intrusive/ilist_hook.hpp" +#include "../Utils/singleton.hh" //#include "FIFORunner.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + + class Scheduler; + namespace scheduler { - /** \brief + /** \brief Task execution scheduler + + 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. + + 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; @@ -48,45 +60,85 @@ 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 - struct TaskInfo + /** \brief Task structure + + TaskInfo is the base-class for all tasks. + */ + class TaskInfo : public TaskListBase { - TaskInfo(); + public: + explicit TaskInfo(std::string const & name); virtual ~TaskInfo(); - bool runnable; + protected: + void setRunnable(); + + private: virtual void run() = 0; + + bool runnable_; + std::string name_; +# ifdef SENF_DEBUG + std::string backtrace_; +# endif + + friend class FIFORunner; }; /////////////////////////////////////////////////////////////////////////// ///\name Structors and default members ///@{ - FIFORunner(); + using singleton::instance; + using singleton::alive; ///@} /////////////////////////////////////////////////////////////////////////// - void enqueue(TaskInfo * task); - void dequeue(TaskInfo * task); + void enqueue(TaskInfo * task); ///< Add task to queue + void dequeue(TaskInfo * task); ///< Remove task from queue - void run(); + void run(); ///< Run queue + + void taskTimeout(unsigned ms); ///< Set task timeout to \a ms milliseconds + unsigned taskTimeout() const; ///< Get task timeout in milliseconds + + 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. */ 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 class singleton; + friend class senf::Scheduler; }; - }} ///////////////////////////////hh.e////////////////////////////////////////