Scheduler: Factor out TimerSource from TimerDispatcher and implement POSIXTimerSource
[senf.git] / Scheduler / FIFORunner.hh
index 40154d3..27b626f 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,7 +61,9 @@ 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();
@@ -76,6 +78,7 @@ namespace detail {
             virtual bool v_enabled() const;
 
             bool runnable_;
+            Priority priority_;
 #       ifdef SENF_DEBUG
             std::string backtrace_;
 #       endif
@@ -97,6 +100,9 @@ namespace detail {
         void taskTimeout(unsigned ms);
         unsigned taskTimeout() const;
 
+        void startWatchdog();
+        void stopWatchdog();
+
         unsigned hangCount() const;
 
         iterator begin() const;
@@ -110,9 +116,26 @@ 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_;
         std::string runningName_;
 #   ifdef SENF_DEBUG