|
|
1 | /* |
|
|
2 | * Copyright (c) 2007 Marc Alexander Lehmann <libev@schmorp.de> |
|
|
3 | * All rights reserved. |
|
|
4 | * |
|
|
5 | * Redistribution and use in source and binary forms, with or without |
|
|
6 | * modification, are permitted provided that the following conditions are |
|
|
7 | * met: |
|
|
8 | * |
|
|
9 | * * Redistributions of source code must retain the above copyright |
|
|
10 | * notice, this list of conditions and the following disclaimer. |
|
|
11 | * |
|
|
12 | * * Redistributions in binary form must reproduce the above |
|
|
13 | * copyright notice, this list of conditions and the following |
|
|
14 | * disclaimer in the documentation and/or other materials provided |
|
|
15 | * with the distribution. |
|
|
16 | * |
|
|
17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
|
18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
|
19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
|
20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
|
21 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
|
22 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
|
23 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
|
27 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
28 | */ |
|
|
29 | |
1 | #include <math.h> |
30 | #include <math.h> |
2 | #include <stdlib.h> |
31 | #include <stdlib.h> |
|
|
32 | #include <unistd.h> |
|
|
33 | #include <fcntl.h> |
|
|
34 | #include <signal.h> |
|
|
35 | #include <stddef.h> |
3 | |
36 | |
4 | #include <stdio.h> |
37 | #include <stdio.h> |
5 | |
38 | |
6 | #include <assert.h> |
39 | #include <assert.h> |
7 | #include <errno.h> |
40 | #include <errno.h> |
8 | #include <sys/time.h> |
41 | #include <sys/time.h> |
9 | #include <time.h> |
42 | #include <time.h> |
10 | |
43 | |
11 | #ifdef CLOCK_MONOTONIC |
|
|
12 | # define HAVE_MONOTONIC 1 |
|
|
13 | #endif |
|
|
14 | |
|
|
15 | #define HAVE_EPOLL 1 |
44 | #define HAVE_EPOLL 1 |
16 | #define HAVE_REALTIME 1 |
45 | |
|
|
46 | #ifndef HAVE_MONOTONIC |
|
|
47 | # ifdef CLOCK_MONOTONIC |
|
|
48 | # define HAVE_MONOTONIC 1 |
|
|
49 | # endif |
|
|
50 | #endif |
|
|
51 | |
|
|
52 | #ifndef HAVE_SELECT |
17 | #define HAVE_SELECT 0 |
53 | # define HAVE_SELECT 1 |
|
|
54 | #endif |
|
|
55 | |
|
|
56 | #ifndef HAVE_EPOLL |
|
|
57 | # define HAVE_EPOLL 0 |
|
|
58 | #endif |
|
|
59 | |
|
|
60 | #ifndef HAVE_REALTIME |
|
|
61 | # define HAVE_REALTIME 1 /* posix requirement, but might be slower */ |
|
|
62 | #endif |
18 | |
63 | |
19 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
64 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
20 | #define MAX_BLOCKTIME 60. |
65 | #define MAX_BLOCKTIME 60. |
21 | |
66 | |
22 | #include "ev.h" |
67 | #include "ev.h" |
23 | |
68 | |
24 | struct ev_watcher { |
69 | typedef struct ev_watcher *W; |
25 | EV_WATCHER (ev_watcher); |
|
|
26 | }; |
|
|
27 | |
|
|
28 | struct ev_watcher_list { |
70 | typedef struct ev_watcher_list *WL; |
29 | EV_WATCHER_LIST (ev_watcher_list); |
71 | typedef struct ev_watcher_time *WT; |
30 | }; |
|
|
31 | |
72 | |
32 | static ev_tstamp now, diff; /* monotonic clock */ |
73 | static ev_tstamp now, diff; /* monotonic clock */ |
33 | ev_tstamp ev_now; |
74 | ev_tstamp ev_now; |
34 | int ev_method; |
75 | int ev_method; |
35 | |
76 | |
36 | static int have_monotonic; /* runtime */ |
77 | static int have_monotonic; /* runtime */ |
37 | |
78 | |
38 | static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ |
79 | static ev_tstamp method_fudge; /* stupid epoll-returns-early bug */ |
39 | static void (*method_reify)(void); |
80 | static void (*method_modify)(int fd, int oev, int nev); |
40 | static void (*method_poll)(ev_tstamp timeout); |
81 | static void (*method_poll)(ev_tstamp timeout); |
|
|
82 | |
|
|
83 | /*****************************************************************************/ |
41 | |
84 | |
42 | ev_tstamp |
85 | ev_tstamp |
43 | ev_time (void) |
86 | ev_time (void) |
44 | { |
87 | { |
45 | #if HAVE_REALTIME |
88 | #if HAVE_REALTIME |
… | |
… | |
70 | |
113 | |
71 | #define array_needsize(base,cur,cnt,init) \ |
114 | #define array_needsize(base,cur,cnt,init) \ |
72 | if ((cnt) > cur) \ |
115 | if ((cnt) > cur) \ |
73 | { \ |
116 | { \ |
74 | int newcnt = cur ? cur << 1 : 16; \ |
117 | int newcnt = cur ? cur << 1 : 16; \ |
75 | fprintf (stderr, "resize(" # base ") from %d to %d\n", cur, newcnt);\ |
|
|
76 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
118 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
77 | init (base + cur, newcnt - cur); \ |
119 | init (base + cur, newcnt - cur); \ |
78 | cur = newcnt; \ |
120 | cur = newcnt; \ |
79 | } |
121 | } |
80 | |
122 | |
|
|
123 | /*****************************************************************************/ |
|
|
124 | |
81 | typedef struct |
125 | typedef struct |
82 | { |
126 | { |
83 | struct ev_io *head; |
127 | struct ev_io *head; |
84 | unsigned char wev, rev; /* want, received event set */ |
128 | unsigned char wev, rev; /* want, received event set */ |
85 | } ANFD; |
129 | } ANFD; |
… | |
… | |
101 | } |
145 | } |
102 | } |
146 | } |
103 | |
147 | |
104 | typedef struct |
148 | typedef struct |
105 | { |
149 | { |
106 | struct ev_watcher *w; |
150 | W w; |
107 | int events; |
151 | int events; |
108 | } ANPENDING; |
152 | } ANPENDING; |
109 | |
153 | |
110 | static ANPENDING *pendings; |
154 | static ANPENDING *pendings; |
111 | static int pendingmax, pendingcnt; |
155 | static int pendingmax, pendingcnt; |
112 | |
156 | |
113 | static void |
157 | static void |
114 | event (struct ev_watcher *w, int events) |
158 | event (W w, int events) |
115 | { |
159 | { |
|
|
160 | if (w->active) |
|
|
161 | { |
116 | w->pending = ++pendingcnt; |
162 | w->pending = ++pendingcnt; |
117 | array_needsize (pendings, pendingmax, pendingcnt, ); |
163 | array_needsize (pendings, pendingmax, pendingcnt, ); |
118 | pendings [pendingcnt - 1].w = w; |
164 | pendings [pendingcnt - 1].w = w; |
119 | pendings [pendingcnt - 1].events = events; |
165 | pendings [pendingcnt - 1].events = events; |
|
|
166 | } |
120 | } |
167 | } |
121 | |
168 | |
122 | static void |
169 | static void |
123 | fd_event (int fd, int events) |
170 | fd_event (int fd, int events) |
124 | { |
171 | { |
… | |
… | |
128 | for (w = anfd->head; w; w = w->next) |
175 | for (w = anfd->head; w; w = w->next) |
129 | { |
176 | { |
130 | int ev = w->events & events; |
177 | int ev = w->events & events; |
131 | |
178 | |
132 | if (ev) |
179 | if (ev) |
133 | event ((struct ev_watcher *)w, ev); |
180 | event ((W)w, ev); |
134 | } |
181 | } |
135 | } |
182 | } |
136 | |
183 | |
|
|
184 | static void |
|
|
185 | queue_events (W *events, int eventcnt, int type) |
|
|
186 | { |
|
|
187 | int i; |
|
|
188 | |
|
|
189 | for (i = 0; i < eventcnt; ++i) |
|
|
190 | event (events [i], type); |
|
|
191 | } |
|
|
192 | |
|
|
193 | /*****************************************************************************/ |
|
|
194 | |
137 | static struct ev_timer **atimers; |
195 | static struct ev_timer **timers; |
138 | static int atimermax, atimercnt; |
196 | static int timermax, timercnt; |
139 | |
197 | |
140 | static struct ev_timer **rtimers; |
198 | static struct ev_periodic **periodics; |
141 | static int rtimermax, rtimercnt; |
199 | static int periodicmax, periodiccnt; |
142 | |
200 | |
143 | static void |
201 | static void |
144 | upheap (struct ev_timer **timers, int k) |
202 | upheap (WT *timers, int k) |
145 | { |
203 | { |
146 | struct ev_timer *w = timers [k]; |
204 | WT w = timers [k]; |
147 | |
205 | |
148 | while (k && timers [k >> 1]->at > w->at) |
206 | while (k && timers [k >> 1]->at > w->at) |
149 | { |
207 | { |
150 | timers [k] = timers [k >> 1]; |
208 | timers [k] = timers [k >> 1]; |
151 | timers [k]->active = k + 1; |
209 | timers [k]->active = k + 1; |
… | |
… | |
156 | timers [k]->active = k + 1; |
214 | timers [k]->active = k + 1; |
157 | |
215 | |
158 | } |
216 | } |
159 | |
217 | |
160 | static void |
218 | static void |
161 | downheap (struct ev_timer **timers, int N, int k) |
219 | downheap (WT *timers, int N, int k) |
162 | { |
220 | { |
163 | struct ev_timer *w = timers [k]; |
221 | WT w = timers [k]; |
164 | |
222 | |
165 | while (k < (N >> 1)) |
223 | while (k < (N >> 1)) |
166 | { |
224 | { |
167 | int j = k << 1; |
225 | int j = k << 1; |
168 | |
226 | |
… | |
… | |
179 | |
237 | |
180 | timers [k] = w; |
238 | timers [k] = w; |
181 | timers [k]->active = k + 1; |
239 | timers [k]->active = k + 1; |
182 | } |
240 | } |
183 | |
241 | |
184 | static struct ev_signal **signals; |
242 | /*****************************************************************************/ |
|
|
243 | |
|
|
244 | typedef struct |
|
|
245 | { |
|
|
246 | struct ev_signal *head; |
|
|
247 | sig_atomic_t gotsig; |
|
|
248 | } ANSIG; |
|
|
249 | |
|
|
250 | static ANSIG *signals; |
185 | static int signalmax; |
251 | static int signalmax; |
186 | |
252 | |
|
|
253 | static int sigpipe [2]; |
|
|
254 | static sig_atomic_t gotsig; |
|
|
255 | static struct ev_io sigev; |
|
|
256 | |
187 | static void |
257 | static void |
188 | signals_init (struct ev_signal **base, int count) |
258 | signals_init (ANSIG *base, int count) |
189 | { |
259 | { |
190 | while (count--) |
260 | while (count--) |
191 | *base++ = 0; |
261 | { |
|
|
262 | base->head = 0; |
|
|
263 | base->gotsig = 0; |
|
|
264 | ++base; |
|
|
265 | } |
192 | } |
266 | } |
|
|
267 | |
|
|
268 | static void |
|
|
269 | sighandler (int signum) |
|
|
270 | { |
|
|
271 | signals [signum - 1].gotsig = 1; |
|
|
272 | |
|
|
273 | if (!gotsig) |
|
|
274 | { |
|
|
275 | gotsig = 1; |
|
|
276 | write (sigpipe [1], &gotsig, 1); |
|
|
277 | } |
|
|
278 | } |
|
|
279 | |
|
|
280 | static void |
|
|
281 | sigcb (struct ev_io *iow, int revents) |
|
|
282 | { |
|
|
283 | struct ev_signal *w; |
|
|
284 | int sig; |
|
|
285 | |
|
|
286 | gotsig = 0; |
|
|
287 | read (sigpipe [0], &revents, 1); |
|
|
288 | |
|
|
289 | for (sig = signalmax; sig--; ) |
|
|
290 | if (signals [sig].gotsig) |
|
|
291 | { |
|
|
292 | signals [sig].gotsig = 0; |
|
|
293 | |
|
|
294 | for (w = signals [sig].head; w; w = w->next) |
|
|
295 | event ((W)w, EV_SIGNAL); |
|
|
296 | } |
|
|
297 | } |
|
|
298 | |
|
|
299 | static void |
|
|
300 | siginit (void) |
|
|
301 | { |
|
|
302 | fcntl (sigpipe [0], F_SETFD, FD_CLOEXEC); |
|
|
303 | fcntl (sigpipe [1], F_SETFD, FD_CLOEXEC); |
|
|
304 | |
|
|
305 | /* rather than sort out wether we really need nb, set it */ |
|
|
306 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
|
|
307 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
|
|
308 | |
|
|
309 | evio_set (&sigev, sigpipe [0], EV_READ); |
|
|
310 | evio_start (&sigev); |
|
|
311 | } |
|
|
312 | |
|
|
313 | /*****************************************************************************/ |
|
|
314 | |
|
|
315 | static struct ev_idle **idles; |
|
|
316 | static int idlemax, idlecnt; |
|
|
317 | |
|
|
318 | static struct ev_check **checks; |
|
|
319 | static int checkmax, checkcnt; |
|
|
320 | |
|
|
321 | /*****************************************************************************/ |
193 | |
322 | |
194 | #if HAVE_EPOLL |
323 | #if HAVE_EPOLL |
195 | # include "ev_epoll.c" |
324 | # include "ev_epoll.c" |
196 | #endif |
325 | #endif |
197 | #if HAVE_SELECT |
326 | #if HAVE_SELECT |
… | |
… | |
210 | |
339 | |
211 | ev_now = ev_time (); |
340 | ev_now = ev_time (); |
212 | now = get_clock (); |
341 | now = get_clock (); |
213 | diff = ev_now - now; |
342 | diff = ev_now - now; |
214 | |
343 | |
|
|
344 | if (pipe (sigpipe)) |
|
|
345 | return 0; |
|
|
346 | |
|
|
347 | ev_method = EVMETHOD_NONE; |
215 | #if HAVE_EPOLL |
348 | #if HAVE_EPOLL |
216 | if (epoll_init (flags)) |
349 | if (ev_method == EVMETHOD_NONE) epoll_init (flags); |
217 | return ev_method; |
|
|
218 | #endif |
350 | #endif |
219 | #if HAVE_SELECT |
351 | #if HAVE_SELECT |
220 | if (select_init (flags)) |
352 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
221 | return ev_method; |
|
|
222 | #endif |
353 | #endif |
223 | |
354 | |
224 | ev_method = EVMETHOD_NONE; |
355 | if (ev_method) |
|
|
356 | { |
|
|
357 | evw_init (&sigev, sigcb); |
|
|
358 | siginit (); |
|
|
359 | } |
|
|
360 | |
225 | return ev_method; |
361 | return ev_method; |
226 | } |
362 | } |
227 | |
363 | |
|
|
364 | /*****************************************************************************/ |
|
|
365 | |
228 | void ev_prefork (void) |
366 | void ev_prefork (void) |
229 | { |
367 | { |
|
|
368 | /* nop */ |
230 | } |
369 | } |
231 | |
370 | |
232 | void ev_postfork_parent (void) |
371 | void ev_postfork_parent (void) |
233 | { |
372 | { |
|
|
373 | /* nop */ |
234 | } |
374 | } |
235 | |
375 | |
236 | void ev_postfork_child (void) |
376 | void ev_postfork_child (void) |
237 | { |
377 | { |
238 | #if HAVE_EPOLL |
378 | #if HAVE_EPOLL |
|
|
379 | if (ev_method == EVMETHOD_EPOLL) |
239 | epoll_postfork_child (); |
380 | epoll_postfork_child (); |
240 | #endif |
381 | #endif |
|
|
382 | |
|
|
383 | evio_stop (&sigev); |
|
|
384 | close (sigpipe [0]); |
|
|
385 | close (sigpipe [1]); |
|
|
386 | pipe (sigpipe); |
|
|
387 | siginit (); |
|
|
388 | } |
|
|
389 | |
|
|
390 | /*****************************************************************************/ |
|
|
391 | |
|
|
392 | static void |
|
|
393 | fd_reify (void) |
|
|
394 | { |
|
|
395 | int i; |
|
|
396 | |
|
|
397 | for (i = 0; i < fdchangecnt; ++i) |
|
|
398 | { |
|
|
399 | int fd = fdchanges [i]; |
|
|
400 | ANFD *anfd = anfds + fd; |
|
|
401 | struct ev_io *w; |
|
|
402 | |
|
|
403 | int wev = 0; |
|
|
404 | |
|
|
405 | for (w = anfd->head; w; w = w->next) |
|
|
406 | wev |= w->events; |
|
|
407 | |
|
|
408 | if (anfd->wev != wev) |
|
|
409 | { |
|
|
410 | method_modify (fd, anfd->wev, wev); |
|
|
411 | anfd->wev = wev; |
|
|
412 | } |
|
|
413 | } |
|
|
414 | |
|
|
415 | fdchangecnt = 0; |
241 | } |
416 | } |
242 | |
417 | |
243 | static void |
418 | static void |
244 | call_pending () |
419 | call_pending () |
245 | { |
420 | { |
… | |
… | |
258 | |
433 | |
259 | pendingcnt = 0; |
434 | pendingcnt = 0; |
260 | } |
435 | } |
261 | |
436 | |
262 | static void |
437 | static void |
263 | timers_reify (struct ev_timer **timers, int timercnt, ev_tstamp now) |
438 | timers_reify () |
264 | { |
439 | { |
265 | while (timercnt && timers [0]->at <= now) |
440 | while (timercnt && timers [0]->at <= now) |
266 | { |
441 | { |
267 | struct ev_timer *w = timers [0]; |
442 | struct ev_timer *w = timers [0]; |
|
|
443 | |
|
|
444 | event ((W)w, EV_TIMEOUT); |
268 | |
445 | |
269 | /* first reschedule or stop timer */ |
446 | /* first reschedule or stop timer */ |
270 | if (w->repeat) |
447 | if (w->repeat) |
271 | { |
448 | { |
272 | if (w->is_abs) |
|
|
273 | w->at += floor ((now - w->at) / w->repeat + 1.) * w->repeat; |
|
|
274 | else |
|
|
275 | w->at = now + w->repeat; |
449 | w->at = now + w->repeat; |
276 | |
450 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
277 | assert (w->at > now); |
|
|
278 | |
|
|
279 | downheap (timers, timercnt, 0); |
451 | downheap ((WT *)timers, timercnt, 0); |
280 | } |
452 | } |
281 | else |
453 | else |
282 | { |
|
|
283 | evtimer_stop (w); /* nonrepeating: stop timer */ |
454 | evtimer_stop (w); /* nonrepeating: stop timer */ |
284 | --timercnt; /* maybe pass by reference instead? */ |
455 | } |
|
|
456 | } |
|
|
457 | |
|
|
458 | static void |
|
|
459 | periodics_reify () |
|
|
460 | { |
|
|
461 | while (periodiccnt && periodics [0]->at <= ev_now) |
|
|
462 | { |
|
|
463 | struct ev_periodic *w = periodics [0]; |
|
|
464 | |
|
|
465 | /* first reschedule or stop timer */ |
|
|
466 | if (w->interval) |
285 | } |
467 | { |
|
|
468 | w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; |
|
|
469 | assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); |
|
|
470 | downheap ((WT *)periodics, periodiccnt, 0); |
|
|
471 | } |
|
|
472 | else |
|
|
473 | evperiodic_stop (w); /* nonrepeating: stop timer */ |
286 | |
474 | |
287 | event ((struct ev_watcher *)w, EV_TIMEOUT); |
475 | event ((W)w, EV_TIMEOUT); |
|
|
476 | } |
|
|
477 | } |
|
|
478 | |
|
|
479 | static void |
|
|
480 | periodics_reschedule (ev_tstamp diff) |
|
|
481 | { |
|
|
482 | int i; |
|
|
483 | |
|
|
484 | /* adjust periodics after time jump */ |
|
|
485 | for (i = 0; i < periodiccnt; ++i) |
|
|
486 | { |
|
|
487 | struct ev_periodic *w = periodics [i]; |
|
|
488 | |
|
|
489 | if (w->interval) |
|
|
490 | { |
|
|
491 | ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; |
|
|
492 | |
|
|
493 | if (fabs (diff) >= 1e-4) |
|
|
494 | { |
|
|
495 | evperiodic_stop (w); |
|
|
496 | evperiodic_start (w); |
|
|
497 | |
|
|
498 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
|
|
499 | } |
|
|
500 | } |
288 | } |
501 | } |
289 | } |
502 | } |
290 | |
503 | |
291 | static void |
504 | static void |
292 | time_update () |
505 | time_update () |
293 | { |
506 | { |
294 | int i; |
507 | int i; |
|
|
508 | |
295 | ev_now = ev_time (); |
509 | ev_now = ev_time (); |
296 | |
510 | |
297 | if (have_monotonic) |
511 | if (have_monotonic) |
298 | { |
512 | { |
299 | ev_tstamp odiff = diff; |
513 | ev_tstamp odiff = diff; |
300 | |
514 | |
301 | /* detecting time jumps is much more difficult */ |
|
|
302 | for (i = 2; --i; ) /* loop a few times, before making important decisions */ |
515 | for (i = 4; --i; ) /* loop a few times, before making important decisions */ |
303 | { |
516 | { |
304 | now = get_clock (); |
517 | now = get_clock (); |
305 | diff = ev_now - now; |
518 | diff = ev_now - now; |
306 | |
519 | |
307 | if (fabs (odiff - diff) < MIN_TIMEJUMP) |
520 | if (fabs (odiff - diff) < MIN_TIMEJUMP) |
308 | return; /* all is well */ |
521 | return; /* all is well */ |
309 | |
522 | |
310 | ev_now = ev_time (); |
523 | ev_now = ev_time (); |
311 | } |
524 | } |
312 | |
525 | |
313 | /* time jump detected, reschedule atimers */ |
526 | periodics_reschedule (diff - odiff); |
314 | for (i = 0; i < atimercnt; ++i) |
527 | /* no timer adjustment, as the monotonic clock doesn't jump */ |
315 | { |
|
|
316 | struct ev_timer *w = atimers [i]; |
|
|
317 | w->at += ceil ((ev_now - w->at) / w->repeat + 1.) * w->repeat; |
|
|
318 | } |
|
|
319 | } |
528 | } |
320 | else |
529 | else |
321 | { |
530 | { |
322 | if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) |
531 | if (now > ev_now || now < ev_now - MAX_BLOCKTIME - MIN_TIMEJUMP) |
323 | /* time jump detected, adjust rtimers */ |
532 | { |
|
|
533 | periodics_reschedule (ev_now - now); |
|
|
534 | |
|
|
535 | /* adjust timers. this is easy, as the offset is the same for all */ |
324 | for (i = 0; i < rtimercnt; ++i) |
536 | for (i = 0; i < timercnt; ++i) |
325 | rtimers [i]->at += ev_now - now; |
537 | timers [i]->at += diff; |
|
|
538 | } |
326 | |
539 | |
327 | now = ev_now; |
540 | now = ev_now; |
328 | } |
541 | } |
329 | } |
542 | } |
330 | |
543 | |
331 | int ev_loop_done; |
544 | int ev_loop_done; |
332 | |
545 | |
333 | void ev_loop (int flags) |
546 | void ev_loop (int flags) |
334 | { |
547 | { |
335 | double block; |
548 | double block; |
336 | ev_loop_done = flags & EVLOOP_ONESHOT; |
549 | ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; |
|
|
550 | |
|
|
551 | if (checkcnt) |
|
|
552 | { |
|
|
553 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
|
|
554 | call_pending (); |
|
|
555 | } |
337 | |
556 | |
338 | do |
557 | do |
339 | { |
558 | { |
340 | /* update fd-related kernel structures */ |
559 | /* update fd-related kernel structures */ |
341 | method_reify (); fdchangecnt = 0; |
560 | fd_reify (); |
342 | |
561 | |
343 | /* calculate blocking time */ |
562 | /* calculate blocking time */ |
|
|
563 | |
|
|
564 | /* we only need this for !monotonic clock, but as we always have timers, we just calculate it every time */ |
|
|
565 | ev_now = ev_time (); |
|
|
566 | |
344 | if (flags & EVLOOP_NONBLOCK) |
567 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
345 | block = 0.; |
568 | block = 0.; |
346 | else |
569 | else |
347 | { |
570 | { |
348 | block = MAX_BLOCKTIME; |
571 | block = MAX_BLOCKTIME; |
349 | |
572 | |
350 | if (rtimercnt) |
573 | if (timercnt) |
351 | { |
574 | { |
352 | ev_tstamp to = rtimers [0]->at - get_clock () + method_fudge; |
575 | ev_tstamp to = timers [0]->at - (have_monotonic ? get_clock () : ev_now) + method_fudge; |
353 | if (block > to) block = to; |
576 | if (block > to) block = to; |
354 | } |
577 | } |
355 | |
578 | |
356 | if (atimercnt) |
579 | if (periodiccnt) |
357 | { |
580 | { |
358 | ev_tstamp to = atimers [0]->at - ev_time () + method_fudge; |
581 | ev_tstamp to = periodics [0]->at - ev_now + method_fudge; |
359 | if (block > to) block = to; |
582 | if (block > to) block = to; |
360 | } |
583 | } |
361 | |
584 | |
362 | if (block < 0.) block = 0.; |
585 | if (block < 0.) block = 0.; |
363 | } |
586 | } |
… | |
… | |
365 | method_poll (block); |
588 | method_poll (block); |
366 | |
589 | |
367 | /* update ev_now, do magic */ |
590 | /* update ev_now, do magic */ |
368 | time_update (); |
591 | time_update (); |
369 | |
592 | |
370 | /* put pending timers into pendign queue and reschedule them */ |
593 | /* queue pending timers and reschedule them */ |
371 | /* absolute timers first */ |
594 | periodics_reify (); /* absolute timers first */ |
372 | timers_reify (atimers, atimercnt, ev_now); |
|
|
373 | /* relative timers second */ |
595 | timers_reify (); /* relative timers second */ |
374 | timers_reify (rtimers, rtimercnt, now); |
596 | |
|
|
597 | /* queue idle watchers unless io or timers are pending */ |
|
|
598 | if (!pendingcnt) |
|
|
599 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
|
|
600 | |
|
|
601 | /* queue check and possibly idle watchers */ |
|
|
602 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
375 | |
603 | |
376 | call_pending (); |
604 | call_pending (); |
377 | } |
605 | } |
378 | while (!ev_loop_done); |
606 | while (!ev_loop_done); |
379 | } |
|
|
380 | |
607 | |
|
|
608 | if (ev_loop_done != 2) |
|
|
609 | ev_loop_done = 0; |
|
|
610 | } |
|
|
611 | |
|
|
612 | /*****************************************************************************/ |
|
|
613 | |
381 | static void |
614 | static void |
382 | wlist_add (struct ev_watcher_list **head, struct ev_watcher_list *elem) |
615 | wlist_add (WL *head, WL elem) |
383 | { |
616 | { |
384 | elem->next = *head; |
617 | elem->next = *head; |
385 | *head = elem; |
618 | *head = elem; |
386 | } |
619 | } |
387 | |
620 | |
388 | static void |
621 | static void |
389 | wlist_del (struct ev_watcher_list **head, struct ev_watcher_list *elem) |
622 | wlist_del (WL *head, WL elem) |
390 | { |
623 | { |
391 | while (*head) |
624 | while (*head) |
392 | { |
625 | { |
393 | if (*head == elem) |
626 | if (*head == elem) |
394 | { |
627 | { |
… | |
… | |
399 | head = &(*head)->next; |
632 | head = &(*head)->next; |
400 | } |
633 | } |
401 | } |
634 | } |
402 | |
635 | |
403 | static void |
636 | static void |
404 | ev_start (struct ev_watcher *w, int active) |
637 | ev_clear (W w) |
405 | { |
638 | { |
|
|
639 | if (w->pending) |
|
|
640 | { |
|
|
641 | pendings [w->pending - 1].w = 0; |
406 | w->pending = 0; |
642 | w->pending = 0; |
|
|
643 | } |
|
|
644 | } |
|
|
645 | |
|
|
646 | static void |
|
|
647 | ev_start (W w, int active) |
|
|
648 | { |
407 | w->active = active; |
649 | w->active = active; |
408 | } |
650 | } |
409 | |
651 | |
410 | static void |
652 | static void |
411 | ev_stop (struct ev_watcher *w) |
653 | ev_stop (W w) |
412 | { |
654 | { |
413 | if (w->pending) |
|
|
414 | pendings [w->pending - 1].w = 0; |
|
|
415 | |
|
|
416 | w->active = 0; |
655 | w->active = 0; |
417 | /* nop */ |
|
|
418 | } |
656 | } |
|
|
657 | |
|
|
658 | /*****************************************************************************/ |
419 | |
659 | |
420 | void |
660 | void |
421 | evio_start (struct ev_io *w) |
661 | evio_start (struct ev_io *w) |
422 | { |
662 | { |
423 | if (ev_is_active (w)) |
663 | if (ev_is_active (w)) |
424 | return; |
664 | return; |
425 | |
665 | |
426 | int fd = w->fd; |
666 | int fd = w->fd; |
427 | |
667 | |
428 | ev_start ((struct ev_watcher *)w, 1); |
668 | ev_start ((W)w, 1); |
429 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
669 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
430 | wlist_add ((struct ev_watcher_list **)&anfds[fd].head, (struct ev_watcher_list *)w); |
670 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
431 | |
671 | |
432 | ++fdchangecnt; |
672 | ++fdchangecnt; |
433 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
673 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
434 | fdchanges [fdchangecnt - 1] = fd; |
674 | fdchanges [fdchangecnt - 1] = fd; |
435 | } |
675 | } |
436 | |
676 | |
437 | void |
677 | void |
438 | evio_stop (struct ev_io *w) |
678 | evio_stop (struct ev_io *w) |
439 | { |
679 | { |
|
|
680 | ev_clear ((W)w); |
440 | if (!ev_is_active (w)) |
681 | if (!ev_is_active (w)) |
441 | return; |
682 | return; |
442 | |
683 | |
443 | wlist_del ((struct ev_watcher_list **)&anfds[w->fd].head, (struct ev_watcher_list *)w); |
684 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
444 | ev_stop ((struct ev_watcher *)w); |
685 | ev_stop ((W)w); |
445 | |
686 | |
446 | ++fdchangecnt; |
687 | ++fdchangecnt; |
447 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
688 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
448 | fdchanges [fdchangecnt - 1] = w->fd; |
689 | fdchanges [fdchangecnt - 1] = w->fd; |
449 | } |
690 | } |
… | |
… | |
452 | evtimer_start (struct ev_timer *w) |
693 | evtimer_start (struct ev_timer *w) |
453 | { |
694 | { |
454 | if (ev_is_active (w)) |
695 | if (ev_is_active (w)) |
455 | return; |
696 | return; |
456 | |
697 | |
457 | if (w->is_abs) |
698 | w->at += now; |
458 | { |
|
|
459 | /* this formula differs from the one in timer_reify becuse we do not round up */ |
|
|
460 | if (w->repeat) |
|
|
461 | w->at += ceil ((ev_now - w->at) / w->repeat) * w->repeat; |
|
|
462 | |
699 | |
463 | ev_start ((struct ev_watcher *)w, ++atimercnt); |
700 | assert (("timer repeat value less than zero not allowed", w->repeat >= 0.)); |
|
|
701 | |
|
|
702 | ev_start ((W)w, ++timercnt); |
464 | array_needsize (atimers, atimermax, atimercnt, ); |
703 | array_needsize (timers, timermax, timercnt, ); |
465 | atimers [atimercnt - 1] = w; |
704 | timers [timercnt - 1] = w; |
466 | upheap (atimers, atimercnt - 1); |
705 | upheap ((WT *)timers, timercnt - 1); |
467 | } |
|
|
468 | else |
|
|
469 | { |
|
|
470 | w->at += now; |
|
|
471 | |
|
|
472 | ev_start ((struct ev_watcher *)w, ++rtimercnt); |
|
|
473 | array_needsize (rtimers, rtimermax, rtimercnt, ); |
|
|
474 | rtimers [rtimercnt - 1] = w; |
|
|
475 | upheap (rtimers, rtimercnt - 1); |
|
|
476 | } |
|
|
477 | |
|
|
478 | } |
706 | } |
479 | |
707 | |
480 | void |
708 | void |
481 | evtimer_stop (struct ev_timer *w) |
709 | evtimer_stop (struct ev_timer *w) |
482 | { |
710 | { |
|
|
711 | ev_clear ((W)w); |
483 | if (!ev_is_active (w)) |
712 | if (!ev_is_active (w)) |
484 | return; |
713 | return; |
485 | |
714 | |
486 | if (w->is_abs) |
|
|
487 | { |
|
|
488 | if (w->active < atimercnt--) |
715 | if (w->active < timercnt--) |
489 | { |
716 | { |
490 | atimers [w->active - 1] = atimers [atimercnt]; |
717 | timers [w->active - 1] = timers [timercnt]; |
|
|
718 | downheap ((WT *)timers, timercnt, w->active - 1); |
|
|
719 | } |
|
|
720 | |
|
|
721 | w->at = w->repeat; |
|
|
722 | |
|
|
723 | ev_stop ((W)w); |
|
|
724 | } |
|
|
725 | |
|
|
726 | void |
|
|
727 | evtimer_again (struct ev_timer *w) |
|
|
728 | { |
|
|
729 | if (ev_is_active (w)) |
|
|
730 | { |
|
|
731 | if (w->repeat) |
|
|
732 | { |
|
|
733 | w->at = now + w->repeat; |
491 | downheap (atimers, atimercnt, w->active - 1); |
734 | downheap ((WT *)timers, timercnt, w->active - 1); |
492 | } |
|
|
493 | } |
|
|
494 | else |
|
|
495 | { |
|
|
496 | if (w->active < rtimercnt--) |
|
|
497 | { |
735 | } |
498 | rtimers [w->active - 1] = rtimers [rtimercnt]; |
736 | else |
499 | downheap (rtimers, rtimercnt, w->active - 1); |
737 | evtimer_stop (w); |
500 | } |
738 | } |
|
|
739 | else if (w->repeat) |
|
|
740 | evtimer_start (w); |
|
|
741 | } |
|
|
742 | |
|
|
743 | void |
|
|
744 | evperiodic_start (struct ev_periodic *w) |
|
|
745 | { |
|
|
746 | if (ev_is_active (w)) |
|
|
747 | return; |
|
|
748 | |
|
|
749 | assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); |
|
|
750 | |
|
|
751 | /* this formula differs from the one in periodic_reify because we do not always round up */ |
|
|
752 | if (w->interval) |
|
|
753 | w->at += ceil ((ev_now - w->at) / w->interval) * w->interval; |
|
|
754 | |
|
|
755 | ev_start ((W)w, ++periodiccnt); |
|
|
756 | array_needsize (periodics, periodicmax, periodiccnt, ); |
|
|
757 | periodics [periodiccnt - 1] = w; |
|
|
758 | upheap ((WT *)periodics, periodiccnt - 1); |
|
|
759 | } |
|
|
760 | |
|
|
761 | void |
|
|
762 | evperiodic_stop (struct ev_periodic *w) |
|
|
763 | { |
|
|
764 | ev_clear ((W)w); |
|
|
765 | if (!ev_is_active (w)) |
|
|
766 | return; |
|
|
767 | |
|
|
768 | if (w->active < periodiccnt--) |
501 | } |
769 | { |
|
|
770 | periodics [w->active - 1] = periodics [periodiccnt]; |
|
|
771 | downheap ((WT *)periodics, periodiccnt, w->active - 1); |
|
|
772 | } |
502 | |
773 | |
503 | ev_stop ((struct ev_watcher *)w); |
774 | ev_stop ((W)w); |
504 | } |
775 | } |
505 | |
776 | |
506 | void |
777 | void |
507 | evsignal_start (struct ev_signal *w) |
778 | evsignal_start (struct ev_signal *w) |
508 | { |
779 | { |
509 | if (ev_is_active (w)) |
780 | if (ev_is_active (w)) |
510 | return; |
781 | return; |
511 | |
782 | |
512 | ev_start ((struct ev_watcher *)w, 1); |
783 | ev_start ((W)w, 1); |
513 | array_needsize (signals, signalmax, w->signum, signals_init); |
784 | array_needsize (signals, signalmax, w->signum, signals_init); |
514 | wlist_add ((struct ev_watcher_list **)&signals [w->signum - 1], (struct ev_watcher_list *)w); |
785 | wlist_add ((WL *)&signals [w->signum - 1].head, (WL)w); |
|
|
786 | |
|
|
787 | if (!w->next) |
|
|
788 | { |
|
|
789 | struct sigaction sa; |
|
|
790 | sa.sa_handler = sighandler; |
|
|
791 | sigfillset (&sa.sa_mask); |
|
|
792 | sa.sa_flags = 0; |
|
|
793 | sigaction (w->signum, &sa, 0); |
|
|
794 | } |
515 | } |
795 | } |
516 | |
796 | |
517 | void |
797 | void |
518 | evsignal_stop (struct ev_signal *w) |
798 | evsignal_stop (struct ev_signal *w) |
519 | { |
799 | { |
|
|
800 | ev_clear ((W)w); |
520 | if (!ev_is_active (w)) |
801 | if (!ev_is_active (w)) |
521 | return; |
802 | return; |
522 | |
803 | |
523 | wlist_del ((struct ev_watcher_list **)&signals [w->signum - 1], (struct ev_watcher_list *)w); |
804 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
524 | ev_stop ((struct ev_watcher *)w); |
805 | ev_stop ((W)w); |
525 | } |
|
|
526 | |
806 | |
|
|
807 | if (!signals [w->signum - 1].head) |
|
|
808 | signal (w->signum, SIG_DFL); |
|
|
809 | } |
|
|
810 | |
|
|
811 | void evidle_start (struct ev_idle *w) |
|
|
812 | { |
|
|
813 | if (ev_is_active (w)) |
|
|
814 | return; |
|
|
815 | |
|
|
816 | ev_start ((W)w, ++idlecnt); |
|
|
817 | array_needsize (idles, idlemax, idlecnt, ); |
|
|
818 | idles [idlecnt - 1] = w; |
|
|
819 | } |
|
|
820 | |
|
|
821 | void evidle_stop (struct ev_idle *w) |
|
|
822 | { |
|
|
823 | ev_clear ((W)w); |
|
|
824 | if (ev_is_active (w)) |
|
|
825 | return; |
|
|
826 | |
|
|
827 | idles [w->active - 1] = idles [--idlecnt]; |
|
|
828 | ev_stop ((W)w); |
|
|
829 | } |
|
|
830 | |
|
|
831 | void evcheck_start (struct ev_check *w) |
|
|
832 | { |
|
|
833 | if (ev_is_active (w)) |
|
|
834 | return; |
|
|
835 | |
|
|
836 | ev_start ((W)w, ++checkcnt); |
|
|
837 | array_needsize (checks, checkmax, checkcnt, ); |
|
|
838 | checks [checkcnt - 1] = w; |
|
|
839 | } |
|
|
840 | |
|
|
841 | void evcheck_stop (struct ev_check *w) |
|
|
842 | { |
|
|
843 | ev_clear ((W)w); |
|
|
844 | if (ev_is_active (w)) |
|
|
845 | return; |
|
|
846 | |
|
|
847 | checks [w->active - 1] = checks [--checkcnt]; |
|
|
848 | ev_stop ((W)w); |
|
|
849 | } |
|
|
850 | |
527 | /*****************************************************************************/ |
851 | /*****************************************************************************/ |
|
|
852 | |
|
|
853 | struct ev_once |
|
|
854 | { |
|
|
855 | struct ev_io io; |
|
|
856 | struct ev_timer to; |
|
|
857 | void (*cb)(int revents, void *arg); |
|
|
858 | void *arg; |
|
|
859 | }; |
|
|
860 | |
|
|
861 | static void |
|
|
862 | once_cb (struct ev_once *once, int revents) |
|
|
863 | { |
|
|
864 | void (*cb)(int revents, void *arg) = once->cb; |
|
|
865 | void *arg = once->arg; |
|
|
866 | |
|
|
867 | evio_stop (&once->io); |
|
|
868 | evtimer_stop (&once->to); |
|
|
869 | free (once); |
|
|
870 | |
|
|
871 | cb (revents, arg); |
|
|
872 | } |
|
|
873 | |
|
|
874 | static void |
|
|
875 | once_cb_io (struct ev_io *w, int revents) |
|
|
876 | { |
|
|
877 | once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); |
|
|
878 | } |
|
|
879 | |
|
|
880 | static void |
|
|
881 | once_cb_to (struct ev_timer *w, int revents) |
|
|
882 | { |
|
|
883 | once_cb ((struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); |
|
|
884 | } |
|
|
885 | |
|
|
886 | void |
|
|
887 | ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
|
|
888 | { |
|
|
889 | struct ev_once *once = malloc (sizeof (struct ev_once)); |
|
|
890 | |
|
|
891 | if (!once) |
|
|
892 | cb (EV_ERROR, arg); |
|
|
893 | else |
|
|
894 | { |
|
|
895 | once->cb = cb; |
|
|
896 | once->arg = arg; |
|
|
897 | |
|
|
898 | evw_init (&once->io, once_cb_io); |
|
|
899 | |
|
|
900 | if (fd >= 0) |
|
|
901 | { |
|
|
902 | evio_set (&once->io, fd, events); |
|
|
903 | evio_start (&once->io); |
|
|
904 | } |
|
|
905 | |
|
|
906 | evw_init (&once->to, once_cb_to); |
|
|
907 | |
|
|
908 | if (timeout >= 0.) |
|
|
909 | { |
|
|
910 | evtimer_set (&once->to, timeout, 0.); |
|
|
911 | evtimer_start (&once->to); |
|
|
912 | } |
|
|
913 | } |
|
|
914 | } |
|
|
915 | |
|
|
916 | /*****************************************************************************/ |
|
|
917 | |
528 | #if 1 |
918 | #if 0 |
|
|
919 | |
|
|
920 | struct ev_io wio; |
529 | |
921 | |
530 | static void |
922 | static void |
531 | sin_cb (struct ev_io *w, int revents) |
923 | sin_cb (struct ev_io *w, int revents) |
532 | { |
924 | { |
533 | fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); |
925 | fprintf (stderr, "sin %d, revents %d\n", w->fd, revents); |
… | |
… | |
539 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
931 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
540 | evtimer_stop (w); |
932 | evtimer_stop (w); |
541 | evtimer_start (w); |
933 | evtimer_start (w); |
542 | } |
934 | } |
543 | |
935 | |
|
|
936 | static void |
|
|
937 | scb (struct ev_signal *w, int revents) |
|
|
938 | { |
|
|
939 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
|
|
940 | evio_stop (&wio); |
|
|
941 | evio_start (&wio); |
|
|
942 | } |
|
|
943 | |
|
|
944 | static void |
|
|
945 | gcb (struct ev_signal *w, int revents) |
|
|
946 | { |
|
|
947 | fprintf (stderr, "generic %x\n", revents); |
|
|
948 | |
|
|
949 | } |
|
|
950 | |
544 | int main (void) |
951 | int main (void) |
545 | { |
952 | { |
546 | struct ev_io sin; |
|
|
547 | |
|
|
548 | ev_init (0); |
953 | ev_init (0); |
549 | |
954 | |
550 | evw_init (&sin, sin_cb, 55); |
|
|
551 | evio_set (&sin, 0, EV_READ); |
955 | evio_init (&wio, sin_cb, 0, EV_READ); |
552 | evio_start (&sin); |
956 | evio_start (&wio); |
553 | |
957 | |
554 | struct ev_timer t[10000]; |
958 | struct ev_timer t[10000]; |
555 | |
959 | |
556 | #if 1 |
960 | #if 0 |
557 | int i; |
961 | int i; |
558 | for (i = 0; i < 10000; ++i) |
962 | for (i = 0; i < 10000; ++i) |
559 | { |
963 | { |
560 | struct ev_timer *w = t + i; |
964 | struct ev_timer *w = t + i; |
561 | evw_init (w, ocb, i); |
965 | evw_init (w, ocb, i); |
562 | evtimer_set_abs (w, drand48 (), 0.99775533); |
966 | evtimer_init_abs (w, ocb, drand48 (), 0.99775533); |
563 | evtimer_start (w); |
967 | evtimer_start (w); |
564 | if (drand48 () < 0.5) |
968 | if (drand48 () < 0.5) |
565 | evtimer_stop (w); |
969 | evtimer_stop (w); |
566 | } |
970 | } |
567 | #endif |
971 | #endif |
568 | |
972 | |
569 | struct ev_timer t1; |
973 | struct ev_timer t1; |
570 | evw_init (&t1, ocb, 0); |
974 | evtimer_init (&t1, ocb, 5, 10); |
571 | evtimer_set_abs (&t1, 5, 10); |
|
|
572 | evtimer_start (&t1); |
975 | evtimer_start (&t1); |
573 | |
976 | |
|
|
977 | struct ev_signal sig; |
|
|
978 | evsignal_init (&sig, scb, SIGQUIT); |
|
|
979 | evsignal_start (&sig); |
|
|
980 | |
|
|
981 | struct ev_check cw; |
|
|
982 | evcheck_init (&cw, gcb); |
|
|
983 | evcheck_start (&cw); |
|
|
984 | |
|
|
985 | struct ev_idle iw; |
|
|
986 | evidle_init (&iw, gcb); |
|
|
987 | evidle_start (&iw); |
|
|
988 | |
574 | ev_loop (0); |
989 | ev_loop (0); |
575 | |
990 | |
576 | return 0; |
991 | return 0; |
577 | } |
992 | } |
578 | |
993 | |