|
|
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 | #if EV_USE_CONFIG_H |
|
|
30 | # include "config.h" |
|
|
31 | #endif |
|
|
32 | |
1 | #include <math.h> |
33 | #include <math.h> |
2 | #include <stdlib.h> |
34 | #include <stdlib.h> |
3 | #include <unistd.h> |
35 | #include <unistd.h> |
4 | #include <fcntl.h> |
36 | #include <fcntl.h> |
5 | #include <signal.h> |
37 | #include <signal.h> |
… | |
… | |
7 | |
39 | |
8 | #include <stdio.h> |
40 | #include <stdio.h> |
9 | |
41 | |
10 | #include <assert.h> |
42 | #include <assert.h> |
11 | #include <errno.h> |
43 | #include <errno.h> |
|
|
44 | #include <sys/types.h> |
|
|
45 | #include <sys/wait.h> |
12 | #include <sys/time.h> |
46 | #include <sys/time.h> |
13 | #include <time.h> |
47 | #include <time.h> |
14 | |
48 | |
15 | #define HAVE_EPOLL 1 |
|
|
16 | |
|
|
17 | #ifndef HAVE_MONOTONIC |
49 | #ifndef EV_USE_MONOTONIC |
18 | # ifdef CLOCK_MONOTONIC |
50 | # ifdef CLOCK_MONOTONIC |
19 | # define HAVE_MONOTONIC 1 |
51 | # define EV_USE_MONOTONIC 1 |
20 | # endif |
52 | # endif |
21 | #endif |
53 | #endif |
22 | |
54 | |
23 | #ifndef HAVE_SELECT |
55 | #ifndef EV_USE_SELECT |
24 | # define HAVE_SELECT 1 |
56 | # define EV_USE_SELECT 1 |
25 | #endif |
57 | #endif |
26 | |
58 | |
27 | #ifndef HAVE_EPOLL |
59 | #ifndef EV_USE_EPOLL |
28 | # define HAVE_EPOLL 0 |
60 | # define EV_USE_EPOLL 0 |
29 | #endif |
61 | #endif |
30 | |
62 | |
|
|
63 | #ifndef CLOCK_REALTIME |
|
|
64 | # define EV_USE_REALTIME 0 |
|
|
65 | #endif |
31 | #ifndef HAVE_REALTIME |
66 | #ifndef EV_USE_REALTIME |
32 | # define HAVE_REALTIME 1 /* posix requirement, but might be slower */ |
67 | # define EV_USE_REALTIME 1 /* posix requirement, but might be slower */ |
33 | #endif |
68 | #endif |
34 | |
69 | |
35 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
70 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
36 | #define MAX_BLOCKTIME 60. |
71 | #define MAX_BLOCKTIME 59.731 /* never wait longer than this time (to detetc time jumps) */ |
|
|
72 | #define PID_HASHSIZE 16 /* size of pid hash table, must be power of two */ |
|
|
73 | #define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ |
37 | |
74 | |
38 | #include "ev.h" |
75 | #include "ev.h" |
39 | |
76 | |
40 | typedef struct ev_watcher *W; |
77 | typedef struct ev_watcher *W; |
41 | typedef struct ev_watcher_list *WL; |
78 | typedef struct ev_watcher_list *WL; |
… | |
… | |
54 | /*****************************************************************************/ |
91 | /*****************************************************************************/ |
55 | |
92 | |
56 | ev_tstamp |
93 | ev_tstamp |
57 | ev_time (void) |
94 | ev_time (void) |
58 | { |
95 | { |
59 | #if HAVE_REALTIME |
96 | #if EV_USE_REALTIME |
60 | struct timespec ts; |
97 | struct timespec ts; |
61 | clock_gettime (CLOCK_REALTIME, &ts); |
98 | clock_gettime (CLOCK_REALTIME, &ts); |
62 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
99 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
63 | #else |
100 | #else |
64 | struct timeval tv; |
101 | struct timeval tv; |
… | |
… | |
68 | } |
105 | } |
69 | |
106 | |
70 | static ev_tstamp |
107 | static ev_tstamp |
71 | get_clock (void) |
108 | get_clock (void) |
72 | { |
109 | { |
73 | #if HAVE_MONOTONIC |
110 | #if EV_USE_MONOTONIC |
74 | if (have_monotonic) |
111 | if (have_monotonic) |
75 | { |
112 | { |
76 | struct timespec ts; |
113 | struct timespec ts; |
77 | clock_gettime (CLOCK_MONOTONIC, &ts); |
114 | clock_gettime (CLOCK_MONOTONIC, &ts); |
78 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
115 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
… | |
… | |
80 | #endif |
117 | #endif |
81 | |
118 | |
82 | return ev_time (); |
119 | return ev_time (); |
83 | } |
120 | } |
84 | |
121 | |
|
|
122 | #define array_roundsize(base,n) ((n) | 4 & ~3) |
|
|
123 | |
85 | #define array_needsize(base,cur,cnt,init) \ |
124 | #define array_needsize(base,cur,cnt,init) \ |
86 | if ((cnt) > cur) \ |
125 | if ((cnt) > cur) \ |
87 | { \ |
126 | { \ |
88 | int newcnt = cur ? cur << 1 : 16; \ |
127 | int newcnt = cur; \ |
|
|
128 | do \ |
|
|
129 | { \ |
|
|
130 | newcnt = array_roundsize (base, newcnt << 1); \ |
|
|
131 | } \ |
|
|
132 | while ((cnt) > newcnt); \ |
|
|
133 | \ |
89 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
134 | base = realloc (base, sizeof (*base) * (newcnt)); \ |
90 | init (base + cur, newcnt - cur); \ |
135 | init (base + cur, newcnt - cur); \ |
91 | cur = newcnt; \ |
136 | cur = newcnt; \ |
92 | } |
137 | } |
93 | |
138 | |
94 | /*****************************************************************************/ |
139 | /*****************************************************************************/ |
95 | |
140 | |
96 | typedef struct |
141 | typedef struct |
97 | { |
142 | { |
98 | struct ev_io *head; |
143 | struct ev_io *head; |
99 | unsigned char wev, rev; /* want, received event set */ |
144 | int events; |
100 | } ANFD; |
145 | } ANFD; |
101 | |
146 | |
102 | static ANFD *anfds; |
147 | static ANFD *anfds; |
103 | static int anfdmax; |
148 | static int anfdmax; |
104 | |
149 | |
105 | static int *fdchanges; |
|
|
106 | static int fdchangemax, fdchangecnt; |
|
|
107 | |
|
|
108 | static void |
150 | static void |
109 | anfds_init (ANFD *base, int count) |
151 | anfds_init (ANFD *base, int count) |
110 | { |
152 | { |
111 | while (count--) |
153 | while (count--) |
112 | { |
154 | { |
113 | base->head = 0; |
155 | base->head = 0; |
114 | base->wev = base->rev = EV_NONE; |
156 | base->events = EV_NONE; |
115 | ++base; |
157 | ++base; |
116 | } |
158 | } |
117 | } |
159 | } |
118 | |
160 | |
119 | typedef struct |
161 | typedef struct |
… | |
… | |
126 | static int pendingmax, pendingcnt; |
168 | static int pendingmax, pendingcnt; |
127 | |
169 | |
128 | static void |
170 | static void |
129 | event (W w, int events) |
171 | event (W w, int events) |
130 | { |
172 | { |
131 | if (w->active) |
|
|
132 | { |
|
|
133 | w->pending = ++pendingcnt; |
173 | w->pending = ++pendingcnt; |
134 | array_needsize (pendings, pendingmax, pendingcnt, ); |
174 | array_needsize (pendings, pendingmax, pendingcnt, ); |
135 | pendings [pendingcnt - 1].w = w; |
175 | pendings [pendingcnt - 1].w = w; |
136 | pendings [pendingcnt - 1].events = events; |
176 | pendings [pendingcnt - 1].events = events; |
137 | } |
177 | } |
|
|
178 | |
|
|
179 | static void |
|
|
180 | queue_events (W *events, int eventcnt, int type) |
|
|
181 | { |
|
|
182 | int i; |
|
|
183 | |
|
|
184 | for (i = 0; i < eventcnt; ++i) |
|
|
185 | event (events [i], type); |
138 | } |
186 | } |
139 | |
187 | |
140 | static void |
188 | static void |
141 | fd_event (int fd, int events) |
189 | fd_event (int fd, int events) |
142 | { |
190 | { |
… | |
… | |
150 | if (ev) |
198 | if (ev) |
151 | event ((W)w, ev); |
199 | event ((W)w, ev); |
152 | } |
200 | } |
153 | } |
201 | } |
154 | |
202 | |
|
|
203 | /*****************************************************************************/ |
|
|
204 | |
|
|
205 | static int *fdchanges; |
|
|
206 | static int fdchangemax, fdchangecnt; |
|
|
207 | |
155 | static void |
208 | static void |
156 | queue_events (W *events, int eventcnt, int type) |
209 | fd_reify (void) |
157 | { |
210 | { |
158 | int i; |
211 | int i; |
159 | |
212 | |
160 | for (i = 0; i < eventcnt; ++i) |
213 | for (i = 0; i < fdchangecnt; ++i) |
161 | event (events [i], type); |
214 | { |
|
|
215 | int fd = fdchanges [i]; |
|
|
216 | ANFD *anfd = anfds + fd; |
|
|
217 | struct ev_io *w; |
|
|
218 | |
|
|
219 | int events = 0; |
|
|
220 | |
|
|
221 | for (w = anfd->head; w; w = w->next) |
|
|
222 | events |= w->events; |
|
|
223 | |
|
|
224 | anfd->events &= ~EV_REIFY; |
|
|
225 | |
|
|
226 | if (anfd->events != events) |
|
|
227 | { |
|
|
228 | method_modify (fd, anfd->events, events); |
|
|
229 | anfd->events = events; |
|
|
230 | } |
|
|
231 | } |
|
|
232 | |
|
|
233 | fdchangecnt = 0; |
|
|
234 | } |
|
|
235 | |
|
|
236 | static void |
|
|
237 | fd_change (int fd) |
|
|
238 | { |
|
|
239 | if (anfds [fd].events & EV_REIFY || fdchangecnt < 0) |
|
|
240 | return; |
|
|
241 | |
|
|
242 | anfds [fd].events |= EV_REIFY; |
|
|
243 | |
|
|
244 | ++fdchangecnt; |
|
|
245 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
|
|
246 | fdchanges [fdchangecnt - 1] = fd; |
|
|
247 | } |
|
|
248 | |
|
|
249 | /* called on EBADF to verify fds */ |
|
|
250 | static void |
|
|
251 | fd_recheck (void) |
|
|
252 | { |
|
|
253 | int fd; |
|
|
254 | |
|
|
255 | for (fd = 0; fd < anfdmax; ++fd) |
|
|
256 | if (anfds [fd].events) |
|
|
257 | if (fcntl (fd, F_GETFD) == -1 && errno == EBADF) |
|
|
258 | while (anfds [fd].head) |
|
|
259 | { |
|
|
260 | event ((W)anfds [fd].head, EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT); |
|
|
261 | ev_io_stop (anfds [fd].head); |
|
|
262 | } |
162 | } |
263 | } |
163 | |
264 | |
164 | /*****************************************************************************/ |
265 | /*****************************************************************************/ |
165 | |
266 | |
166 | static struct ev_timer **timers; |
267 | static struct ev_timer **timers; |
… | |
… | |
275 | |
376 | |
276 | /* rather than sort out wether we really need nb, set it */ |
377 | /* rather than sort out wether we really need nb, set it */ |
277 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
378 | fcntl (sigpipe [0], F_SETFL, O_NONBLOCK); |
278 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
379 | fcntl (sigpipe [1], F_SETFL, O_NONBLOCK); |
279 | |
380 | |
280 | evio_set (&sigev, sigpipe [0], EV_READ); |
381 | ev_io_set (&sigev, sigpipe [0], EV_READ); |
281 | evio_start (&sigev); |
382 | ev_io_start (&sigev); |
282 | } |
383 | } |
283 | |
384 | |
284 | /*****************************************************************************/ |
385 | /*****************************************************************************/ |
285 | |
386 | |
286 | static struct ev_idle **idles; |
387 | static struct ev_idle **idles; |
287 | static int idlemax, idlecnt; |
388 | static int idlemax, idlecnt; |
288 | |
389 | |
|
|
390 | static struct ev_prepare **prepares; |
|
|
391 | static int preparemax, preparecnt; |
|
|
392 | |
289 | static struct ev_check **checks; |
393 | static struct ev_check **checks; |
290 | static int checkmax, checkcnt; |
394 | static int checkmax, checkcnt; |
291 | |
395 | |
292 | /*****************************************************************************/ |
396 | /*****************************************************************************/ |
293 | |
397 | |
|
|
398 | static struct ev_child *childs [PID_HASHSIZE]; |
|
|
399 | static struct ev_signal childev; |
|
|
400 | |
|
|
401 | #ifndef WCONTINUED |
|
|
402 | # define WCONTINUED 0 |
|
|
403 | #endif |
|
|
404 | |
|
|
405 | static void |
|
|
406 | childcb (struct ev_signal *sw, int revents) |
|
|
407 | { |
|
|
408 | struct ev_child *w; |
|
|
409 | int pid, status; |
|
|
410 | |
|
|
411 | while ((pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)) != -1) |
|
|
412 | for (w = childs [pid & (PID_HASHSIZE - 1)]; w; w = w->next) |
|
|
413 | if (w->pid == pid || w->pid == -1) |
|
|
414 | { |
|
|
415 | w->status = status; |
|
|
416 | event ((W)w, EV_CHILD); |
|
|
417 | } |
|
|
418 | } |
|
|
419 | |
|
|
420 | /*****************************************************************************/ |
|
|
421 | |
294 | #if HAVE_EPOLL |
422 | #if EV_USE_EPOLL |
295 | # include "ev_epoll.c" |
423 | # include "ev_epoll.c" |
296 | #endif |
424 | #endif |
297 | #if HAVE_SELECT |
425 | #if EV_USE_SELECT |
298 | # include "ev_select.c" |
426 | # include "ev_select.c" |
299 | #endif |
427 | #endif |
300 | |
428 | |
|
|
429 | int |
|
|
430 | ev_version_major (void) |
|
|
431 | { |
|
|
432 | return EV_VERSION_MAJOR; |
|
|
433 | } |
|
|
434 | |
|
|
435 | int |
|
|
436 | ev_version_minor (void) |
|
|
437 | { |
|
|
438 | return EV_VERSION_MINOR; |
|
|
439 | } |
|
|
440 | |
301 | int ev_init (int flags) |
441 | int ev_init (int flags) |
302 | { |
442 | { |
303 | #if HAVE_MONOTONIC |
|
|
304 | { |
|
|
305 | struct timespec ts; |
|
|
306 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
|
|
307 | have_monotonic = 1; |
|
|
308 | } |
|
|
309 | #endif |
|
|
310 | |
|
|
311 | ev_now = ev_time (); |
|
|
312 | now = get_clock (); |
|
|
313 | diff = ev_now - now; |
|
|
314 | |
|
|
315 | if (pipe (sigpipe)) |
|
|
316 | return 0; |
|
|
317 | |
|
|
318 | ev_method = EVMETHOD_NONE; |
|
|
319 | #if HAVE_EPOLL |
|
|
320 | if (ev_method == EVMETHOD_NONE) epoll_init (flags); |
|
|
321 | #endif |
|
|
322 | #if HAVE_SELECT |
|
|
323 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
|
|
324 | #endif |
|
|
325 | |
|
|
326 | if (ev_method) |
443 | if (!ev_method) |
|
|
444 | { |
|
|
445 | #if EV_USE_MONOTONIC |
327 | { |
446 | { |
|
|
447 | struct timespec ts; |
|
|
448 | if (!clock_gettime (CLOCK_MONOTONIC, &ts)) |
|
|
449 | have_monotonic = 1; |
|
|
450 | } |
|
|
451 | #endif |
|
|
452 | |
|
|
453 | ev_now = ev_time (); |
|
|
454 | now = get_clock (); |
|
|
455 | diff = ev_now - now; |
|
|
456 | |
|
|
457 | if (pipe (sigpipe)) |
|
|
458 | return 0; |
|
|
459 | |
|
|
460 | ev_method = EVMETHOD_NONE; |
|
|
461 | #if EV_USE_EPOLL |
|
|
462 | if (ev_method == EVMETHOD_NONE) epoll_init (flags); |
|
|
463 | #endif |
|
|
464 | #if EV_USE_SELECT |
|
|
465 | if (ev_method == EVMETHOD_NONE) select_init (flags); |
|
|
466 | #endif |
|
|
467 | |
|
|
468 | if (ev_method) |
|
|
469 | { |
328 | evw_init (&sigev, sigcb); |
470 | ev_watcher_init (&sigev, sigcb); |
329 | siginit (); |
471 | siginit (); |
|
|
472 | |
|
|
473 | ev_signal_init (&childev, childcb, SIGCHLD); |
|
|
474 | ev_signal_start (&childev); |
|
|
475 | } |
330 | } |
476 | } |
331 | |
477 | |
332 | return ev_method; |
478 | return ev_method; |
333 | } |
479 | } |
334 | |
480 | |
335 | /*****************************************************************************/ |
481 | /*****************************************************************************/ |
336 | |
482 | |
|
|
483 | void |
337 | void ev_prefork (void) |
484 | ev_prefork (void) |
338 | { |
485 | { |
339 | /* nop */ |
486 | /* nop */ |
340 | } |
487 | } |
341 | |
488 | |
|
|
489 | void |
342 | void ev_postfork_parent (void) |
490 | ev_postfork_parent (void) |
343 | { |
491 | { |
344 | /* nop */ |
492 | /* nop */ |
345 | } |
493 | } |
346 | |
494 | |
|
|
495 | void |
347 | void ev_postfork_child (void) |
496 | ev_postfork_child (void) |
348 | { |
497 | { |
349 | #if HAVE_EPOLL |
498 | #if EV_USE_EPOLL |
350 | if (ev_method == EVMETHOD_EPOLL) |
499 | if (ev_method == EVMETHOD_EPOLL) |
351 | epoll_postfork_child (); |
500 | epoll_postfork_child (); |
352 | #endif |
501 | #endif |
353 | |
502 | |
354 | evio_stop (&sigev); |
503 | ev_io_stop (&sigev); |
355 | close (sigpipe [0]); |
504 | close (sigpipe [0]); |
356 | close (sigpipe [1]); |
505 | close (sigpipe [1]); |
357 | pipe (sigpipe); |
506 | pipe (sigpipe); |
358 | siginit (); |
507 | siginit (); |
359 | } |
508 | } |
360 | |
509 | |
361 | /*****************************************************************************/ |
510 | /*****************************************************************************/ |
362 | |
511 | |
363 | static void |
512 | static void |
364 | fd_reify (void) |
|
|
365 | { |
|
|
366 | int i; |
|
|
367 | |
|
|
368 | for (i = 0; i < fdchangecnt; ++i) |
|
|
369 | { |
|
|
370 | int fd = fdchanges [i]; |
|
|
371 | ANFD *anfd = anfds + fd; |
|
|
372 | struct ev_io *w; |
|
|
373 | |
|
|
374 | int wev = 0; |
|
|
375 | |
|
|
376 | for (w = anfd->head; w; w = w->next) |
|
|
377 | wev |= w->events; |
|
|
378 | |
|
|
379 | if (anfd->wev != wev) |
|
|
380 | { |
|
|
381 | method_modify (fd, anfd->wev, wev); |
|
|
382 | anfd->wev = wev; |
|
|
383 | } |
|
|
384 | } |
|
|
385 | |
|
|
386 | fdchangecnt = 0; |
|
|
387 | } |
|
|
388 | |
|
|
389 | static void |
|
|
390 | call_pending () |
513 | call_pending (void) |
391 | { |
514 | { |
392 | int i; |
515 | while (pendingcnt) |
393 | |
|
|
394 | for (i = 0; i < pendingcnt; ++i) |
|
|
395 | { |
516 | { |
396 | ANPENDING *p = pendings + i; |
517 | ANPENDING *p = pendings + --pendingcnt; |
397 | |
518 | |
398 | if (p->w) |
519 | if (p->w) |
399 | { |
520 | { |
400 | p->w->pending = 0; |
521 | p->w->pending = 0; |
401 | p->w->cb (p->w, p->events); |
522 | p->w->cb (p->w, p->events); |
402 | } |
523 | } |
403 | } |
524 | } |
404 | |
|
|
405 | pendingcnt = 0; |
|
|
406 | } |
525 | } |
407 | |
526 | |
408 | static void |
527 | static void |
409 | timers_reify () |
528 | timers_reify (void) |
410 | { |
529 | { |
411 | while (timercnt && timers [0]->at <= now) |
530 | while (timercnt && timers [0]->at <= now) |
412 | { |
531 | { |
413 | struct ev_timer *w = timers [0]; |
532 | struct ev_timer *w = timers [0]; |
414 | |
|
|
415 | event ((W)w, EV_TIMEOUT); |
|
|
416 | |
533 | |
417 | /* first reschedule or stop timer */ |
534 | /* first reschedule or stop timer */ |
418 | if (w->repeat) |
535 | if (w->repeat) |
419 | { |
536 | { |
420 | w->at = now + w->repeat; |
537 | w->at = now + w->repeat; |
421 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
538 | assert (("timer timeout in the past, negative repeat?", w->at > now)); |
422 | downheap ((WT *)timers, timercnt, 0); |
539 | downheap ((WT *)timers, timercnt, 0); |
423 | } |
540 | } |
424 | else |
541 | else |
425 | evtimer_stop (w); /* nonrepeating: stop timer */ |
542 | ev_timer_stop (w); /* nonrepeating: stop timer */ |
426 | } |
|
|
427 | } |
|
|
428 | |
543 | |
|
|
544 | event ((W)w, EV_TIMEOUT); |
|
|
545 | } |
|
|
546 | } |
|
|
547 | |
429 | static void |
548 | static void |
430 | periodics_reify () |
549 | periodics_reify (void) |
431 | { |
550 | { |
432 | while (periodiccnt && periodics [0]->at <= ev_now) |
551 | while (periodiccnt && periodics [0]->at <= ev_now) |
433 | { |
552 | { |
434 | struct ev_periodic *w = periodics [0]; |
553 | struct ev_periodic *w = periodics [0]; |
435 | |
554 | |
… | |
… | |
439 | w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; |
558 | w->at += floor ((ev_now - w->at) / w->interval + 1.) * w->interval; |
440 | assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); |
559 | assert (("periodic timeout in the past, negative interval?", w->at > ev_now)); |
441 | downheap ((WT *)periodics, periodiccnt, 0); |
560 | downheap ((WT *)periodics, periodiccnt, 0); |
442 | } |
561 | } |
443 | else |
562 | else |
444 | evperiodic_stop (w); /* nonrepeating: stop timer */ |
563 | ev_periodic_stop (w); /* nonrepeating: stop timer */ |
445 | |
564 | |
446 | event ((W)w, EV_TIMEOUT); |
565 | event ((W)w, EV_TIMEOUT); |
447 | } |
566 | } |
448 | } |
567 | } |
449 | |
568 | |
… | |
… | |
461 | { |
580 | { |
462 | ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; |
581 | ev_tstamp diff = ceil ((ev_now - w->at) / w->interval) * w->interval; |
463 | |
582 | |
464 | if (fabs (diff) >= 1e-4) |
583 | if (fabs (diff) >= 1e-4) |
465 | { |
584 | { |
466 | evperiodic_stop (w); |
585 | ev_periodic_stop (w); |
467 | evperiodic_start (w); |
586 | ev_periodic_start (w); |
468 | |
587 | |
469 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
588 | i = 0; /* restart loop, inefficient, but time jumps should be rare */ |
470 | } |
589 | } |
471 | } |
590 | } |
472 | } |
591 | } |
473 | } |
592 | } |
474 | |
593 | |
475 | static void |
594 | static void |
476 | time_update () |
595 | time_update (void) |
477 | { |
596 | { |
478 | int i; |
597 | int i; |
479 | |
598 | |
480 | ev_now = ev_time (); |
599 | ev_now = ev_time (); |
481 | |
600 | |
… | |
… | |
515 | int ev_loop_done; |
634 | int ev_loop_done; |
516 | |
635 | |
517 | void ev_loop (int flags) |
636 | void ev_loop (int flags) |
518 | { |
637 | { |
519 | double block; |
638 | double block; |
520 | ev_loop_done = flags & EVLOOP_ONESHOT ? 1 : 0; |
639 | ev_loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; |
521 | |
|
|
522 | if (checkcnt) |
|
|
523 | { |
|
|
524 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
|
|
525 | call_pending (); |
|
|
526 | } |
|
|
527 | |
640 | |
528 | do |
641 | do |
529 | { |
642 | { |
|
|
643 | /* queue check watchers (and execute them) */ |
|
|
644 | if (preparecnt) |
|
|
645 | { |
|
|
646 | queue_events ((W *)prepares, preparecnt, EV_PREPARE); |
|
|
647 | call_pending (); |
|
|
648 | } |
|
|
649 | |
530 | /* update fd-related kernel structures */ |
650 | /* update fd-related kernel structures */ |
531 | fd_reify (); |
651 | fd_reify (); |
532 | |
652 | |
533 | /* calculate blocking time */ |
653 | /* calculate blocking time */ |
534 | |
654 | |
535 | /* we only need this for !monotonic clock, but as we always have timers, we just calculate it every time */ |
655 | /* we only need this for !monotonic clockor timers, but as we basically |
|
|
656 | always have timers, we just calculate it always */ |
536 | ev_now = ev_time (); |
657 | ev_now = ev_time (); |
537 | |
658 | |
538 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
659 | if (flags & EVLOOP_NONBLOCK || idlecnt) |
539 | block = 0.; |
660 | block = 0.; |
540 | else |
661 | else |
… | |
… | |
560 | |
681 | |
561 | /* update ev_now, do magic */ |
682 | /* update ev_now, do magic */ |
562 | time_update (); |
683 | time_update (); |
563 | |
684 | |
564 | /* queue pending timers and reschedule them */ |
685 | /* queue pending timers and reschedule them */ |
|
|
686 | timers_reify (); /* relative timers called last */ |
565 | periodics_reify (); /* absolute timers first */ |
687 | periodics_reify (); /* absolute timers called first */ |
566 | timers_reify (); /* relative timers second */ |
|
|
567 | |
688 | |
568 | /* queue idle watchers unless io or timers are pending */ |
689 | /* queue idle watchers unless io or timers are pending */ |
569 | if (!pendingcnt) |
690 | if (!pendingcnt) |
570 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
691 | queue_events ((W *)idles, idlecnt, EV_IDLE); |
571 | |
692 | |
572 | /* queue check and possibly idle watchers */ |
693 | /* queue check watchers, to be executed first */ |
|
|
694 | if (checkcnt) |
573 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
695 | queue_events ((W *)checks, checkcnt, EV_CHECK); |
574 | |
696 | |
575 | call_pending (); |
697 | call_pending (); |
576 | } |
698 | } |
577 | while (!ev_loop_done); |
699 | while (!ev_loop_done); |
578 | |
700 | |
… | |
… | |
627 | } |
749 | } |
628 | |
750 | |
629 | /*****************************************************************************/ |
751 | /*****************************************************************************/ |
630 | |
752 | |
631 | void |
753 | void |
632 | evio_start (struct ev_io *w) |
754 | ev_io_start (struct ev_io *w) |
633 | { |
755 | { |
634 | if (ev_is_active (w)) |
756 | if (ev_is_active (w)) |
635 | return; |
757 | return; |
636 | |
758 | |
637 | int fd = w->fd; |
759 | int fd = w->fd; |
638 | |
760 | |
639 | ev_start ((W)w, 1); |
761 | ev_start ((W)w, 1); |
640 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
762 | array_needsize (anfds, anfdmax, fd + 1, anfds_init); |
641 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
763 | wlist_add ((WL *)&anfds[fd].head, (WL)w); |
642 | |
764 | |
643 | ++fdchangecnt; |
765 | fd_change (fd); |
644 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
|
|
645 | fdchanges [fdchangecnt - 1] = fd; |
|
|
646 | } |
766 | } |
647 | |
767 | |
648 | void |
768 | void |
649 | evio_stop (struct ev_io *w) |
769 | ev_io_stop (struct ev_io *w) |
650 | { |
770 | { |
651 | ev_clear ((W)w); |
771 | ev_clear ((W)w); |
652 | if (!ev_is_active (w)) |
772 | if (!ev_is_active (w)) |
653 | return; |
773 | return; |
654 | |
774 | |
655 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
775 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
656 | ev_stop ((W)w); |
776 | ev_stop ((W)w); |
657 | |
777 | |
658 | ++fdchangecnt; |
778 | fd_change (w->fd); |
659 | array_needsize (fdchanges, fdchangemax, fdchangecnt, ); |
|
|
660 | fdchanges [fdchangecnt - 1] = w->fd; |
|
|
661 | } |
779 | } |
662 | |
780 | |
663 | void |
781 | void |
664 | evtimer_start (struct ev_timer *w) |
782 | ev_timer_start (struct ev_timer *w) |
665 | { |
783 | { |
666 | if (ev_is_active (w)) |
784 | if (ev_is_active (w)) |
667 | return; |
785 | return; |
668 | |
786 | |
669 | w->at += now; |
787 | w->at += now; |
… | |
… | |
675 | timers [timercnt - 1] = w; |
793 | timers [timercnt - 1] = w; |
676 | upheap ((WT *)timers, timercnt - 1); |
794 | upheap ((WT *)timers, timercnt - 1); |
677 | } |
795 | } |
678 | |
796 | |
679 | void |
797 | void |
680 | evtimer_stop (struct ev_timer *w) |
798 | ev_timer_stop (struct ev_timer *w) |
681 | { |
799 | { |
682 | ev_clear ((W)w); |
800 | ev_clear ((W)w); |
683 | if (!ev_is_active (w)) |
801 | if (!ev_is_active (w)) |
684 | return; |
802 | return; |
685 | |
803 | |
… | |
… | |
693 | |
811 | |
694 | ev_stop ((W)w); |
812 | ev_stop ((W)w); |
695 | } |
813 | } |
696 | |
814 | |
697 | void |
815 | void |
698 | evtimer_again (struct ev_timer *w) |
816 | ev_timer_again (struct ev_timer *w) |
699 | { |
817 | { |
700 | if (ev_is_active (w)) |
818 | if (ev_is_active (w)) |
701 | { |
819 | { |
702 | if (w->repeat) |
820 | if (w->repeat) |
703 | { |
821 | { |
704 | w->at = now + w->repeat; |
822 | w->at = now + w->repeat; |
705 | downheap ((WT *)timers, timercnt, w->active - 1); |
823 | downheap ((WT *)timers, timercnt, w->active - 1); |
706 | } |
824 | } |
707 | else |
825 | else |
708 | evtimer_stop (w); |
826 | ev_timer_stop (w); |
709 | } |
827 | } |
710 | else if (w->repeat) |
828 | else if (w->repeat) |
711 | evtimer_start (w); |
829 | ev_timer_start (w); |
712 | } |
830 | } |
713 | |
831 | |
714 | void |
832 | void |
715 | evperiodic_start (struct ev_periodic *w) |
833 | ev_periodic_start (struct ev_periodic *w) |
716 | { |
834 | { |
717 | if (ev_is_active (w)) |
835 | if (ev_is_active (w)) |
718 | return; |
836 | return; |
719 | |
837 | |
720 | assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); |
838 | assert (("periodic interval value less than zero not allowed", w->interval >= 0.)); |
… | |
… | |
728 | periodics [periodiccnt - 1] = w; |
846 | periodics [periodiccnt - 1] = w; |
729 | upheap ((WT *)periodics, periodiccnt - 1); |
847 | upheap ((WT *)periodics, periodiccnt - 1); |
730 | } |
848 | } |
731 | |
849 | |
732 | void |
850 | void |
733 | evperiodic_stop (struct ev_periodic *w) |
851 | ev_periodic_stop (struct ev_periodic *w) |
734 | { |
852 | { |
735 | ev_clear ((W)w); |
853 | ev_clear ((W)w); |
736 | if (!ev_is_active (w)) |
854 | if (!ev_is_active (w)) |
737 | return; |
855 | return; |
738 | |
856 | |
… | |
… | |
744 | |
862 | |
745 | ev_stop ((W)w); |
863 | ev_stop ((W)w); |
746 | } |
864 | } |
747 | |
865 | |
748 | void |
866 | void |
749 | evsignal_start (struct ev_signal *w) |
867 | ev_signal_start (struct ev_signal *w) |
750 | { |
868 | { |
751 | if (ev_is_active (w)) |
869 | if (ev_is_active (w)) |
752 | return; |
870 | return; |
753 | |
871 | |
754 | ev_start ((W)w, 1); |
872 | ev_start ((W)w, 1); |
… | |
… | |
764 | sigaction (w->signum, &sa, 0); |
882 | sigaction (w->signum, &sa, 0); |
765 | } |
883 | } |
766 | } |
884 | } |
767 | |
885 | |
768 | void |
886 | void |
769 | evsignal_stop (struct ev_signal *w) |
887 | ev_signal_stop (struct ev_signal *w) |
770 | { |
888 | { |
771 | ev_clear ((W)w); |
889 | ev_clear ((W)w); |
772 | if (!ev_is_active (w)) |
890 | if (!ev_is_active (w)) |
773 | return; |
891 | return; |
774 | |
892 | |
… | |
… | |
777 | |
895 | |
778 | if (!signals [w->signum - 1].head) |
896 | if (!signals [w->signum - 1].head) |
779 | signal (w->signum, SIG_DFL); |
897 | signal (w->signum, SIG_DFL); |
780 | } |
898 | } |
781 | |
899 | |
|
|
900 | void |
782 | void evidle_start (struct ev_idle *w) |
901 | ev_idle_start (struct ev_idle *w) |
783 | { |
902 | { |
784 | if (ev_is_active (w)) |
903 | if (ev_is_active (w)) |
785 | return; |
904 | return; |
786 | |
905 | |
787 | ev_start ((W)w, ++idlecnt); |
906 | ev_start ((W)w, ++idlecnt); |
788 | array_needsize (idles, idlemax, idlecnt, ); |
907 | array_needsize (idles, idlemax, idlecnt, ); |
789 | idles [idlecnt - 1] = w; |
908 | idles [idlecnt - 1] = w; |
790 | } |
909 | } |
791 | |
910 | |
|
|
911 | void |
792 | void evidle_stop (struct ev_idle *w) |
912 | ev_idle_stop (struct ev_idle *w) |
793 | { |
913 | { |
794 | ev_clear ((W)w); |
914 | ev_clear ((W)w); |
795 | if (ev_is_active (w)) |
915 | if (ev_is_active (w)) |
796 | return; |
916 | return; |
797 | |
917 | |
798 | idles [w->active - 1] = idles [--idlecnt]; |
918 | idles [w->active - 1] = idles [--idlecnt]; |
799 | ev_stop ((W)w); |
919 | ev_stop ((W)w); |
800 | } |
920 | } |
801 | |
921 | |
|
|
922 | void |
|
|
923 | ev_prepare_start (struct ev_prepare *w) |
|
|
924 | { |
|
|
925 | if (ev_is_active (w)) |
|
|
926 | return; |
|
|
927 | |
|
|
928 | ev_start ((W)w, ++preparecnt); |
|
|
929 | array_needsize (prepares, preparemax, preparecnt, ); |
|
|
930 | prepares [preparecnt - 1] = w; |
|
|
931 | } |
|
|
932 | |
|
|
933 | void |
|
|
934 | ev_prepare_stop (struct ev_prepare *w) |
|
|
935 | { |
|
|
936 | ev_clear ((W)w); |
|
|
937 | if (ev_is_active (w)) |
|
|
938 | return; |
|
|
939 | |
|
|
940 | prepares [w->active - 1] = prepares [--preparecnt]; |
|
|
941 | ev_stop ((W)w); |
|
|
942 | } |
|
|
943 | |
|
|
944 | void |
802 | void evcheck_start (struct ev_check *w) |
945 | ev_check_start (struct ev_check *w) |
803 | { |
946 | { |
804 | if (ev_is_active (w)) |
947 | if (ev_is_active (w)) |
805 | return; |
948 | return; |
806 | |
949 | |
807 | ev_start ((W)w, ++checkcnt); |
950 | ev_start ((W)w, ++checkcnt); |
808 | array_needsize (checks, checkmax, checkcnt, ); |
951 | array_needsize (checks, checkmax, checkcnt, ); |
809 | checks [checkcnt - 1] = w; |
952 | checks [checkcnt - 1] = w; |
810 | } |
953 | } |
811 | |
954 | |
|
|
955 | void |
812 | void evcheck_stop (struct ev_check *w) |
956 | ev_check_stop (struct ev_check *w) |
813 | { |
957 | { |
814 | ev_clear ((W)w); |
958 | ev_clear ((W)w); |
815 | if (ev_is_active (w)) |
959 | if (ev_is_active (w)) |
816 | return; |
960 | return; |
817 | |
961 | |
818 | checks [w->active - 1] = checks [--checkcnt]; |
962 | checks [w->active - 1] = checks [--checkcnt]; |
|
|
963 | ev_stop ((W)w); |
|
|
964 | } |
|
|
965 | |
|
|
966 | void |
|
|
967 | ev_child_start (struct ev_child *w) |
|
|
968 | { |
|
|
969 | if (ev_is_active (w)) |
|
|
970 | return; |
|
|
971 | |
|
|
972 | ev_start ((W)w, 1); |
|
|
973 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
|
|
974 | } |
|
|
975 | |
|
|
976 | void |
|
|
977 | ev_child_stop (struct ev_child *w) |
|
|
978 | { |
|
|
979 | ev_clear ((W)w); |
|
|
980 | if (ev_is_active (w)) |
|
|
981 | return; |
|
|
982 | |
|
|
983 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
819 | ev_stop ((W)w); |
984 | ev_stop ((W)w); |
820 | } |
985 | } |
821 | |
986 | |
822 | /*****************************************************************************/ |
987 | /*****************************************************************************/ |
823 | |
988 | |
… | |
… | |
833 | once_cb (struct ev_once *once, int revents) |
998 | once_cb (struct ev_once *once, int revents) |
834 | { |
999 | { |
835 | void (*cb)(int revents, void *arg) = once->cb; |
1000 | void (*cb)(int revents, void *arg) = once->cb; |
836 | void *arg = once->arg; |
1001 | void *arg = once->arg; |
837 | |
1002 | |
838 | evio_stop (&once->io); |
1003 | ev_io_stop (&once->io); |
839 | evtimer_stop (&once->to); |
1004 | ev_timer_stop (&once->to); |
840 | free (once); |
1005 | free (once); |
841 | |
1006 | |
842 | cb (revents, arg); |
1007 | cb (revents, arg); |
843 | } |
1008 | } |
844 | |
1009 | |
… | |
… | |
858 | ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1023 | ev_once (int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
859 | { |
1024 | { |
860 | struct ev_once *once = malloc (sizeof (struct ev_once)); |
1025 | struct ev_once *once = malloc (sizeof (struct ev_once)); |
861 | |
1026 | |
862 | if (!once) |
1027 | if (!once) |
863 | cb (EV_ERROR, arg); |
1028 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
864 | else |
1029 | else |
865 | { |
1030 | { |
866 | once->cb = cb; |
1031 | once->cb = cb; |
867 | once->arg = arg; |
1032 | once->arg = arg; |
868 | |
1033 | |
869 | evw_init (&once->io, once_cb_io); |
1034 | ev_watcher_init (&once->io, once_cb_io); |
870 | |
|
|
871 | if (fd >= 0) |
1035 | if (fd >= 0) |
872 | { |
1036 | { |
873 | evio_set (&once->io, fd, events); |
1037 | ev_io_set (&once->io, fd, events); |
874 | evio_start (&once->io); |
1038 | ev_io_start (&once->io); |
875 | } |
1039 | } |
876 | |
1040 | |
877 | evw_init (&once->to, once_cb_to); |
1041 | ev_watcher_init (&once->to, once_cb_to); |
878 | |
|
|
879 | if (timeout >= 0.) |
1042 | if (timeout >= 0.) |
880 | { |
1043 | { |
881 | evtimer_set (&once->to, timeout, 0.); |
1044 | ev_timer_set (&once->to, timeout, 0.); |
882 | evtimer_start (&once->to); |
1045 | ev_timer_start (&once->to); |
883 | } |
1046 | } |
884 | } |
1047 | } |
885 | } |
1048 | } |
886 | |
1049 | |
887 | /*****************************************************************************/ |
1050 | /*****************************************************************************/ |
… | |
… | |
898 | |
1061 | |
899 | static void |
1062 | static void |
900 | ocb (struct ev_timer *w, int revents) |
1063 | ocb (struct ev_timer *w, int revents) |
901 | { |
1064 | { |
902 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
1065 | //fprintf (stderr, "timer %f,%f (%x) (%f) d%p\n", w->at, w->repeat, revents, w->at - ev_time (), w->data); |
903 | evtimer_stop (w); |
1066 | ev_timer_stop (w); |
904 | evtimer_start (w); |
1067 | ev_timer_start (w); |
905 | } |
1068 | } |
906 | |
1069 | |
907 | static void |
1070 | static void |
908 | scb (struct ev_signal *w, int revents) |
1071 | scb (struct ev_signal *w, int revents) |
909 | { |
1072 | { |
910 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
1073 | fprintf (stderr, "signal %x,%d\n", revents, w->signum); |
911 | evio_stop (&wio); |
1074 | ev_io_stop (&wio); |
912 | evio_start (&wio); |
1075 | ev_io_start (&wio); |
913 | } |
1076 | } |
914 | |
1077 | |
915 | static void |
1078 | static void |
916 | gcb (struct ev_signal *w, int revents) |
1079 | gcb (struct ev_signal *w, int revents) |
917 | { |
1080 | { |
… | |
… | |
921 | |
1084 | |
922 | int main (void) |
1085 | int main (void) |
923 | { |
1086 | { |
924 | ev_init (0); |
1087 | ev_init (0); |
925 | |
1088 | |
926 | evio_init (&wio, sin_cb, 0, EV_READ); |
1089 | ev_io_init (&wio, sin_cb, 0, EV_READ); |
927 | evio_start (&wio); |
1090 | ev_io_start (&wio); |
928 | |
1091 | |
929 | struct ev_timer t[10000]; |
1092 | struct ev_timer t[10000]; |
930 | |
1093 | |
931 | #if 0 |
1094 | #if 0 |
932 | int i; |
1095 | int i; |
933 | for (i = 0; i < 10000; ++i) |
1096 | for (i = 0; i < 10000; ++i) |
934 | { |
1097 | { |
935 | struct ev_timer *w = t + i; |
1098 | struct ev_timer *w = t + i; |
936 | evw_init (w, ocb, i); |
1099 | ev_watcher_init (w, ocb, i); |
937 | evtimer_init_abs (w, ocb, drand48 (), 0.99775533); |
1100 | ev_timer_init_abs (w, ocb, drand48 (), 0.99775533); |
938 | evtimer_start (w); |
1101 | ev_timer_start (w); |
939 | if (drand48 () < 0.5) |
1102 | if (drand48 () < 0.5) |
940 | evtimer_stop (w); |
1103 | ev_timer_stop (w); |
941 | } |
1104 | } |
942 | #endif |
1105 | #endif |
943 | |
1106 | |
944 | struct ev_timer t1; |
1107 | struct ev_timer t1; |
945 | evtimer_init (&t1, ocb, 5, 10); |
1108 | ev_timer_init (&t1, ocb, 5, 10); |
946 | evtimer_start (&t1); |
1109 | ev_timer_start (&t1); |
947 | |
1110 | |
948 | struct ev_signal sig; |
1111 | struct ev_signal sig; |
949 | evsignal_init (&sig, scb, SIGQUIT); |
1112 | ev_signal_init (&sig, scb, SIGQUIT); |
950 | evsignal_start (&sig); |
1113 | ev_signal_start (&sig); |
951 | |
1114 | |
952 | struct ev_check cw; |
1115 | struct ev_check cw; |
953 | evcheck_init (&cw, gcb); |
1116 | ev_check_init (&cw, gcb); |
954 | evcheck_start (&cw); |
1117 | ev_check_start (&cw); |
955 | |
1118 | |
956 | struct ev_idle iw; |
1119 | struct ev_idle iw; |
957 | evidle_init (&iw, gcb); |
1120 | ev_idle_init (&iw, gcb); |
958 | evidle_start (&iw); |
1121 | ev_idle_start (&iw); |
959 | |
1122 | |
960 | ev_loop (0); |
1123 | ev_loop (0); |
961 | |
1124 | |
962 | return 0; |
1125 | return 0; |
963 | } |
1126 | } |