… | |
… | |
41 | # define EV_USE_MONOTONIC 1 |
41 | # define EV_USE_MONOTONIC 1 |
42 | # endif |
42 | # endif |
43 | # ifndef EV_USE_REALTIME |
43 | # ifndef EV_USE_REALTIME |
44 | # define EV_USE_REALTIME 1 |
44 | # define EV_USE_REALTIME 1 |
45 | # endif |
45 | # endif |
|
|
46 | # else |
|
|
47 | # ifndef EV_USE_MONOTONIC |
|
|
48 | # define EV_USE_MONOTONIC 0 |
|
|
49 | # endif |
|
|
50 | # ifndef EV_USE_REALTIME |
|
|
51 | # define EV_USE_REALTIME 0 |
|
|
52 | # endif |
46 | # endif |
53 | # endif |
47 | |
54 | |
48 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
55 | # if HAVE_SELECT && HAVE_SYS_SELECT_H && !defined (EV_USE_SELECT) |
49 | # define EV_USE_SELECT 1 |
56 | # define EV_USE_SELECT 1 |
|
|
57 | # else |
|
|
58 | # define EV_USE_SELECT 0 |
50 | # endif |
59 | # endif |
51 | |
60 | |
52 | # if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) |
61 | # if HAVE_POLL && HAVE_POLL_H && !defined (EV_USE_POLL) |
53 | # define EV_USE_POLL 1 |
62 | # define EV_USE_POLL 1 |
|
|
63 | # else |
|
|
64 | # define EV_USE_POLL 0 |
54 | # endif |
65 | # endif |
55 | |
66 | |
56 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) |
67 | # if HAVE_EPOLL_CTL && HAVE_SYS_EPOLL_H && !defined (EV_USE_EPOLL) |
57 | # define EV_USE_EPOLL 1 |
68 | # define EV_USE_EPOLL 1 |
|
|
69 | # else |
|
|
70 | # define EV_USE_EPOLL 0 |
58 | # endif |
71 | # endif |
59 | |
72 | |
60 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
73 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H && HAVE_SYS_QUEUE_H && !defined (EV_USE_KQUEUE) |
61 | # define EV_USE_KQUEUE 1 |
74 | # define EV_USE_KQUEUE 1 |
|
|
75 | # else |
|
|
76 | # define EV_USE_KQUEUE 0 |
62 | # endif |
77 | # endif |
63 | |
78 | |
64 | # if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) |
79 | # if HAVE_PORT_H && HAVE_PORT_CREATE && !defined (EV_USE_PORT) |
65 | # define EV_USE_PORT 1 |
80 | # define EV_USE_PORT 1 |
|
|
81 | # else |
|
|
82 | # define EV_USE_PORT 0 |
66 | # endif |
83 | # endif |
67 | |
84 | |
68 | #endif |
85 | #endif |
69 | |
86 | |
70 | #include <math.h> |
87 | #include <math.h> |
… | |
… | |
162 | # include "ev.h" |
179 | # include "ev.h" |
163 | #endif |
180 | #endif |
164 | |
181 | |
165 | #if __GNUC__ >= 3 |
182 | #if __GNUC__ >= 3 |
166 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
183 | # define expect(expr,value) __builtin_expect ((expr),(value)) |
167 | # define inline inline |
184 | # define inline static inline |
168 | #else |
185 | #else |
169 | # define expect(expr,value) (expr) |
186 | # define expect(expr,value) (expr) |
170 | # define inline static |
187 | # define inline static |
171 | #endif |
188 | #endif |
172 | |
189 | |
… | |
… | |
366 | void |
383 | void |
367 | ev_feed_event (EV_P_ void *w, int revents) |
384 | ev_feed_event (EV_P_ void *w, int revents) |
368 | { |
385 | { |
369 | W w_ = (W)w; |
386 | W w_ = (W)w; |
370 | |
387 | |
371 | if (w_->pending) |
388 | if (expect_false (w_->pending)) |
372 | { |
389 | { |
373 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
390 | pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; |
374 | return; |
391 | return; |
375 | } |
392 | } |
376 | |
393 | |
… | |
… | |
410 | fd_event (EV_A_ fd, revents); |
427 | fd_event (EV_A_ fd, revents); |
411 | } |
428 | } |
412 | |
429 | |
413 | /*****************************************************************************/ |
430 | /*****************************************************************************/ |
414 | |
431 | |
415 | static void |
432 | inline void |
416 | fd_reify (EV_P) |
433 | fd_reify (EV_P) |
417 | { |
434 | { |
418 | int i; |
435 | int i; |
419 | |
436 | |
420 | for (i = 0; i < fdchangecnt; ++i) |
437 | for (i = 0; i < fdchangecnt; ++i) |
… | |
… | |
447 | } |
464 | } |
448 | |
465 | |
449 | static void |
466 | static void |
450 | fd_change (EV_P_ int fd) |
467 | fd_change (EV_P_ int fd) |
451 | { |
468 | { |
452 | if (anfds [fd].reify) |
469 | if (expect_false (anfds [fd].reify)) |
453 | return; |
470 | return; |
454 | |
471 | |
455 | anfds [fd].reify = 1; |
472 | anfds [fd].reify = 1; |
456 | |
473 | |
457 | ++fdchangecnt; |
474 | ++fdchangecnt; |
… | |
… | |
469 | ev_io_stop (EV_A_ w); |
486 | ev_io_stop (EV_A_ w); |
470 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
487 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
471 | } |
488 | } |
472 | } |
489 | } |
473 | |
490 | |
474 | static int |
491 | inline int |
475 | fd_valid (int fd) |
492 | fd_valid (int fd) |
476 | { |
493 | { |
477 | #ifdef _WIN32 |
494 | #ifdef _WIN32 |
478 | return _get_osfhandle (fd) != -1; |
495 | return _get_osfhandle (fd) != -1; |
479 | #else |
496 | #else |
… | |
… | |
648 | for (signum = signalmax; signum--; ) |
665 | for (signum = signalmax; signum--; ) |
649 | if (signals [signum].gotsig) |
666 | if (signals [signum].gotsig) |
650 | ev_feed_signal_event (EV_A_ signum + 1); |
667 | ev_feed_signal_event (EV_A_ signum + 1); |
651 | } |
668 | } |
652 | |
669 | |
653 | inline void |
670 | static void |
654 | fd_intern (int fd) |
671 | fd_intern (int fd) |
655 | { |
672 | { |
656 | #ifdef _WIN32 |
673 | #ifdef _WIN32 |
657 | int arg = 1; |
674 | int arg = 1; |
658 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
675 | ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); |
… | |
… | |
809 | ev_init (&sigev, sigcb); |
826 | ev_init (&sigev, sigcb); |
810 | ev_set_priority (&sigev, EV_MAXPRI); |
827 | ev_set_priority (&sigev, EV_MAXPRI); |
811 | } |
828 | } |
812 | } |
829 | } |
813 | |
830 | |
814 | void |
831 | static void |
815 | loop_destroy (EV_P) |
832 | loop_destroy (EV_P) |
816 | { |
833 | { |
817 | int i; |
834 | int i; |
818 | |
835 | |
819 | #if EV_USE_PORT |
836 | #if EV_USE_PORT |
… | |
… | |
910 | |
927 | |
911 | #endif |
928 | #endif |
912 | |
929 | |
913 | #if EV_MULTIPLICITY |
930 | #if EV_MULTIPLICITY |
914 | struct ev_loop * |
931 | struct ev_loop * |
915 | ev_default_loop_ (unsigned int flags) |
932 | ev_default_loop_init (unsigned int flags) |
916 | #else |
933 | #else |
917 | int |
934 | int |
918 | ev_default_loop (unsigned int flags) |
935 | ev_default_loop (unsigned int flags) |
919 | #endif |
936 | #endif |
920 | { |
937 | { |
… | |
… | |
1012 | EV_CB_INVOKE (p->w, p->events); |
1029 | EV_CB_INVOKE (p->w, p->events); |
1013 | } |
1030 | } |
1014 | } |
1031 | } |
1015 | } |
1032 | } |
1016 | |
1033 | |
1017 | static void |
1034 | inline void |
1018 | timers_reify (EV_P) |
1035 | timers_reify (EV_P) |
1019 | { |
1036 | { |
1020 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1037 | while (timercnt && ((WT)timers [0])->at <= mn_now) |
1021 | { |
1038 | { |
1022 | struct ev_timer *w = timers [0]; |
1039 | struct ev_timer *w = timers [0]; |
… | |
… | |
1040 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1057 | ev_feed_event (EV_A_ (W)w, EV_TIMEOUT); |
1041 | } |
1058 | } |
1042 | } |
1059 | } |
1043 | |
1060 | |
1044 | #if EV_PERIODICS |
1061 | #if EV_PERIODICS |
1045 | static void |
1062 | inline void |
1046 | periodics_reify (EV_P) |
1063 | periodics_reify (EV_P) |
1047 | { |
1064 | { |
1048 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1065 | while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) |
1049 | { |
1066 | { |
1050 | struct ev_periodic *w = periodics [0]; |
1067 | struct ev_periodic *w = periodics [0]; |
… | |
… | |
1109 | ev_rt_now = ev_time (); |
1126 | ev_rt_now = ev_time (); |
1110 | return 1; |
1127 | return 1; |
1111 | } |
1128 | } |
1112 | } |
1129 | } |
1113 | |
1130 | |
1114 | static void |
1131 | inline void |
1115 | time_update (EV_P) |
1132 | time_update (EV_P) |
1116 | { |
1133 | { |
1117 | int i; |
1134 | int i; |
1118 | |
1135 | |
1119 | #if EV_USE_MONOTONIC |
1136 | #if EV_USE_MONOTONIC |
… | |
… | |
1230 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1247 | ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + method_fudge; |
1231 | if (block > to) block = to; |
1248 | if (block > to) block = to; |
1232 | } |
1249 | } |
1233 | #endif |
1250 | #endif |
1234 | |
1251 | |
1235 | if (block < 0.) block = 0.; |
1252 | if (expect_false (block < 0.)) block = 0.; |
1236 | } |
1253 | } |
1237 | |
1254 | |
1238 | method_poll (EV_A_ block); |
1255 | method_poll (EV_A_ block); |
1239 | |
1256 | |
1240 | /* update ev_rt_now, do magic */ |
1257 | /* update ev_rt_now, do magic */ |
… | |
… | |
1249 | /* queue idle watchers unless io or timers are pending */ |
1266 | /* queue idle watchers unless io or timers are pending */ |
1250 | if (idlecnt && !any_pending (EV_A)) |
1267 | if (idlecnt && !any_pending (EV_A)) |
1251 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1268 | queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); |
1252 | |
1269 | |
1253 | /* queue check watchers, to be executed first */ |
1270 | /* queue check watchers, to be executed first */ |
1254 | if (checkcnt) |
1271 | if (expect_false (checkcnt)) |
1255 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1272 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
1256 | |
1273 | |
1257 | call_pending (EV_A); |
1274 | call_pending (EV_A); |
1258 | |
1275 | |
1259 | if (loop_done) |
1276 | if (expect_false (loop_done)) |
1260 | break; |
1277 | break; |
1261 | } |
1278 | } |
1262 | |
1279 | |
1263 | if (loop_done != 2) |
1280 | if (loop_done != 2) |
1264 | loop_done = 0; |
1281 | loop_done = 0; |
… | |
… | |
1326 | void |
1343 | void |
1327 | ev_io_start (EV_P_ struct ev_io *w) |
1344 | ev_io_start (EV_P_ struct ev_io *w) |
1328 | { |
1345 | { |
1329 | int fd = w->fd; |
1346 | int fd = w->fd; |
1330 | |
1347 | |
1331 | if (ev_is_active (w)) |
1348 | if (expect_false (ev_is_active (w))) |
1332 | return; |
1349 | return; |
1333 | |
1350 | |
1334 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1351 | assert (("ev_io_start called with negative fd", fd >= 0)); |
1335 | |
1352 | |
1336 | ev_start (EV_A_ (W)w, 1); |
1353 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
1342 | |
1359 | |
1343 | void |
1360 | void |
1344 | ev_io_stop (EV_P_ struct ev_io *w) |
1361 | ev_io_stop (EV_P_ struct ev_io *w) |
1345 | { |
1362 | { |
1346 | ev_clear_pending (EV_A_ (W)w); |
1363 | ev_clear_pending (EV_A_ (W)w); |
1347 | if (!ev_is_active (w)) |
1364 | if (expect_false (!ev_is_active (w))) |
1348 | return; |
1365 | return; |
1349 | |
1366 | |
1350 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1367 | assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
1351 | |
1368 | |
1352 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
1369 | wlist_del ((WL *)&anfds[w->fd].head, (WL)w); |
… | |
… | |
1356 | } |
1373 | } |
1357 | |
1374 | |
1358 | void |
1375 | void |
1359 | ev_timer_start (EV_P_ struct ev_timer *w) |
1376 | ev_timer_start (EV_P_ struct ev_timer *w) |
1360 | { |
1377 | { |
1361 | if (ev_is_active (w)) |
1378 | if (expect_false (ev_is_active (w))) |
1362 | return; |
1379 | return; |
1363 | |
1380 | |
1364 | ((WT)w)->at += mn_now; |
1381 | ((WT)w)->at += mn_now; |
1365 | |
1382 | |
1366 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
1383 | assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
… | |
… | |
1375 | |
1392 | |
1376 | void |
1393 | void |
1377 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1394 | ev_timer_stop (EV_P_ struct ev_timer *w) |
1378 | { |
1395 | { |
1379 | ev_clear_pending (EV_A_ (W)w); |
1396 | ev_clear_pending (EV_A_ (W)w); |
1380 | if (!ev_is_active (w)) |
1397 | if (expect_false (!ev_is_active (w))) |
1381 | return; |
1398 | return; |
1382 | |
1399 | |
1383 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1400 | assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); |
1384 | |
1401 | |
1385 | if (((W)w)->active < timercnt--) |
1402 | if (expect_true (((W)w)->active < timercnt--)) |
1386 | { |
1403 | { |
1387 | timers [((W)w)->active - 1] = timers [timercnt]; |
1404 | timers [((W)w)->active - 1] = timers [timercnt]; |
1388 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1405 | adjustheap ((WT *)timers, timercnt, ((W)w)->active - 1); |
1389 | } |
1406 | } |
1390 | |
1407 | |
… | |
… | |
1415 | |
1432 | |
1416 | #if EV_PERIODICS |
1433 | #if EV_PERIODICS |
1417 | void |
1434 | void |
1418 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1435 | ev_periodic_start (EV_P_ struct ev_periodic *w) |
1419 | { |
1436 | { |
1420 | if (ev_is_active (w)) |
1437 | if (expect_false (ev_is_active (w))) |
1421 | return; |
1438 | return; |
1422 | |
1439 | |
1423 | if (w->reschedule_cb) |
1440 | if (w->reschedule_cb) |
1424 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1441 | ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); |
1425 | else if (w->interval) |
1442 | else if (w->interval) |
… | |
… | |
1439 | |
1456 | |
1440 | void |
1457 | void |
1441 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1458 | ev_periodic_stop (EV_P_ struct ev_periodic *w) |
1442 | { |
1459 | { |
1443 | ev_clear_pending (EV_A_ (W)w); |
1460 | ev_clear_pending (EV_A_ (W)w); |
1444 | if (!ev_is_active (w)) |
1461 | if (expect_false (!ev_is_active (w))) |
1445 | return; |
1462 | return; |
1446 | |
1463 | |
1447 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1464 | assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); |
1448 | |
1465 | |
1449 | if (((W)w)->active < periodiccnt--) |
1466 | if (expect_true (((W)w)->active < periodiccnt--)) |
1450 | { |
1467 | { |
1451 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1468 | periodics [((W)w)->active - 1] = periodics [periodiccnt]; |
1452 | adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1469 | adjustheap ((WT *)periodics, periodiccnt, ((W)w)->active - 1); |
1453 | } |
1470 | } |
1454 | |
1471 | |
… | |
… | |
1465 | #endif |
1482 | #endif |
1466 | |
1483 | |
1467 | void |
1484 | void |
1468 | ev_idle_start (EV_P_ struct ev_idle *w) |
1485 | ev_idle_start (EV_P_ struct ev_idle *w) |
1469 | { |
1486 | { |
1470 | if (ev_is_active (w)) |
1487 | if (expect_false (ev_is_active (w))) |
1471 | return; |
1488 | return; |
1472 | |
1489 | |
1473 | ev_start (EV_A_ (W)w, ++idlecnt); |
1490 | ev_start (EV_A_ (W)w, ++idlecnt); |
1474 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1491 | array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); |
1475 | idles [idlecnt - 1] = w; |
1492 | idles [idlecnt - 1] = w; |
… | |
… | |
1477 | |
1494 | |
1478 | void |
1495 | void |
1479 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1496 | ev_idle_stop (EV_P_ struct ev_idle *w) |
1480 | { |
1497 | { |
1481 | ev_clear_pending (EV_A_ (W)w); |
1498 | ev_clear_pending (EV_A_ (W)w); |
1482 | if (!ev_is_active (w)) |
1499 | if (expect_false (!ev_is_active (w))) |
1483 | return; |
1500 | return; |
1484 | |
1501 | |
1485 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1502 | idles [((W)w)->active - 1] = idles [--idlecnt]; |
1486 | ev_stop (EV_A_ (W)w); |
1503 | ev_stop (EV_A_ (W)w); |
1487 | } |
1504 | } |
1488 | |
1505 | |
1489 | void |
1506 | void |
1490 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
1507 | ev_prepare_start (EV_P_ struct ev_prepare *w) |
1491 | { |
1508 | { |
1492 | if (ev_is_active (w)) |
1509 | if (expect_false (ev_is_active (w))) |
1493 | return; |
1510 | return; |
1494 | |
1511 | |
1495 | ev_start (EV_A_ (W)w, ++preparecnt); |
1512 | ev_start (EV_A_ (W)w, ++preparecnt); |
1496 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1513 | array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
1497 | prepares [preparecnt - 1] = w; |
1514 | prepares [preparecnt - 1] = w; |
… | |
… | |
1499 | |
1516 | |
1500 | void |
1517 | void |
1501 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1518 | ev_prepare_stop (EV_P_ struct ev_prepare *w) |
1502 | { |
1519 | { |
1503 | ev_clear_pending (EV_A_ (W)w); |
1520 | ev_clear_pending (EV_A_ (W)w); |
1504 | if (!ev_is_active (w)) |
1521 | if (expect_false (!ev_is_active (w))) |
1505 | return; |
1522 | return; |
1506 | |
1523 | |
1507 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1524 | prepares [((W)w)->active - 1] = prepares [--preparecnt]; |
1508 | ev_stop (EV_A_ (W)w); |
1525 | ev_stop (EV_A_ (W)w); |
1509 | } |
1526 | } |
1510 | |
1527 | |
1511 | void |
1528 | void |
1512 | ev_check_start (EV_P_ struct ev_check *w) |
1529 | ev_check_start (EV_P_ struct ev_check *w) |
1513 | { |
1530 | { |
1514 | if (ev_is_active (w)) |
1531 | if (expect_false (ev_is_active (w))) |
1515 | return; |
1532 | return; |
1516 | |
1533 | |
1517 | ev_start (EV_A_ (W)w, ++checkcnt); |
1534 | ev_start (EV_A_ (W)w, ++checkcnt); |
1518 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1535 | array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); |
1519 | checks [checkcnt - 1] = w; |
1536 | checks [checkcnt - 1] = w; |
… | |
… | |
1521 | |
1538 | |
1522 | void |
1539 | void |
1523 | ev_check_stop (EV_P_ struct ev_check *w) |
1540 | ev_check_stop (EV_P_ struct ev_check *w) |
1524 | { |
1541 | { |
1525 | ev_clear_pending (EV_A_ (W)w); |
1542 | ev_clear_pending (EV_A_ (W)w); |
1526 | if (!ev_is_active (w)) |
1543 | if (expect_false (!ev_is_active (w))) |
1527 | return; |
1544 | return; |
1528 | |
1545 | |
1529 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1546 | checks [((W)w)->active - 1] = checks [--checkcnt]; |
1530 | ev_stop (EV_A_ (W)w); |
1547 | ev_stop (EV_A_ (W)w); |
1531 | } |
1548 | } |
… | |
… | |
1538 | ev_signal_start (EV_P_ struct ev_signal *w) |
1555 | ev_signal_start (EV_P_ struct ev_signal *w) |
1539 | { |
1556 | { |
1540 | #if EV_MULTIPLICITY |
1557 | #if EV_MULTIPLICITY |
1541 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1558 | assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1542 | #endif |
1559 | #endif |
1543 | if (ev_is_active (w)) |
1560 | if (expect_false (ev_is_active (w))) |
1544 | return; |
1561 | return; |
1545 | |
1562 | |
1546 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1563 | assert (("ev_signal_start called with illegal signal number", w->signum > 0)); |
1547 | |
1564 | |
1548 | ev_start (EV_A_ (W)w, 1); |
1565 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
1565 | |
1582 | |
1566 | void |
1583 | void |
1567 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1584 | ev_signal_stop (EV_P_ struct ev_signal *w) |
1568 | { |
1585 | { |
1569 | ev_clear_pending (EV_A_ (W)w); |
1586 | ev_clear_pending (EV_A_ (W)w); |
1570 | if (!ev_is_active (w)) |
1587 | if (expect_false (!ev_is_active (w))) |
1571 | return; |
1588 | return; |
1572 | |
1589 | |
1573 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1590 | wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); |
1574 | ev_stop (EV_A_ (W)w); |
1591 | ev_stop (EV_A_ (W)w); |
1575 | |
1592 | |
… | |
… | |
1581 | ev_child_start (EV_P_ struct ev_child *w) |
1598 | ev_child_start (EV_P_ struct ev_child *w) |
1582 | { |
1599 | { |
1583 | #if EV_MULTIPLICITY |
1600 | #if EV_MULTIPLICITY |
1584 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1601 | assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
1585 | #endif |
1602 | #endif |
1586 | if (ev_is_active (w)) |
1603 | if (expect_false (ev_is_active (w))) |
1587 | return; |
1604 | return; |
1588 | |
1605 | |
1589 | ev_start (EV_A_ (W)w, 1); |
1606 | ev_start (EV_A_ (W)w, 1); |
1590 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1607 | wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1591 | } |
1608 | } |
1592 | |
1609 | |
1593 | void |
1610 | void |
1594 | ev_child_stop (EV_P_ struct ev_child *w) |
1611 | ev_child_stop (EV_P_ struct ev_child *w) |
1595 | { |
1612 | { |
1596 | ev_clear_pending (EV_A_ (W)w); |
1613 | ev_clear_pending (EV_A_ (W)w); |
1597 | if (!ev_is_active (w)) |
1614 | if (expect_false (!ev_is_active (w))) |
1598 | return; |
1615 | return; |
1599 | |
1616 | |
1600 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1617 | wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); |
1601 | ev_stop (EV_A_ (W)w); |
1618 | ev_stop (EV_A_ (W)w); |
1602 | } |
1619 | } |
… | |
… | |
1639 | void |
1656 | void |
1640 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1657 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
1641 | { |
1658 | { |
1642 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
1659 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
1643 | |
1660 | |
1644 | if (!once) |
1661 | if (expect_false (!once)) |
|
|
1662 | { |
1645 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1663 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMEOUT, arg); |
1646 | else |
1664 | return; |
1647 | { |
1665 | } |
|
|
1666 | |
1648 | once->cb = cb; |
1667 | once->cb = cb; |
1649 | once->arg = arg; |
1668 | once->arg = arg; |
1650 | |
1669 | |
1651 | ev_init (&once->io, once_cb_io); |
1670 | ev_init (&once->io, once_cb_io); |
1652 | if (fd >= 0) |
1671 | if (fd >= 0) |
1653 | { |
1672 | { |
1654 | ev_io_set (&once->io, fd, events); |
1673 | ev_io_set (&once->io, fd, events); |
1655 | ev_io_start (EV_A_ &once->io); |
1674 | ev_io_start (EV_A_ &once->io); |
1656 | } |
1675 | } |
1657 | |
1676 | |
1658 | ev_init (&once->to, once_cb_to); |
1677 | ev_init (&once->to, once_cb_to); |
1659 | if (timeout >= 0.) |
1678 | if (timeout >= 0.) |
1660 | { |
1679 | { |
1661 | ev_timer_set (&once->to, timeout, 0.); |
1680 | ev_timer_set (&once->to, timeout, 0.); |
1662 | ev_timer_start (EV_A_ &once->to); |
1681 | ev_timer_start (EV_A_ &once->to); |
1663 | } |
|
|
1664 | } |
1682 | } |
1665 | } |
1683 | } |
1666 | |
1684 | |
1667 | #ifdef __cplusplus |
1685 | #ifdef __cplusplus |
1668 | } |
1686 | } |