2d137819911346fa8b75f71982556d0d770cee2a
[senf.git] / Scheduler / Scheduler.cc
1 // $Id$
2 //
3 // Copyright (C) 2006
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 Scheduler non-inline non-template implementation
25
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
31     threads)
32  */
33
34 #include "Scheduler.hh"
35 //#include "Scheduler.ih"
36
37 // Custom includes
38 #include "SignalEvent.hh"
39
40 #define prefix_
41 ///////////////////////////////cc.p////////////////////////////////////////
42
43 prefix_ void senf::Scheduler::process()
44 {
45     terminate_ = false;
46     while(! terminate_ && ! (scheduler::detail::FdDispatcher::instance().empty() &&
47                              scheduler::detail::TimerDispatcher::instance().empty() &&
48                              scheduler::detail::FileDispatcher::instance().empty())) {
49         scheduler::detail::SignalDispatcher::instance().unblockSignals();
50         scheduler::detail::TimerDispatcher::instance().unblockSignals();
51         scheduler::FdManager::instance().processOnce();
52         scheduler::detail::TimerDispatcher::instance().blockSignals();
53         scheduler::detail::SignalDispatcher::instance().blockSignals();
54         scheduler::detail::FileDispatcher::instance().prepareRun();
55         scheduler::FIFORunner::instance().run();
56     }
57 }
58
59 prefix_ void senf::Scheduler::restart()
60 {
61     scheduler::FdManager* fdm (&scheduler::FdManager::instance());
62     scheduler::FIFORunner* ffr (&scheduler::FIFORunner::instance());
63     scheduler::detail::FdDispatcher* fdd (&scheduler::detail::FdDispatcher::instance());
64     scheduler::detail::TimerDispatcher* td (&scheduler::detail::TimerDispatcher::instance());
65     scheduler::detail::SignalDispatcher* sd (&scheduler::detail::SignalDispatcher::instance());
66     scheduler::detail::FileDispatcher* fld (&scheduler::detail::FileDispatcher::instance());
67     
68     fld->~FileDispatcher();
69     sd->~SignalDispatcher();
70     td->~TimerDispatcher();
71     fdd->~FdDispatcher();
72     ffr->~FIFORunner();
73     fdm->~FdManager();
74     
75     new (fdm) scheduler::FdManager();
76     new (ffr) scheduler::FIFORunner();
77     new (fdd) scheduler::detail::FdDispatcher();
78     new (td) scheduler::detail::TimerDispatcher();
79     new (sd) scheduler::detail::SignalDispatcher();
80     new (fld) scheduler::detail::FileDispatcher();
81 }
82
83 ///////////////////////////////////////////////////////////////////////////
84 // senf::SchedulerLogTimeSource
85
86 prefix_ senf::log::time_type senf::SchedulerLogTimeSource::operator()()
87     const
88 {
89     return Scheduler::instance().eventTime();
90 }
91
92 ///////////////////////////////cc.e////////////////////////////////////////
93 #undef prefix_
94
95 \f
96 // Local Variables:
97 // mode: c++
98 // fill-column: 100
99 // c-file-style: "senf"
100 // indent-tabs-mode: nil
101 // ispell-local-dictionary: "american"
102 // compile-command: "scons -u test"
103 // comment-column: 40
104 // End: