… | |
… | |
39 | |
39 | |
40 | // this is a dummy time watcher to ensure that the first |
40 | // this is a dummy time watcher to ensure that the first |
41 | // time watcher is _always_ valid, this gets rid of a lot |
41 | // time watcher is _always_ valid, this gets rid of a lot |
42 | // of null-pointer-checks |
42 | // of null-pointer-checks |
43 | // (must come _before_ iom is being defined) |
43 | // (must come _before_ iom is being defined) |
44 | static struct tw0 : time_watcher { |
44 | static struct tw0 : time_watcher |
45 | void cb (time_watcher &w) |
|
|
46 | { |
45 | { |
|
|
46 | void cb (time_watcher &w) |
|
|
47 | { |
47 | // should never get called |
48 | // should never get called |
48 | // reached end-of-time, or tstamp has a bogus definition, |
49 | // reached end-of-time, or tstamp has a bogus definition, |
49 | // or compiler initilization order broken, or somethine else :) |
50 | // or compiler initilization order broken, or somethine else :) |
50 | abort (); |
51 | abort (); |
51 | } |
52 | } |
52 | |
53 | |
53 | tw0() |
54 | tw0() |
54 | : time_watcher (this, &tw0::cb) |
55 | : time_watcher (this, &tw0::cb) |
55 | { } |
56 | { }} |
56 | } tw0; |
57 | tw0; |
57 | |
58 | |
58 | tstamp NOW; |
59 | tstamp NOW; |
59 | static bool iom_valid; |
60 | static bool iom_valid; |
60 | io_manager iom; |
61 | io_manager iom; |
61 | |
62 | |
… | |
… | |
65 | if (!iom_valid) |
66 | if (!iom_valid) |
66 | abort (); |
67 | abort (); |
67 | |
68 | |
68 | if (!w->active) |
69 | if (!w->active) |
69 | { |
70 | { |
|
|
71 | #if IOM_CHECK |
|
|
72 | queue.activity = true; |
|
|
73 | #endif |
70 | queue.push_back (w); |
74 | queue.push_back (w); |
71 | w->active = queue.size (); |
75 | w->active = queue.size (); |
72 | } |
76 | } |
73 | } |
77 | } |
74 | |
78 | |
… | |
… | |
96 | void io_manager::reg (time_watcher *w) { reg (w, tw); } |
100 | void io_manager::reg (time_watcher *w) { reg (w, tw); } |
97 | void io_manager::unreg (time_watcher *w) { unreg (w, tw); } |
101 | void io_manager::unreg (time_watcher *w) { unreg (w, tw); } |
98 | #endif |
102 | #endif |
99 | |
103 | |
100 | #if IOM_IO |
104 | #if IOM_IO |
101 | void io_manager::reg (io_watcher *w) { reg (w, iow); } |
105 | void io_manager::reg (io_watcher *w) { reg (w, iow); } |
102 | void io_manager::unreg (io_watcher *w) { unreg (w, iow); } |
106 | void io_manager::unreg (io_watcher *w) { unreg (w, iow); } |
103 | #endif |
107 | #endif |
104 | |
108 | |
105 | #if IOM_CHECK |
109 | #if IOM_CHECK |
106 | void io_manager::reg (check_watcher *w) { reg (w, cw); } |
110 | void io_manager::reg (check_watcher *w) { reg (w, cw); } |
… | |
… | |
141 | tval.tv_usec = 0; |
145 | tval.tv_usec = 0; |
142 | to = &tval; |
146 | to = &tval; |
143 | } |
147 | } |
144 | else |
148 | else |
145 | #endif |
149 | #endif |
|
|
150 | |
146 | { |
151 | { |
147 | #if IOM_TIME |
152 | #if IOM_TIME |
148 | time_watcher *next; |
153 | time_watcher *next; |
149 | |
154 | |
150 | for (;;) |
155 | for (;;) |
… | |
… | |
173 | unreg (next); |
178 | unreg (next); |
174 | next->call (*next); |
179 | next->call (*next); |
175 | } |
180 | } |
176 | } |
181 | } |
177 | #endif |
182 | #endif |
|
|
183 | |
178 | } |
184 | } |
179 | |
185 | |
180 | #if IOM_CHECK |
186 | #if IOM_CHECK |
|
|
187 | tw.activity = false; |
|
|
188 | |
181 | for (int i = cw.size (); i--; ) |
189 | for (int i = cw.size (); i--; ) |
182 | if (!cw[i]) |
190 | if (!cw[i]) |
183 | cw.erase_unordered (i); |
191 | cw.erase_unordered (i); |
184 | else |
192 | else |
185 | cw[i]->call (*cw[i]); |
193 | cw[i]->call (*cw[i]); |
|
|
194 | |
|
|
195 | if (tw.activity) |
|
|
196 | { |
|
|
197 | tval.tv_sec = 0; |
|
|
198 | tval.tv_usec = 0; |
|
|
199 | to = &tval; |
|
|
200 | } |
186 | #endif |
201 | #endif |
187 | |
202 | |
188 | #if IOM_IO |
203 | #if IOM_IO |
189 | fd_set rfd, wfd, efd; |
204 | fd_set rfd, wfd, efd; |
190 | |
205 | |
… | |
… | |
245 | select (0, 0, 0, 0, &to); |
260 | select (0, 0, 0, 0, &to); |
246 | set_now (); |
261 | set_now (); |
247 | #else |
262 | #else |
248 | break; |
263 | break; |
249 | #endif |
264 | #endif |
|
|
265 | |
250 | } |
266 | } |
251 | } |
267 | } |
252 | |
268 | |
253 | io_manager::io_manager () |
269 | io_manager::io_manager () |
254 | { |
270 | { |