4 // Fraunhofer Institute for Open Communication Systems (FOKUS)
5 // Competence Center NETwork research (NET), St. Augustin, GERMANY
6 // Stefan Bund <g0dil@berlios.de>
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.
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.
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.
24 \brief Scheduler non-inline non-template implementation
26 \idea Multithreading support: To support multithreading, the
27 static member Scheduler::instance() must return a thread-local
28 value (that is Scheduler::instance() must allocate one Scheduler
29 instance per thread). Another possibility would be to distribute
30 the async load unto several threads (one scheduler for multiple
34 #include "Scheduler.hh"
35 //#include "Scheduler.ih"
40 ///////////////////////////////cc.p////////////////////////////////////////
43 bool terminate_ (false);
46 prefix_ void senf::scheduler::terminate()
51 prefix_ void senf::scheduler::process()
54 while(! terminate_ && ! (detail::FdDispatcher::instance().empty() &&
55 detail::TimerDispatcher::instance().empty() &&
56 detail::FileDispatcher::instance().empty())) {
57 detail::SignalDispatcher::instance().unblockSignals();
58 detail::TimerDispatcher::instance().unblockSignals();
59 detail::FdManager::instance().processOnce();
60 detail::TimerDispatcher::instance().blockSignals();
61 detail::SignalDispatcher::instance().blockSignals();
62 detail::FileDispatcher::instance().prepareRun();
63 detail::EventHookDispatcher::instance().prepareRun();
64 detail::FIFORunner::instance().run();
68 prefix_ void senf::scheduler::restart()
70 detail::FdManager* fdm (&detail::FdManager::instance());
71 detail::FIFORunner* ffr (&detail::FIFORunner::instance());
72 detail::FdDispatcher* fdd (&detail::FdDispatcher::instance());
73 detail::TimerDispatcher* tdd (&detail::TimerDispatcher::instance());
74 detail::SignalDispatcher* sdd (&detail::SignalDispatcher::instance());
75 detail::FileDispatcher* fld (&detail::FileDispatcher::instance());
76 detail::EventHookDispatcher* eed (&detail::EventHookDispatcher::instance());
78 eed->~EventHookDispatcher();
79 fld->~FileDispatcher();
80 sdd->~SignalDispatcher();
81 tdd->~TimerDispatcher();
86 new (fdm) detail::FdManager();
87 new (ffr) detail::FIFORunner();
88 new (fdd) detail::FdDispatcher();
89 new (tdd) detail::TimerDispatcher();
90 new (sdd) detail::SignalDispatcher();
91 new (fld) detail::FileDispatcher();
92 new (eed) detail::EventHookDispatcher();
95 prefix_ bool senf::scheduler::empty()
97 return detail::FdDispatcher::instance().empty()
98 && detail::TimerDispatcher::instance().empty()
99 && detail::FileDispatcher::instance().empty()
100 && detail::SignalDispatcher::instance().empty()
101 && detail::EventHookDispatcher::instance().empty();
104 ///////////////////////////////////////////////////////////////////////////
105 // senf::schedulerLogTimeSource
107 prefix_ senf::log::time_type senf::scheduler::LogTimeSource::operator()()
113 ///////////////////////////////cc.e////////////////////////////////////////
120 // c-file-style: "senf"
121 // indent-tabs-mode: nil
122 // ispell-local-dictionary: "american"
123 // compile-command: "scons -u test"
124 // comment-column: 40