#define HH_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 "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
+ class TaskInfo
: public TaskListBase
{
- TaskInfo();
+ public:
+ explicit TaskInfo(std::string const & name);
virtual ~TaskInfo();
- bool runnable;
+ protected:
+ void setRunnable();
+
+ private:
virtual void run() = 0;
- };
- ///////////////////////////////////////////////////////////////////////////
- ///\name Structors and default members
- ///@{
+ bool runnable_;
+ std::string name_;
+# ifdef SENF_DEBUG
+ std::string backtrace_;
+# endif
- FIFORunner();
-
- ///@}
- ///////////////////////////////////////////////////////////////////////////
+ friend class FIFORunner;
+ };
+ 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;
+
+ 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. */
+
protected:
private:
+ FIFORunner();
+ ~FIFORunner();
+
+ static void watchdog(int, siginfo_t *, void *);
+
TaskList tasks_;
TaskList::iterator next_;
+ timer_t watchdogId_;
+ 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"