3ad8d7e1850380d33531951f5e5708698f0ebca8
[senf.git] / Scheduler / FIFORunner.hh
1 // $Id$
2 //
3 // Copyright (C) 2008 
4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 //     Stefan Bund <g0dil@berlios.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief FIFORunner public header */
25
26 #ifndef HH_FIFORunner_
27 #define HH_FIFORunner_ 1
28
29 // Custom includes
30 #include <boost/utility.hpp>
31 #include "../boost/intrusive/ilist.hpp"
32 #include "../boost/intrusive/ilist_hook.hpp"
33
34 //#include "FIFORunner.mpp"
35 ///////////////////////////////hh.p////////////////////////////////////////
36
37 namespace senf { 
38 namespace scheduler {
39
40     /** \brief
41       */
42     class FIFORunner
43         : boost::noncopyable
44     {
45     public:
46         struct TaskInfo;
47
48     private:
49         struct TaskListTag;
50         typedef boost::intrusive::ilist_base_hook<TaskListTag> TaskListBase;
51         typedef TaskListBase::value_traits<TaskInfo> TaskListType;
52         typedef boost::intrusive::ilist<TaskListType, false> TaskList;
53
54     public:
55         ///////////////////////////////////////////////////////////////////////////
56         // Types
57
58         struct TaskInfo 
59             : public TaskListBase
60         {
61             TaskInfo();
62             virtual ~TaskInfo();
63
64             bool runnable;
65             virtual void run() = 0;
66         };
67
68         ///////////////////////////////////////////////////////////////////////////
69         ///\name Structors and default members
70         ///@{
71
72         FIFORunner();
73
74         ///@}
75         ///////////////////////////////////////////////////////////////////////////
76
77         void enqueue(TaskInfo * task);
78         void dequeue(TaskInfo * task);
79         
80         void run();
81
82     protected:
83
84     private:
85         TaskList tasks_;
86         TaskList::iterator next_;
87     };
88
89
90 }}
91
92 ///////////////////////////////hh.e////////////////////////////////////////
93 #include "FIFORunner.cci"
94 //#include "FIFORunner.ct"
95 //#include "FIFORunner.cti"
96 #endif
97
98 \f
99 // Local Variables:
100 // mode: c++
101 // fill-column: 100
102 // comment-column: 40
103 // c-file-style: "senf"
104 // indent-tabs-mode: nil
105 // ispell-local-dictionary: "american"
106 // compile-command: "scons -u test"
107 // End: