Fix Build-Depends in debian/control
[senf.git] / Scheduler / FIFORunner.hh
index a6db0a5..39e2e3a 100644 (file)
@@ -23,8 +23,8 @@
 /** \file
     \brief FIFORunner public header */
 
-#ifndef HH_FIFORunner_
-#define HH_FIFORunner_ 1
+#ifndef HH_SENF_Scheduler_FIFORunner_
+#define HH_SENF_Scheduler_FIFORunner_ 1
 
 // Custom includes
 #include <signal.h>
@@ -32,6 +32,7 @@
 #include "../boost/intrusive/ilist.hpp"
 #include "../boost/intrusive/ilist_hook.hpp"
 #include "../Utils/singleton.hh"
+#include "EventManager.hh"
 
 //#include "FIFORunner.mpp"
 ///////////////////////////////hh.p////////////////////////////////////////
@@ -56,26 +57,38 @@ namespace detail {
 
     public:
         class TaskInfo 
-            : public TaskListBase
+            : public Event, 
+              public TaskListBase
         {
         public:
-            explicit TaskInfo(std::string const & name);
+            enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
+
+            explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
             virtual ~TaskInfo();
 
+            void run();
+
+            bool runnable() const;
+
         protected:
             void setRunnable();
             
         private:
-            virtual void run() = 0;
+            virtual void v_run() = 0;
+            virtual bool v_enabled() const;
 
             bool runnable_;
-            std::string name_;
+            Priority priority_;
 #       ifdef SENF_DEBUG
             std::string backtrace_;
 #       endif
 
             friend class FIFORunner;
         };
+
+        typedef boost::filter_iterator<
+            EventManager::IteratorFilter, TaskList::const_iterator> iterator;
+
         using singleton<FIFORunner>::instance;
         using singleton<FIFORunner>::alive;
 
@@ -86,12 +99,16 @@ namespace detail {
 
         void taskTimeout(unsigned ms);
         unsigned taskTimeout() const;
+        void abortOnTimeout(bool flag);
+        bool abortOnTimeout() const;
+
+        void startWatchdog();
+        void stopWatchdog();
+
+        unsigned hangCount();
 
-        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. */
+        iterator begin() const;
+        iterator end() const;
 
     protected:
 
@@ -101,10 +118,28 @@ namespace detail {
 
         static void watchdog(int, siginfo_t *, void *);
 
+        TaskList::iterator priorityEnd(TaskInfo::Priority p);
+        void run(TaskList::iterator f, TaskList::iterator l);
+        
+        struct NullTask : public TaskInfo
+        {
+            NullTask();
+            ~NullTask();
+            virtual void v_run();;
+            virtual char const * v_type() const;
+            virtual std::string v_info() const;
+        };
+
         TaskList tasks_;
         TaskList::iterator next_;
+
+        NullTask normalPriorityEnd_;
+        NullTask highPriorityEnd_;
+        
         timer_t watchdogId_;
+        bool watchdogRunning_;
         unsigned watchdogMs_;
+        bool watchdogAbort_;
         std::string runningName_;
 #   ifdef SENF_DEBUG
         std::string runningBacktrace_;