Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

FIFORunner.hh

Go to the documentation of this file.
00001 // $Id: FIFORunner.hh 1781 2011-04-11 12:10:19Z tho $
00002 //
00003 // Copyright (C) 2008
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Scheduler_FIFORunner_
00027 #define HH_SENF_Scheduler_FIFORunner_ 1
00028 
00029 // Custom includes
00030 #include <signal.h>
00031 #include <boost/utility.hpp>
00032 #include <senf/boost_intrusive/ilist.hpp>
00033 #include <senf/boost_intrusive/ilist_hook.hpp>
00034 #include <senf/Utils/singleton.hh>
00035 #include "EventManager.hh"
00036 
00037 //#include "FIFORunner.mpp"
00038 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00039 
00040 namespace senf {
00041 namespace scheduler {
00042 
00043     void restart();
00044 
00045 namespace detail {
00046 
00047     class FIFORunner
00048         : public singleton<FIFORunner>
00049     {
00050     public:
00051         struct TaskInfo;
00052 
00053     private:
00054         struct TaskListTag;
00055         typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
00056         typedef boost::intrusive::ilist<TaskListBase::value_traits<TaskInfo>, false> TaskList;
00057 
00058     public:
00059         class TaskInfo
00060             : public Event,
00061               public TaskListBase
00062         {
00063         public:
00064             enum Priority { PRIORITY_LOW = 0, PRIORITY_NORMAL = 1, PRIORITY_HIGH = 2 };
00065 
00066             explicit TaskInfo(std::string const & name, Priority priority=PRIORITY_NORMAL);
00067             virtual ~TaskInfo();
00068 
00069             void run();
00070 
00071             bool runnable() const;
00072 
00073         protected:
00074             void setRunnable();
00075 
00076         private:
00077             virtual void v_run() = 0;
00078             virtual bool v_enabled() const;
00079 
00080             bool runnable_;
00081             Priority priority_;
00082             std::string backtrace_; // only used if SENF_BACKTRACE is defined.
00083 
00084             friend class FIFORunner;
00085         };
00086 
00087         typedef boost::filter_iterator<
00088             EventManager::IteratorFilter, TaskList::const_iterator> iterator;
00089 
00090         using singleton<FIFORunner>::instance;
00091         using singleton<FIFORunner>::alive;
00092 
00093         void enqueue(TaskInfo * task);
00094         void dequeue(TaskInfo * task);
00095 
00096         void run();
00097 
00098         void taskTimeout(unsigned ms);
00099         unsigned taskTimeout() const;
00100         void abortOnTimeout(bool flag);
00101         bool abortOnTimeout() const;
00102 
00103         void startWatchdog();
00104         void stopWatchdog();
00105 
00106         unsigned hangCount();
00107 
00108         iterator begin() const;
00109         iterator end() const;
00110 
00111         void yield();
00112 
00113     protected:
00114 
00115     private:
00116         FIFORunner();
00117         ~FIFORunner();
00118 
00119         static void watchdog(int, siginfo_t *, void *);
00120         void watchdogError();
00121 
00122         TaskList::iterator priorityEnd(TaskInfo::Priority p);
00123         void run(TaskList::iterator f, TaskList::iterator l);
00124 
00125         struct NullTask : public TaskInfo
00126         {
00127             NullTask();
00128             ~NullTask();
00129             virtual void v_run();;
00130             virtual char const * v_type() const;
00131             virtual std::string v_info() const;
00132         };
00133 
00134         TaskList tasks_;
00135         TaskList::iterator next_;
00136 
00137         NullTask normalPriorityEnd_;
00138         NullTask highPriorityEnd_;
00139 
00140         timer_t watchdogId_;
00141         bool watchdogRunning_;
00142         unsigned watchdogMs_;
00143         bool watchdogAbort_;
00144         std::string runningName_;
00145 #   ifdef SENF_DEBUG
00146         std::string runningBacktrace_;
00147 #   endif
00148         unsigned watchdogCount_;
00149         unsigned hangCount_;
00150         bool yield_;
00151 
00152         friend void senf::scheduler::restart();
00153         friend class singleton<FIFORunner>;
00154     };
00155 
00156 }}}
00157 
00158 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00159 #include "FIFORunner.cci"
00160 //#include "FIFORunner.ct"
00161 //#include "FIFORunner.cti"
00162 #endif
00163 
00164 
00165 // Local Variables:
00166 // mode: c++
00167 // fill-column: 100
00168 // comment-column: 40
00169 // c-file-style: "senf"
00170 // indent-tabs-mode: nil
00171 // ispell-local-dictionary: "american"
00172 // compile-command: "scons -u test"
00173 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research