Scheduler: Implement new timer event API
[senf.git] / Scheduler / FIFORunner.hh
index 9121445..2c04bc6 100644 (file)
 #include <boost/utility.hpp>
 #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 Task execution scheduler
@@ -48,7 +52,7 @@ namespace scheduler {
         is posted for the task.
       */
     class FIFORunner
-        : boost::noncopyable
+        : public singleton<FIFORunner>
     {
     public:
         struct TaskInfo;
@@ -56,8 +60,7 @@ namespace scheduler {
     private:
         struct TaskListTag;
         typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
-        typedef TaskListBase::value_traits<TaskInfo> TaskListType;
-        typedef boost::intrusive::ilist<TaskListType, false> TaskList;
+        typedef boost::intrusive::ilist<TaskListBase::value_traits<TaskInfo>, false> TaskList;
 
     public:
         ///////////////////////////////////////////////////////////////////////////
@@ -70,7 +73,7 @@ namespace scheduler {
         struct TaskInfo 
             : public TaskListBase
         {
-            TaskInfo();
+            explicit TaskInfo(std::string const & name_);
             virtual ~TaskInfo();
 
             bool runnable;              ///< Runnable flag
@@ -89,8 +92,8 @@ namespace scheduler {
         ///\name Structors and default members
         ///@{
 
-        FIFORunner();
-        ~FIFORunner();
+        using singleton<FIFORunner>::instance;
+        using singleton<FIFORunner>::alive;
 
         ///@}
         ///////////////////////////////////////////////////////////////////////////
@@ -100,6 +103,9 @@ namespace scheduler {
         
         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
@@ -109,16 +115,24 @@ namespace scheduler {
     protected:
 
     private:
+        FIFORunner();
+        ~FIFORunner();
+
         static void watchdog(int, siginfo_t *, void *);
 
         TaskList tasks_;
         TaskList::iterator next_;
-        int watchdogId_;
+        timer_t watchdogId_;
+        unsigned watchdogMs_;
         std::string runningName_;
 #   ifdef SENF_DEBUG
         std::string runningBacktrace_;
 #   endif
+        unsigned watchdogCount_;
         unsigned hangCount_;
+
+        friend class singleton<FIFORunner>;
+        friend class senf::Scheduler;
     };