PPI: Add missing TargetDgramWriter doku
[senf.git] / Scheduler / FIFORunner.hh
index 49d62fa..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>
@@ -61,11 +61,15 @@ namespace detail {
               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();
             
@@ -74,6 +78,7 @@ namespace detail {
             virtual bool v_enabled() const;
 
             bool runnable_;
+            Priority priority_;
 #       ifdef SENF_DEBUG
             std::string backtrace_;
 #       endif
@@ -81,6 +86,9 @@ namespace detail {
             friend class FIFORunner;
         };
 
+        typedef boost::filter_iterator<
+            EventManager::IteratorFilter, TaskList::const_iterator> iterator;
+
         using singleton<FIFORunner>::instance;
         using singleton<FIFORunner>::alive;
 
@@ -91,8 +99,16 @@ namespace detail {
 
         void taskTimeout(unsigned ms);
         unsigned taskTimeout() const;
+        void abortOnTimeout(bool flag);
+        bool abortOnTimeout() const;
 
-        unsigned hangCount() const;
+        void startWatchdog();
+        void stopWatchdog();
+
+        unsigned hangCount();
+
+        iterator begin() const;
+        iterator end() const;
 
     protected:
 
@@ -102,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_;