1 | /* |
1 | /* |
2 | iom.C -- generic I/O multiplexor |
2 | iom.C -- generic I/O multiplexer |
3 | Copyright (C) 2003 Marc Lehmann <pcg@goof.com> |
3 | Copyright (C) 2003, 2004 Marc Lehmann <gvpe@schmorp.de> |
4 | |
4 | |
|
|
5 | This file is part of GVPE. |
|
|
6 | |
5 | This program is free software; you can redistribute it and/or modify |
7 | GVPE is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
8 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; either version 2 of the License, or |
9 | the Free Software Foundation; either version 2 of the License, or |
8 | (at your option) any later version. |
10 | (at your option) any later version. |
9 | |
11 | |
10 | This program is distributed in the hope that it will be useful, |
12 | This program is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
14 | |
16 | |
15 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
16 | along with this program; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
17 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
18 | */ |
20 | */ |
19 | |
21 | |
20 | #include "../config.h" |
22 | #include "iom.h" |
21 | |
23 | |
22 | #include <cstdio> |
24 | #include <cstdio> |
23 | #include <cstdlib> |
25 | #include <cstdlib> |
24 | #include <cerrno> |
26 | #include <cerrno> |
25 | |
27 | |
|
|
28 | #include <sys/time.h> |
|
|
29 | |
|
|
30 | #include <assert.h> |
|
|
31 | |
|
|
32 | #if 1 // older unices need these includes for select (2) |
|
|
33 | # include <unistd.h> |
|
|
34 | # include <sys/types.h> |
|
|
35 | # include <time.h> |
|
|
36 | #endif |
|
|
37 | |
|
|
38 | // for IOM_SIG |
|
|
39 | #if IOM_SIG |
|
|
40 | # include <csignal> |
|
|
41 | # include <fcntl.h> |
|
|
42 | #endif |
|
|
43 | |
|
|
44 | // if the BSDs would at least be marginally POSIX-compatible.. *sigh* |
|
|
45 | // until that happens, sys/select.h must come last |
26 | #include <sys/select.h> |
46 | #include <sys/select.h> |
27 | #include <sys/time.h> |
|
|
28 | |
47 | |
29 | #include "iom.h" |
48 | #define TIMEVAL timeval |
|
|
49 | #define TV_FRAC tv_usec |
|
|
50 | #define TV_MULT 1000000L |
30 | |
51 | |
31 | // TSTAMP_MAX must still fit into a positive struct timeval |
52 | #if IOM_IO |
32 | #define TSTAMP_MAX (double)(1UL<<31) |
53 | static io_manager_vec<io_watcher> iow; |
|
|
54 | #endif |
|
|
55 | #if IOM_CHECK |
|
|
56 | static io_manager_vec<check_watcher> cw; |
|
|
57 | #endif |
|
|
58 | #if IOM_TIME |
|
|
59 | static io_manager_vec<time_watcher> tw; |
|
|
60 | #endif |
|
|
61 | #if IOM_IDLE |
|
|
62 | static io_manager_vec<idle_watcher> iw; |
|
|
63 | #endif |
|
|
64 | #if IOM_SIG |
|
|
65 | static int sigpipe[2]; // signal signalling pipe |
|
|
66 | static sigset_t sigs; |
|
|
67 | struct sig_vec : io_manager_vec<sig_watcher> { |
|
|
68 | int pending; |
|
|
69 | sig_vec () |
|
|
70 | : pending (false) |
|
|
71 | { } |
|
|
72 | }; |
|
|
73 | static vector<sig_vec *> sw; |
|
|
74 | #endif |
|
|
75 | |
|
|
76 | // this is a dummy time watcher to ensure that the first |
|
|
77 | // time watcher is _always_ valid, this gets rid of a lot |
|
|
78 | // of null-pointer-checks |
|
|
79 | // (must come _before_ iom is being defined) |
|
|
80 | static struct tw0 : time_watcher |
|
|
81 | { |
|
|
82 | void cb (time_watcher &w) |
|
|
83 | { |
|
|
84 | // should never get called |
|
|
85 | // reached end-of-time, or tstamp has a bogus definition, |
|
|
86 | // or compiler initialisation order broken, or something else :) |
|
|
87 | abort (); |
|
|
88 | } |
|
|
89 | |
|
|
90 | tw0 () |
|
|
91 | : time_watcher (this, &tw0::cb) |
|
|
92 | { } |
|
|
93 | } tw0; |
33 | |
94 | |
34 | tstamp NOW; |
95 | tstamp NOW; |
|
|
96 | |
|
|
97 | #if IOM_TIME |
|
|
98 | tstamp io_manager::now () |
|
|
99 | { |
|
|
100 | struct timeval tv; |
|
|
101 | |
|
|
102 | gettimeofday (&tv, 0); |
|
|
103 | return (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000.; |
|
|
104 | } |
|
|
105 | |
|
|
106 | void io_manager::set_now () |
|
|
107 | { |
|
|
108 | NOW = now (); |
|
|
109 | } |
|
|
110 | #endif |
|
|
111 | |
35 | static bool iom_valid; |
112 | static bool iom_valid; |
36 | io_manager iom; |
113 | |
|
|
114 | // used for initialisation only |
|
|
115 | static struct init { |
|
|
116 | init () |
|
|
117 | { |
|
|
118 | #if IOM_SIG |
|
|
119 | sigemptyset (&sigs); |
|
|
120 | |
|
|
121 | if (pipe (sigpipe)) |
|
|
122 | { |
|
|
123 | perror ("io_manager: unable to create signal pipe, aborting."); |
|
|
124 | abort (); |
|
|
125 | } |
|
|
126 | |
|
|
127 | fcntl (sigpipe[0], F_SETFL, O_NONBLOCK); fcntl (sigpipe[0], F_SETFD, FD_CLOEXEC); |
|
|
128 | fcntl (sigpipe[1], F_SETFL, O_NONBLOCK); fcntl (sigpipe[1], F_SETFD, FD_CLOEXEC); |
|
|
129 | #endif |
|
|
130 | |
|
|
131 | iom_valid = true; |
|
|
132 | |
|
|
133 | #if IOM_TIME |
|
|
134 | io_manager::set_now (); |
|
|
135 | |
|
|
136 | tw0.start (TSTAMP_MAX); |
|
|
137 | #endif |
|
|
138 | } |
|
|
139 | |
|
|
140 | ~init () |
|
|
141 | { |
|
|
142 | iom_valid = false; |
|
|
143 | } |
|
|
144 | |
|
|
145 | static void required (); |
|
|
146 | } init; |
|
|
147 | |
|
|
148 | void |
|
|
149 | init::required () |
|
|
150 | { |
|
|
151 | if (!iom_valid) |
|
|
152 | { |
|
|
153 | write (2, "io_manager: early registration attempt, aborting.\n", |
|
|
154 | sizeof ("io_manager: early registration attempt, aborting.\n") - 1); |
|
|
155 | abort (); |
|
|
156 | } |
|
|
157 | } |
37 | |
158 | |
38 | template<class watcher> |
159 | template<class watcher> |
39 | void io_manager::reg (watcher *w, simplevec<watcher *> &queue) |
160 | void io_manager::reg (watcher &w, io_manager_vec<watcher> &queue) |
40 | { |
161 | { |
41 | if (!iom_valid) |
162 | init::required (); |
42 | abort (); |
|
|
43 | |
163 | |
44 | if (!w->active) |
164 | if (!w.active) |
45 | { |
165 | { |
46 | queue.push_back (w); |
166 | queue.push_back (&w); |
47 | w->active = queue.size (); |
167 | w.active = queue.size (); |
48 | } |
168 | } |
49 | } |
169 | } |
50 | |
170 | |
51 | template<class watcher> |
171 | template<class watcher> |
52 | void io_manager::unreg (watcher *w, simplevec<watcher *> &queue) |
172 | void io_manager::unreg (watcher &w, io_manager_vec<watcher> &queue) |
53 | { |
173 | { |
54 | if (!iom_valid) |
174 | if (!iom_valid) |
55 | return; |
175 | return; |
56 | |
176 | |
57 | if (w->active) |
177 | if (w.active) |
58 | { |
178 | { |
59 | queue [w->active - 1] = 0; |
179 | queue [w.active - 1] = 0; |
60 | w->active = 0; |
180 | w.active = 0; |
61 | } |
181 | } |
62 | } |
182 | } |
63 | |
183 | |
64 | #if IOM_TIME |
184 | #if IOM_TIME |
65 | void time_watcher::trigger () |
185 | void time_watcher::trigger () |
66 | { |
186 | { |
67 | call (*this); |
187 | call (*this); |
68 | |
188 | io_manager::reg (*this); |
69 | iom.reg (this); |
|
|
70 | } |
189 | } |
71 | |
190 | |
72 | void io_manager::reg (time_watcher *w) { reg (w, tw); } |
191 | void io_manager::reg (time_watcher &w) { io_manager::reg (w, tw); } |
73 | void io_manager::unreg (time_watcher *w) { unreg (w, tw); } |
192 | void io_manager::unreg (time_watcher &w) { io_manager::unreg (w, tw); } |
74 | #endif |
193 | #endif |
75 | |
194 | |
76 | #if IOM_IO |
195 | #if IOM_IO |
77 | void io_manager::reg (io_watcher *w) { reg (w, iow); } |
196 | void io_manager::reg (io_watcher &w) { io_manager::reg (w, iow); } |
78 | void io_manager::unreg (io_watcher *w) { unreg (w, iow); } |
197 | void io_manager::unreg (io_watcher &w) { io_manager::unreg (w, iow); } |
79 | #endif |
198 | #endif |
80 | |
199 | |
81 | #if IOM_CHECK |
200 | #if IOM_CHECK |
82 | void io_manager::reg (check_watcher *w) { reg (w, cw); } |
201 | void io_manager::reg (check_watcher &w) { io_manager::reg (w, cw); } |
83 | void io_manager::unreg (check_watcher *w) { unreg (w, cw); } |
202 | void io_manager::unreg (check_watcher &w) { io_manager::unreg (w, cw); } |
84 | #endif |
203 | #endif |
85 | |
204 | |
86 | #if IOM_IDLE |
205 | #if IOM_IDLE |
87 | void io_manager::reg (idle_watcher *w) { reg (w, iw); } |
206 | void io_manager::reg (idle_watcher &w) { io_manager::reg (w, iw); } |
88 | void io_manager::unreg (idle_watcher *w) { unreg (w, iw); } |
207 | void io_manager::unreg (idle_watcher &w) { io_manager::unreg (w, iw); } |
89 | #endif |
208 | #endif |
90 | |
209 | |
91 | #if IOM_TIME |
210 | #if IOM_SIG |
92 | inline void set_now (void) |
211 | static void |
|
|
212 | sighandler (int signum) |
93 | { |
213 | { |
94 | struct timeval tv; |
214 | sw [signum - 1]->pending = true; |
95 | |
215 | |
96 | gettimeofday (&tv, 0); |
216 | // we use a pipe for signal notifications, as most current |
97 | |
217 | // OSes (Linux...) do not implement pselect correctly. ugh. |
98 | NOW = (tstamp)tv.tv_sec + (tstamp)tv.tv_usec / 1000000; |
218 | char ch = signum; // actual content not used |
99 | #endif |
219 | write (sigpipe[1], &ch, 1); |
100 | } |
220 | } |
|
|
221 | |
|
|
222 | void io_manager::reg (sig_watcher &w) |
|
|
223 | { |
|
|
224 | assert (0 < w.signum); |
|
|
225 | |
|
|
226 | sw.reserve (w.signum); |
|
|
227 | |
|
|
228 | while (sw.size () < w.signum) // pathetic |
|
|
229 | sw.push_back (0); |
|
|
230 | |
|
|
231 | sig_vec *&sv = sw[w.signum - 1]; |
|
|
232 | |
|
|
233 | if (!sv) |
|
|
234 | { |
|
|
235 | sv = new sig_vec; |
|
|
236 | |
|
|
237 | sigaddset (&sigs, w.signum); |
|
|
238 | sigprocmask (SIG_BLOCK, &sigs, NULL); |
|
|
239 | |
|
|
240 | struct sigaction sa; |
|
|
241 | sa.sa_handler = sighandler; |
|
|
242 | sigfillset (&sa.sa_mask); |
|
|
243 | sa.sa_flags = SA_RESTART; |
|
|
244 | |
|
|
245 | if (sigaction (w.signum, &sa, 0)) |
|
|
246 | { |
|
|
247 | perror ("io_manager: error while installing signal handler, ignoring."); |
|
|
248 | abort (); |
|
|
249 | } |
|
|
250 | |
|
|
251 | } |
|
|
252 | |
|
|
253 | io_manager::reg (w, *sv); |
|
|
254 | } |
|
|
255 | |
|
|
256 | void io_manager::unreg (sig_watcher &w) |
|
|
257 | { |
|
|
258 | if (!w.active) |
|
|
259 | return; |
|
|
260 | |
|
|
261 | assert (0 < w.signum && w.signum <= sw.size ()); |
|
|
262 | |
|
|
263 | io_manager::unreg (w, *sw[w.signum - 1]); |
|
|
264 | } |
|
|
265 | |
|
|
266 | void sig_watcher::start (int signum) |
|
|
267 | { |
|
|
268 | stop (); |
|
|
269 | this->signum = signum; |
|
|
270 | io_manager::reg (*this); |
|
|
271 | } |
|
|
272 | #endif |
101 | |
273 | |
102 | void io_manager::loop () |
274 | void io_manager::loop () |
103 | { |
275 | { |
|
|
276 | init::required (); |
|
|
277 | |
104 | #if IOM_TIME |
278 | #if IOM_TIME |
105 | set_now (); |
279 | set_now (); |
106 | #endif |
280 | #endif |
107 | |
281 | |
108 | for (;;) |
282 | for (;;) |
109 | { |
283 | { |
110 | struct timeval *to = 0; |
|
|
111 | struct timeval tval; |
|
|
112 | |
284 | |
113 | #if IOM_IDLE |
285 | #if IOM_TIME |
114 | if (iw.size ()) |
286 | // call pending time watchers |
115 | { |
287 | { |
116 | tval.tv_sec = 0; |
288 | bool activity; |
117 | tval.tv_usec = 0; |
289 | |
118 | to = &tval; |
|
|
119 | } |
290 | do |
120 | else |
|
|
121 | #endif |
|
|
122 | { |
|
|
123 | #if IOM_TIME |
|
|
124 | time_watcher *next; |
|
|
125 | |
|
|
126 | for (;;) |
|
|
127 | { |
291 | { |
128 | next = tw[0]; // the first time-watcher must exist at ALL times |
292 | activity = false; |
129 | |
293 | |
130 | for (int i = tw.size (); i--; ) |
294 | for (int i = tw.size (); i--; ) |
131 | if (!tw[i]) |
295 | if (!tw[i]) |
132 | tw.erase_unordered (i); |
296 | tw.erase_unordered (i); |
133 | else if (tw[i]->at < next->at) |
297 | else if (tw[i]->at <= NOW) |
134 | next = tw[i]; |
|
|
135 | |
|
|
136 | if (next->at > NOW) |
|
|
137 | { |
298 | { |
138 | if (next != tw[0]) |
299 | time_watcher &w = *tw[i]; |
139 | { |
300 | |
140 | double diff = next->at - NOW; |
|
|
141 | tval.tv_sec = (int)diff; |
|
|
142 | tval.tv_usec = (int)((diff - tval.tv_sec) * 1000000); |
|
|
143 | to = &tval; |
|
|
144 | } |
|
|
145 | break; |
301 | unreg (w); |
|
|
302 | w.call (w); |
|
|
303 | |
|
|
304 | activity = true; |
146 | } |
305 | } |
147 | else if (next->at >= 0) |
|
|
148 | { |
|
|
149 | unreg (next); |
|
|
150 | next->call (*next); |
|
|
151 | } |
|
|
152 | } |
306 | } |
153 | #endif |
307 | while (activity); |
154 | } |
308 | } |
|
|
309 | #endif |
155 | |
310 | |
156 | #if IOM_CHECK |
311 | #if IOM_CHECK |
|
|
312 | // call all check watchers |
157 | for (int i = cw.size (); i--; ) |
313 | for (int i = cw.size (); i--; ) |
158 | if (!cw[i]) |
314 | if (!cw[i]) |
159 | cw.erase_unordered (i); |
315 | cw.erase_unordered (i); |
160 | else |
316 | else |
161 | cw[i]->call (*cw[i]); |
317 | cw[i]->call (*cw[i]); |
162 | #endif |
318 | #endif |
163 | |
319 | |
|
|
320 | struct TIMEVAL *to = 0; |
|
|
321 | struct TIMEVAL tval; |
|
|
322 | |
164 | #if IOM_IO |
323 | #if IOM_IDLE |
|
|
324 | if (iw.size ()) |
|
|
325 | { |
|
|
326 | tval.tv_sec = 0; |
|
|
327 | tval.TV_FRAC = 0; |
|
|
328 | to = &tval; |
|
|
329 | } |
|
|
330 | else |
|
|
331 | #endif |
|
|
332 | { |
|
|
333 | #if IOM_TIME |
|
|
334 | // find earliest active watcher |
|
|
335 | time_watcher *next = tw[0]; // the first time-watcher must exist at ALL times |
|
|
336 | |
|
|
337 | for (io_manager_vec<time_watcher>::const_iterator i = tw.end (); i-- > tw.begin (); ) |
|
|
338 | if (*i && (*i)->at < next->at) |
|
|
339 | next = *i; |
|
|
340 | |
|
|
341 | if (next->at > NOW && next != tw[0]) |
|
|
342 | { |
|
|
343 | double diff = next->at - NOW; |
|
|
344 | tval.tv_sec = (int)diff; |
|
|
345 | tval.TV_FRAC = (int) ((diff - tval.tv_sec) * TV_MULT); |
|
|
346 | to = &tval; |
|
|
347 | } |
|
|
348 | } |
|
|
349 | #endif |
|
|
350 | |
|
|
351 | #if IOM_IO || IOM_SIG |
165 | fd_set rfd, wfd, efd; |
352 | fd_set rfd, wfd; |
166 | |
353 | |
167 | FD_ZERO (&rfd); |
354 | FD_ZERO (&rfd); |
168 | FD_ZERO (&wfd); |
355 | FD_ZERO (&wfd); |
169 | |
356 | |
170 | int fds = 0; |
357 | int fds = 0; |
171 | |
358 | |
|
|
359 | # if IOM_IO |
172 | for (io_watcher **i = iow.end (); i-- > iow.begin (); ) |
360 | for (io_manager_vec<io_watcher>::const_iterator i = iow.end (); i-- > iow.begin (); ) |
173 | if (*i) |
361 | if (*i) |
174 | { |
362 | { |
175 | if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); |
363 | if ((*i)->events & EVENT_READ ) FD_SET ((*i)->fd, &rfd); |
176 | if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); |
364 | if ((*i)->events & EVENT_WRITE) FD_SET ((*i)->fd, &wfd); |
177 | |
365 | |
178 | if ((*i)->fd >= fds) fds = (*i)->fd + 1; |
366 | if ((*i)->fd >= fds) fds = (*i)->fd + 1; |
179 | } |
367 | } |
|
|
368 | # endif |
180 | |
369 | |
181 | if (!to && !fds) //TODO: also check idle_watchers and check_watchers |
370 | if (!to && !fds) //TODO: also check idle_watchers and check_watchers? |
182 | break; // no events |
371 | break; // no events |
183 | |
372 | |
|
|
373 | # if IOM_SIG |
|
|
374 | FD_SET (sigpipe[0], &rfd); |
|
|
375 | if (sigpipe[0] >= fds) fds = sigpipe[0] + 1; |
|
|
376 | # endif |
|
|
377 | |
|
|
378 | # if IOM_SIG |
|
|
379 | // there is no race, as we use a pipe for signals, so select |
|
|
380 | // will return if a signal is caught. |
|
|
381 | sigprocmask (SIG_UNBLOCK, &sigs, NULL); |
|
|
382 | # endif |
184 | fds = select (fds, &rfd, &wfd, &efd, to); |
383 | fds = select (fds, &rfd, &wfd, NULL, to); |
|
|
384 | # if IOM_SIG |
|
|
385 | sigprocmask (SIG_BLOCK, &sigs, NULL); |
|
|
386 | # endif |
|
|
387 | |
185 | # if IOM_TIME |
388 | # if IOM_TIME |
|
|
389 | { |
|
|
390 | // update time, try to compensate for gross non-monotonic time changes |
|
|
391 | tstamp diff = NOW; |
186 | set_now (); |
392 | set_now (); |
|
|
393 | diff = NOW - diff; |
|
|
394 | |
|
|
395 | if (diff < 0) |
|
|
396 | for (io_manager_vec<time_watcher>::const_iterator i = tw.end (); i-- > tw.begin (); ) |
|
|
397 | if (*i) |
|
|
398 | (*i)->at += diff; |
|
|
399 | } |
187 | # endif |
400 | # endif |
188 | |
401 | |
189 | if (fds > 0) |
402 | if (fds > 0) |
190 | for (int i = iow.size (); i--; ) |
403 | { |
191 | if (!iow[i]) |
404 | # if IOM_SIG |
192 | iow.erase_unordered (i); |
405 | if (FD_ISSET (sigpipe[0], &rfd)) |
193 | else |
|
|
194 | { |
406 | { |
195 | short revents = iow[i]->events; |
407 | char ch; |
196 | |
408 | |
197 | if (!FD_ISSET (iow[i]->fd, &rfd)) revents &= ~EVENT_READ; |
409 | while (read (sigpipe[0], &ch, 1) > 0) |
198 | if (!FD_ISSET (iow[i]->fd, &wfd)) revents &= ~EVENT_WRITE; |
410 | ; |
199 | |
411 | |
200 | if (revents) |
412 | for (vector<sig_vec *>::iterator svp = sw.end (); svp-- > sw.begin (); ) |
201 | iow[i]->call (*iow[i], revents); |
413 | if (*svp && (*svp)->pending) |
|
|
414 | { |
|
|
415 | sig_vec &sv = **svp; |
|
|
416 | for (int i = sv.size (); i--; ) |
|
|
417 | if (!sv[i]) |
|
|
418 | sv.erase_unordered (i); |
|
|
419 | else |
|
|
420 | sv[i]->call (*sv[i]); |
|
|
421 | |
|
|
422 | sv.pending = false; |
|
|
423 | } |
202 | } |
424 | } |
|
|
425 | # endif |
|
|
426 | |
|
|
427 | # if IOM_IO |
|
|
428 | for (int i = iow.size (); i--; ) |
|
|
429 | if (!iow[i]) |
|
|
430 | iow.erase_unordered (i); |
|
|
431 | else |
|
|
432 | { |
|
|
433 | io_watcher &w = *iow[i]; |
|
|
434 | short revents = w.events; |
|
|
435 | |
|
|
436 | if (!FD_ISSET (w.fd, &rfd)) revents &= ~EVENT_READ; |
|
|
437 | if (!FD_ISSET (w.fd, &wfd)) revents &= ~EVENT_WRITE; |
|
|
438 | |
|
|
439 | if (revents) |
|
|
440 | w.call (w, revents); |
|
|
441 | } |
|
|
442 | #endif |
|
|
443 | } |
203 | else if (fds < 0 && errno != EINTR) |
444 | else if (fds < 0 && errno != EINTR) |
204 | { |
445 | { |
205 | perror ("Error while waiting for I/O or time event"); |
446 | perror ("io_manager: fatal error while waiting for I/O or time event, aborting."); |
206 | abort (); |
447 | abort (); |
207 | } |
448 | } |
208 | #if IOM_IDLE |
449 | #if IOM_IDLE |
209 | else |
450 | else |
210 | for (int i = iw.size (); i--; ) |
451 | for (int i = iw.size (); i--; ) |
… | |
… | |
224 | break; |
465 | break; |
225 | #endif |
466 | #endif |
226 | } |
467 | } |
227 | } |
468 | } |
228 | |
469 | |
229 | // this is a dummy time watcher to ensure that the first |
|
|
230 | // time watcher is _always_ valid, this gets rid of a lot |
|
|
231 | // of null-pointer-checks |
|
|
232 | static struct tw0 : time_watcher { |
|
|
233 | void cb (time_watcher &w) |
|
|
234 | { |
|
|
235 | // should never get called |
|
|
236 | // reached end-of-time, or tstamp has a bogus definition :) |
|
|
237 | abort (); |
|
|
238 | } |
|
|
239 | |
|
|
240 | tw0() |
|
|
241 | : time_watcher (this, &tw0::cb) |
|
|
242 | { } |
|
|
243 | } tw0; |
|
|
244 | |
|
|
245 | io_manager::io_manager () |
|
|
246 | { |
|
|
247 | iom_valid = true; |
|
|
248 | |
|
|
249 | #if IOM_TIME |
|
|
250 | set_now (); |
|
|
251 | |
|
|
252 | tw0.start (TSTAMP_MAX); |
|
|
253 | #endif |
|
|
254 | } |
|
|
255 | |
|
|
256 | io_manager::~io_manager () |
|
|
257 | { |
|
|
258 | iom_valid = false; |
|
|
259 | } |
|
|
260 | |
|
|