Scheduler: Implement new file descriptor event API
[senf.git] / Scheduler / FIFORunner.hh
index 464d4f4..3887a3d 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:
         ///////////////////////////////////////////////////////////////////////////
@@ -67,30 +70,34 @@ namespace scheduler {
 
             TaskInfo is the base-class for all tasks.
          */
-        struct TaskInfo 
+        class TaskInfo 
             : public TaskListBase
         {
-            TaskInfo();
+        public:
+            explicit TaskInfo(std::string const & name);
             virtual ~TaskInfo();
 
-            bool runnable;              ///< Runnable flag
-                                        /**< This must be set to \c true when the task is
-                                             runnable. It is reset automatically when the task is
-                                             run. */
+        protected:
+            void setRunnable();
+            
+        private:
+            virtual void run() = 0;
 
-            std::string name;           ///< Descriptive task name
+            bool runnable_;
+            std::string name_;
 #       ifdef SENF_DEBUG
-            std::string backtrace;
+            std::string backtrace_;
 #       endif
-            virtual void run() = 0;     ///< Called to run the task
+
+            friend class FIFORunner;
         };
 
         ///////////////////////////////////////////////////////////////////////////
         ///\name Structors and default members
         ///@{
 
-        FIFORunner();
-        ~FIFORunner();
+        using singleton<FIFORunner>::instance;
+        using singleton<FIFORunner>::alive;
 
         ///@}
         ///////////////////////////////////////////////////////////////////////////
@@ -112,6 +119,9 @@ namespace scheduler {
     protected:
 
     private:
+        FIFORunner();
+        ~FIFORunner();
+
         static void watchdog(int, siginfo_t *, void *);
 
         TaskList tasks_;
@@ -124,8 +134,10 @@ namespace scheduler {
 #   endif
         unsigned watchdogCount_;
         unsigned hangCount_;
-    };
 
+        friend class singleton<FIFORunner>;
+        friend class senf::Scheduler;
+    };
 
 }}