]> Dogcows Code - chaz/yoink/blob - src/moof/runloop.hh
build system enhancements
[chaz/yoink] / src / moof / runloop.hh
1
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
4 *
5 * vi:ts=4 sw=4 tw=75
6 *
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
9 *
10 **************************************************************************/
11
12 #ifndef _MOOF_RUNLOOP_HH_
13 #define _MOOF_RUNLOOP_HH_
14
15 /**
16 * \file runloop.hh
17 * Thread timer management class.
18 */
19
20 #include <vector>
21
22 #include <boost/noncopyable.hpp>
23
24 #include <moof/thread.hh>
25
26
27 namespace moof {
28
29
30 // forward declarations
31 class timer;
32
33
34 /**
35 * A runloop is a loop with scheduled timers.
36 */
37 class runloop : public boost::noncopyable
38 {
39 public:
40
41 /**
42 * Construct a runloop.
43 */
44 runloop() :
45 stop_(false)
46 {
47 #if ENABLE_THREADS
48 thread_id_ = 0;
49 #endif
50 }
51
52 /**
53 * Do one iteration of the runloop.
54 */
55 void run_once();
56
57
58 /**
59 * Start running the runloop.
60 * \return The exit code.
61 */
62 int run();
63
64 /**
65 * Stop the runloop.
66 * \param code The exit code.
67 */
68 void stop(int code = 0);
69
70
71 void add_timer(timer& timer);
72 void remove_timer(timer& timer);
73
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.035063 seconds and 4 git commands to generate.