/** \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>
#include <boost/utility.hpp>
#include "../boost/intrusive/ilist.hpp"
#include "../boost/intrusive/ilist_hook.hpp"
+#include "../Utils/singleton.hh"
+#include "EventManager.hh"
//#include "FIFORunner.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
namespace scheduler {
- /** \brief
- */
+ void restart();
+
+namespace detail {
+
class FIFORunner
- : boost::noncopyable
+ : public singleton<FIFORunner>
{
public:
struct TaskInfo;
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:
- ///////////////////////////////////////////////////////////////////////////
- // Types
-
- struct TaskInfo
- : public TaskListBase
+ class TaskInfo
+ : public Event,
+ public TaskListBase
{
- TaskInfo();
+ public:
+ enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
+
+ explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
virtual ~TaskInfo();
- bool runnable;
- virtual void run() = 0;
- };
+ void run();
- ///////////////////////////////////////////////////////////////////////////
- ///\name Structors and default members
- ///@{
+ bool runnable() const;
- FIFORunner();
+ protected:
+ void setRunnable();
+
+ private:
+ virtual void v_run() = 0;
+ virtual bool v_enabled() const;
- ///@}
- ///////////////////////////////////////////////////////////////////////////
+ bool runnable_;
+ 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;
void enqueue(TaskInfo * task);
void dequeue(TaskInfo * task);
void run();
+ void taskTimeout(unsigned ms);
+ unsigned taskTimeout() const;
+
+ void startWatchdog();
+ void stopWatchdog();
+
+ unsigned hangCount() const;
+
+ iterator begin() const;
+ iterator end() const;
+
protected:
private:
+ FIFORunner();
+ ~FIFORunner();
+
+ 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
+ std::string runningBacktrace_;
+# endif
+ unsigned watchdogCount_;
+ unsigned hangCount_;
+
+ friend void senf::scheduler::restart();
+ friend class singleton<FIFORunner>;
+ };
-}}
+}}}
///////////////////////////////hh.e////////////////////////////////////////
#include "FIFORunner.cci"