X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Scheduler%2FFIFORunner.hh;h=6513f72396485bc575b2e800e995376db6438915;hb=5443435c4c2b6e4386c5334b5b8358273f2bae93;hp=756f07fc4db38f98536ec8d3778f95c95ff6bc50;hpb=925317c7f45c32b01ab9292023db3f372b74bf0f;p=senf.git diff --git a/Scheduler/FIFORunner.hh b/Scheduler/FIFORunner.hh index 756f07f..6513f72 100644 --- a/Scheduler/FIFORunner.hh +++ b/Scheduler/FIFORunner.hh @@ -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 @@ -32,25 +32,18 @@ #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 { - - class Scheduler; - namespace scheduler { - /** \brief Task execution scheduler + void restart(); - The FIFORunner implements a simple FIFO scheduler for callback tasks. All tasks are held in - a queue. Whenever a task is run, it is moved to the end of the queue. Running the queue will - run all tasks which have been marked runnable. +namespace detail { - When running a task, it's runnable flag is always reset. The flag is set whenever an event - is posted for the task. - */ class FIFORunner : public singleton { @@ -63,54 +56,61 @@ namespace scheduler { typedef boost::intrusive::ilist, false> TaskList; public: - /////////////////////////////////////////////////////////////////////////// - // Types - - /** \brief Task structure - - TaskInfo is the base-class for all tasks. - */ - 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; ///< Runnable flag - /**< This must be set to \c true when the task is - runnable. It is reset automatically when the task is - run. */ + void run(); - std::string name; ///< Descriptive task name + bool runnable() const; + + protected: + void setRunnable(); + + private: + virtual void v_run() = 0; + virtual bool v_enabled() const; + + bool runnable_; + Priority priority_; # 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 - ///@{ + typedef boost::filter_iterator< + EventManager::IteratorFilter, TaskList::const_iterator> iterator; using singleton::instance; using singleton::alive; - ///@} - /////////////////////////////////////////////////////////////////////////// - - void enqueue(TaskInfo * task); ///< Add task to queue - void dequeue(TaskInfo * task); ///< Remove task from queue + void enqueue(TaskInfo * task); + void dequeue(TaskInfo * task); - void run(); ///< Run queue + void run(); + + void taskTimeout(unsigned ms); + unsigned taskTimeout() const; + void abortOnTimeout(bool flag); + bool abortOnTimeout() const; - void taskTimeout(unsigned ms); ///< Set task timeout to \a ms milliseconds - unsigned taskTimeout() const; ///< Get task timeout in milliseconds + void startWatchdog(); + void stopWatchdog(); - 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. */ + unsigned hangCount(); + + iterator begin() const; + iterator end() const; + + void yield(); protected: @@ -120,23 +120,41 @@ namespace scheduler { 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_; # endif unsigned watchdogCount_; unsigned hangCount_; + bool yield_; + friend void senf::scheduler::restart(); friend class singleton; - friend class senf::Scheduler; }; - -}} +}}} ///////////////////////////////hh.e//////////////////////////////////////// #include "FIFORunner.cci"