]> Dogcows Code - chaz/yoink/blob - src/moof/runloop.hh
remove some unused stlplus modules
[chaz/yoink] / src / moof / runloop.hh
1
2 /*] Copyright (c) 2009-2011, Charles McGarvey [*****************************
3 **] All rights reserved.
4 *
5 * Distributable under the terms and conditions of the 2-clause BSD license;
6 * see the file COPYING for a complete text of the license.
7 *
8 *****************************************************************************/
9
10 #ifndef _MOOF_RUNLOOP_HH_
11 #define _MOOF_RUNLOOP_HH_
12
13 /**
14 * \file runloop.hh
15 * Thread timer management class.
16 */
17
18 #include <vector>
19
20 #include <boost/noncopyable.hpp>
21
22 #include <moof/thread.hh>
23
24
25 namespace moof {
26
27
28 // forward declarations
29 class timer;
30
31 /**
32 * A runloop is a loop with scheduled timers.
33 */
34 class runloop : public boost::noncopyable
35 {
36 public:
37
38 /**
39 * Construct a runloop.
40 */
41 runloop() :
42 stop_(false)
43 {
44 #if ENABLE_THREADS
45 thread_id_ = 0;
46 #endif
47 }
48
49 /**
50 * Do one iteration of the runloop.
51 * \return The number of tasks which were given time.
52 */
53 int run_once();
54
55 /**
56 * Start running the runloop.
57 * \return The exit code.
58 */
59 int run();
60
61 /**
62 * Stop the runloop.
63 * \param code The exit code.
64 */
65 void stop(int code = 0);
66
67 bool is_running() const
68 {
69 return !stop_;
70 }
71
72 void add_timer(timer& timer);
73 void remove_timer(timer& timer);
74
75 private:
76
77 bool stop_;
78 int code_;
79
80 typedef std::vector<timer*> timer_table;
81 timer_table timers_;
82 timer_table::iterator timers_it_;
83
84 #if ENABLE_THREADS
85 MOOF_DECLARE_MUTEX(timers_mutex_);
86 uint32_t thread_id_;
87 #endif
88 };
89
90
91 } // namespace moof
92
93 #endif // _MOOF_RUNLOOP_HH_
94
This page took 0.03249 seconds and 4 git commands to generate.