ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.132 by root, Fri Nov 23 10:36:30 2007 UTC vs.
Revision 1.138 by root, Sat Nov 24 09:48:38 2007 UTC

32#ifdef __cplusplus 32#ifdef __cplusplus
33extern "C" { 33extern "C" {
34#endif 34#endif
35 35
36#ifndef EV_STANDALONE 36#ifndef EV_STANDALONE
37# ifdef EV_CONFIG_H
38# include EV_CONFIG_H
39# else
37# include "config.h" 40# include "config.h"
41# endif
38 42
39# if HAVE_CLOCK_GETTIME 43# if HAVE_CLOCK_GETTIME
40# ifndef EV_USE_MONOTONIC 44# ifndef EV_USE_MONOTONIC
41# define EV_USE_MONOTONIC 1 45# define EV_USE_MONOTONIC 1
42# endif 46# endif
198#define ABSPRI(w) ((w)->priority - EV_MINPRI) 202#define ABSPRI(w) ((w)->priority - EV_MINPRI)
199 203
200#define EMPTY0 /* required for microsofts broken pseudo-c compiler */ 204#define EMPTY0 /* required for microsofts broken pseudo-c compiler */
201#define EMPTY2(a,b) /* used to suppress some warnings */ 205#define EMPTY2(a,b) /* used to suppress some warnings */
202 206
203typedef struct ev_watcher *W; 207typedef ev_watcher *W;
204typedef struct ev_watcher_list *WL; 208typedef ev_watcher_list *WL;
205typedef struct ev_watcher_time *WT; 209typedef ev_watcher_time *WT;
206 210
207static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 211static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
208 212
209#ifdef _WIN32 213#ifdef _WIN32
210# include "ev_win32.c" 214# include "ev_win32.c"
412 416
413inline void 417inline void
414fd_event (EV_P_ int fd, int revents) 418fd_event (EV_P_ int fd, int revents)
415{ 419{
416 ANFD *anfd = anfds + fd; 420 ANFD *anfd = anfds + fd;
417 struct ev_io *w; 421 ev_io *w;
418 422
419 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 423 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
420 { 424 {
421 int ev = w->events & revents; 425 int ev = w->events & revents;
422 426
423 if (ev) 427 if (ev)
424 ev_feed_event (EV_A_ (W)w, ev); 428 ev_feed_event (EV_A_ (W)w, ev);
440 444
441 for (i = 0; i < fdchangecnt; ++i) 445 for (i = 0; i < fdchangecnt; ++i)
442 { 446 {
443 int fd = fdchanges [i]; 447 int fd = fdchanges [i];
444 ANFD *anfd = anfds + fd; 448 ANFD *anfd = anfds + fd;
445 struct ev_io *w; 449 ev_io *w;
446 450
447 int events = 0; 451 int events = 0;
448 452
449 for (w = (struct ev_io *)anfd->head; w; w = (struct ev_io *)((WL)w)->next) 453 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
450 events |= w->events; 454 events |= w->events;
451 455
452#if EV_SELECT_IS_WINSOCKET 456#if EV_SELECT_IS_WINSOCKET
453 if (events) 457 if (events)
454 { 458 {
481} 485}
482 486
483static void 487static void
484fd_kill (EV_P_ int fd) 488fd_kill (EV_P_ int fd)
485{ 489{
486 struct ev_io *w; 490 ev_io *w;
487 491
488 while ((w = (struct ev_io *)anfds [fd].head)) 492 while ((w = (ev_io *)anfds [fd].head))
489 { 493 {
490 ev_io_stop (EV_A_ w); 494 ev_io_stop (EV_A_ w);
491 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 495 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
492 } 496 }
493} 497}
604static ANSIG *signals; 608static ANSIG *signals;
605static int signalmax; 609static int signalmax;
606 610
607static int sigpipe [2]; 611static int sigpipe [2];
608static sig_atomic_t volatile gotsig; 612static sig_atomic_t volatile gotsig;
609static struct ev_io sigev; 613static ev_io sigev;
610 614
611static void 615static void
612signals_init (ANSIG *base, int count) 616signals_init (ANSIG *base, int count)
613{ 617{
614 while (count--) 618 while (count--)
657 for (w = signals [signum].head; w; w = w->next) 661 for (w = signals [signum].head; w; w = w->next)
658 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 662 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
659} 663}
660 664
661static void 665static void
662sigcb (EV_P_ struct ev_io *iow, int revents) 666sigcb (EV_P_ ev_io *iow, int revents)
663{ 667{
664 int signum; 668 int signum;
665 669
666 read (sigpipe [0], &revents, 1); 670 read (sigpipe [0], &revents, 1);
667 gotsig = 0; 671 gotsig = 0;
694 ev_unref (EV_A); /* child watcher should not keep loop alive */ 698 ev_unref (EV_A); /* child watcher should not keep loop alive */
695} 699}
696 700
697/*****************************************************************************/ 701/*****************************************************************************/
698 702
699static struct ev_child *childs [PID_HASHSIZE]; 703static ev_child *childs [PID_HASHSIZE];
700 704
701#ifndef _WIN32 705#ifndef _WIN32
702 706
703static struct ev_signal childev; 707static ev_signal childev;
704 708
705#ifndef WCONTINUED 709#ifndef WCONTINUED
706# define WCONTINUED 0 710# define WCONTINUED 0
707#endif 711#endif
708 712
709static void 713static void
710child_reap (EV_P_ struct ev_signal *sw, int chain, int pid, int status) 714child_reap (EV_P_ ev_signal *sw, int chain, int pid, int status)
711{ 715{
712 struct ev_child *w; 716 ev_child *w;
713 717
714 for (w = (struct ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (struct ev_child *)((WL)w)->next) 718 for (w = (ev_child *)childs [chain & (PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
715 if (w->pid == pid || !w->pid) 719 if (w->pid == pid || !w->pid)
716 { 720 {
717 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 721 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
718 w->rpid = pid; 722 w->rpid = pid;
719 w->rstatus = status; 723 w->rstatus = status;
720 ev_feed_event (EV_A_ (W)w, EV_CHILD); 724 ev_feed_event (EV_A_ (W)w, EV_CHILD);
721 } 725 }
722} 726}
723 727
724static void 728static void
725childcb (EV_P_ struct ev_signal *sw, int revents) 729childcb (EV_P_ ev_signal *sw, int revents)
726{ 730{
727 int pid, status; 731 int pid, status;
728 732
729 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 733 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
730 { 734 {
812 816
813 return flags; 817 return flags;
814} 818}
815 819
816unsigned int 820unsigned int
821ev_embeddable_backends (void)
822{
823 return EVBACKEND_EPOLL
824 | EVBACKEND_KQUEUE
825 | EVBACKEND_PORT;
826}
827
828unsigned int
817ev_backend (EV_P) 829ev_backend (EV_P)
818{ 830{
819 return backend; 831 return backend;
820} 832}
821 833
1073inline void 1085inline void
1074timers_reify (EV_P) 1086timers_reify (EV_P)
1075{ 1087{
1076 while (timercnt && ((WT)timers [0])->at <= mn_now) 1088 while (timercnt && ((WT)timers [0])->at <= mn_now)
1077 { 1089 {
1078 struct ev_timer *w = timers [0]; 1090 ev_timer *w = timers [0];
1079 1091
1080 assert (("inactive timer on timer heap detected", ev_is_active (w))); 1092 assert (("inactive timer on timer heap detected", ev_is_active (w)));
1081 1093
1082 /* first reschedule or stop timer */ 1094 /* first reschedule or stop timer */
1083 if (w->repeat) 1095 if (w->repeat)
1101inline void 1113inline void
1102periodics_reify (EV_P) 1114periodics_reify (EV_P)
1103{ 1115{
1104 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1116 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1105 { 1117 {
1106 struct ev_periodic *w = periodics [0]; 1118 ev_periodic *w = periodics [0];
1107 1119
1108 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1120 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1109 1121
1110 /* first reschedule or stop timer */ 1122 /* first reschedule or stop timer */
1111 if (w->reschedule_cb) 1123 if (w->reschedule_cb)
1133 int i; 1145 int i;
1134 1146
1135 /* adjust periodics after time jump */ 1147 /* adjust periodics after time jump */
1136 for (i = 0; i < periodiccnt; ++i) 1148 for (i = 0; i < periodiccnt; ++i)
1137 { 1149 {
1138 struct ev_periodic *w = periodics [i]; 1150 ev_periodic *w = periodics [i];
1139 1151
1140 if (w->reschedule_cb) 1152 if (w->reschedule_cb)
1141 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1153 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1142 else if (w->interval) 1154 else if (w->interval)
1143 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; 1155 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
1233static int loop_done; 1245static int loop_done;
1234 1246
1235void 1247void
1236ev_loop (EV_P_ int flags) 1248ev_loop (EV_P_ int flags)
1237{ 1249{
1238 double block;
1239 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; 1250 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
1251 ? EVUNLOOP_ONE
1252 : EVUNLOOP_CANCEL;
1240 1253
1241 while (activecnt) 1254 while (activecnt)
1242 { 1255 {
1243 /* queue check watchers (and execute them) */ 1256 /* queue check watchers (and execute them) */
1244 if (expect_false (preparecnt)) 1257 if (expect_false (preparecnt))
1253 1266
1254 /* update fd-related kernel structures */ 1267 /* update fd-related kernel structures */
1255 fd_reify (EV_A); 1268 fd_reify (EV_A);
1256 1269
1257 /* calculate blocking time */ 1270 /* calculate blocking time */
1271 {
1272 double block;
1258 1273
1259 /* we only need this for !monotonic clock or timers, but as we basically 1274 if (flags & EVLOOP_NONBLOCK || idlecnt)
1260 always have timers, we just calculate it always */ 1275 block = 0.; /* do not block at all */
1276 else
1277 {
1278 /* update time to cancel out callback processing overhead */
1261#if EV_USE_MONOTONIC 1279#if EV_USE_MONOTONIC
1262 if (expect_true (have_monotonic)) 1280 if (expect_true (have_monotonic))
1263 time_update_monotonic (EV_A); 1281 time_update_monotonic (EV_A);
1264 else 1282 else
1265#endif 1283#endif
1266 { 1284 {
1267 ev_rt_now = ev_time (); 1285 ev_rt_now = ev_time ();
1268 mn_now = ev_rt_now; 1286 mn_now = ev_rt_now;
1269 } 1287 }
1270 1288
1271 if (flags & EVLOOP_NONBLOCK || idlecnt)
1272 block = 0.;
1273 else
1274 {
1275 block = MAX_BLOCKTIME; 1289 block = MAX_BLOCKTIME;
1276 1290
1277 if (timercnt) 1291 if (timercnt)
1278 { 1292 {
1279 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1293 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1280 if (block > to) block = to; 1294 if (block > to) block = to;
1281 } 1295 }
1282 1296
1283#if EV_PERIODICS 1297#if EV_PERIODICS
1284 if (periodiccnt) 1298 if (periodiccnt)
1285 { 1299 {
1286 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge; 1300 ev_tstamp to = ((WT)periodics [0])->at - ev_rt_now + backend_fudge;
1287 if (block > to) block = to; 1301 if (block > to) block = to;
1288 } 1302 }
1289#endif 1303#endif
1290 1304
1291 if (expect_false (block < 0.)) block = 0.; 1305 if (expect_false (block < 0.)) block = 0.;
1292 } 1306 }
1293 1307
1294 backend_poll (EV_A_ block); 1308 backend_poll (EV_A_ block);
1309 }
1295 1310
1296 /* update ev_rt_now, do magic */ 1311 /* update ev_rt_now, do magic */
1297 time_update (EV_A); 1312 time_update (EV_A);
1298 1313
1299 /* queue pending timers and reschedule them */ 1314 /* queue pending timers and reschedule them */
1300 timers_reify (EV_A); /* relative timers called last */ 1315 timers_reify (EV_A); /* relative timers called last */
1301#if EV_PERIODICS 1316#if EV_PERIODICS
1302 periodics_reify (EV_A); /* absolute timers called first */ 1317 periodics_reify (EV_A); /* absolute timers called first */
1303#endif 1318#endif
1304 1319
1305 /* queue idle watchers unless io or timers are pending */ 1320 /* queue idle watchers unless other events are pending */
1306 if (idlecnt && !any_pending (EV_A)) 1321 if (idlecnt && !any_pending (EV_A))
1307 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1322 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE);
1308 1323
1309 /* queue check watchers, to be executed first */ 1324 /* queue check watchers, to be executed first */
1310 if (expect_false (checkcnt)) 1325 if (expect_false (checkcnt))
1314 1329
1315 if (expect_false (loop_done)) 1330 if (expect_false (loop_done))
1316 break; 1331 break;
1317 } 1332 }
1318 1333
1319 if (loop_done != 2) 1334 if (loop_done == EVUNLOOP_ONE)
1320 loop_done = 0; 1335 loop_done = EVUNLOOP_CANCEL;
1321} 1336}
1322 1337
1323void 1338void
1324ev_unloop (EV_P_ int how) 1339ev_unloop (EV_P_ int how)
1325{ 1340{
1378} 1393}
1379 1394
1380/*****************************************************************************/ 1395/*****************************************************************************/
1381 1396
1382void 1397void
1383ev_io_start (EV_P_ struct ev_io *w) 1398ev_io_start (EV_P_ ev_io *w)
1384{ 1399{
1385 int fd = w->fd; 1400 int fd = w->fd;
1386 1401
1387 if (expect_false (ev_is_active (w))) 1402 if (expect_false (ev_is_active (w)))
1388 return; 1403 return;
1395 1410
1396 fd_change (EV_A_ fd); 1411 fd_change (EV_A_ fd);
1397} 1412}
1398 1413
1399void 1414void
1400ev_io_stop (EV_P_ struct ev_io *w) 1415ev_io_stop (EV_P_ ev_io *w)
1401{ 1416{
1402 ev_clear_pending (EV_A_ (W)w); 1417 ev_clear_pending (EV_A_ (W)w);
1403 if (expect_false (!ev_is_active (w))) 1418 if (expect_false (!ev_is_active (w)))
1404 return; 1419 return;
1405 1420
1410 1425
1411 fd_change (EV_A_ w->fd); 1426 fd_change (EV_A_ w->fd);
1412} 1427}
1413 1428
1414void 1429void
1415ev_timer_start (EV_P_ struct ev_timer *w) 1430ev_timer_start (EV_P_ ev_timer *w)
1416{ 1431{
1417 if (expect_false (ev_is_active (w))) 1432 if (expect_false (ev_is_active (w)))
1418 return; 1433 return;
1419 1434
1420 ((WT)w)->at += mn_now; 1435 ((WT)w)->at += mn_now;
1421 1436
1422 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 1437 assert (("ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
1423 1438
1424 ev_start (EV_A_ (W)w, ++timercnt); 1439 ev_start (EV_A_ (W)w, ++timercnt);
1425 array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); 1440 array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2);
1426 timers [timercnt - 1] = w; 1441 timers [timercnt - 1] = w;
1427 upheap ((WT *)timers, timercnt - 1); 1442 upheap ((WT *)timers, timercnt - 1);
1428 1443
1429 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1444 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1430} 1445}
1431 1446
1432void 1447void
1433ev_timer_stop (EV_P_ struct ev_timer *w) 1448ev_timer_stop (EV_P_ ev_timer *w)
1434{ 1449{
1435 ev_clear_pending (EV_A_ (W)w); 1450 ev_clear_pending (EV_A_ (W)w);
1436 if (expect_false (!ev_is_active (w))) 1451 if (expect_false (!ev_is_active (w)))
1437 return; 1452 return;
1438 1453
1448 1463
1449 ev_stop (EV_A_ (W)w); 1464 ev_stop (EV_A_ (W)w);
1450} 1465}
1451 1466
1452void 1467void
1453ev_timer_again (EV_P_ struct ev_timer *w) 1468ev_timer_again (EV_P_ ev_timer *w)
1454{ 1469{
1455 if (ev_is_active (w)) 1470 if (ev_is_active (w))
1456 { 1471 {
1457 if (w->repeat) 1472 if (w->repeat)
1458 { 1473 {
1469 } 1484 }
1470} 1485}
1471 1486
1472#if EV_PERIODICS 1487#if EV_PERIODICS
1473void 1488void
1474ev_periodic_start (EV_P_ struct ev_periodic *w) 1489ev_periodic_start (EV_P_ ev_periodic *w)
1475{ 1490{
1476 if (expect_false (ev_is_active (w))) 1491 if (expect_false (ev_is_active (w)))
1477 return; 1492 return;
1478 1493
1479 if (w->reschedule_cb) 1494 if (w->reschedule_cb)
1484 /* this formula differs from the one in periodic_reify because we do not always round up */ 1499 /* this formula differs from the one in periodic_reify because we do not always round up */
1485 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; 1500 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval;
1486 } 1501 }
1487 1502
1488 ev_start (EV_A_ (W)w, ++periodiccnt); 1503 ev_start (EV_A_ (W)w, ++periodiccnt);
1489 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); 1504 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
1490 periodics [periodiccnt - 1] = w; 1505 periodics [periodiccnt - 1] = w;
1491 upheap ((WT *)periodics, periodiccnt - 1); 1506 upheap ((WT *)periodics, periodiccnt - 1);
1492 1507
1493 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1508 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1494} 1509}
1495 1510
1496void 1511void
1497ev_periodic_stop (EV_P_ struct ev_periodic *w) 1512ev_periodic_stop (EV_P_ ev_periodic *w)
1498{ 1513{
1499 ev_clear_pending (EV_A_ (W)w); 1514 ev_clear_pending (EV_A_ (W)w);
1500 if (expect_false (!ev_is_active (w))) 1515 if (expect_false (!ev_is_active (w)))
1501 return; 1516 return;
1502 1517
1510 1525
1511 ev_stop (EV_A_ (W)w); 1526 ev_stop (EV_A_ (W)w);
1512} 1527}
1513 1528
1514void 1529void
1515ev_periodic_again (EV_P_ struct ev_periodic *w) 1530ev_periodic_again (EV_P_ ev_periodic *w)
1516{ 1531{
1517 /* TODO: use adjustheap and recalculation */ 1532 /* TODO: use adjustheap and recalculation */
1518 ev_periodic_stop (EV_A_ w); 1533 ev_periodic_stop (EV_A_ w);
1519 ev_periodic_start (EV_A_ w); 1534 ev_periodic_start (EV_A_ w);
1520} 1535}
1521#endif 1536#endif
1522 1537
1523void 1538void
1524ev_idle_start (EV_P_ struct ev_idle *w) 1539ev_idle_start (EV_P_ ev_idle *w)
1525{ 1540{
1526 if (expect_false (ev_is_active (w))) 1541 if (expect_false (ev_is_active (w)))
1527 return; 1542 return;
1528 1543
1529 ev_start (EV_A_ (W)w, ++idlecnt); 1544 ev_start (EV_A_ (W)w, ++idlecnt);
1530 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); 1545 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1531 idles [idlecnt - 1] = w; 1546 idles [idlecnt - 1] = w;
1532} 1547}
1533 1548
1534void 1549void
1535ev_idle_stop (EV_P_ struct ev_idle *w) 1550ev_idle_stop (EV_P_ ev_idle *w)
1536{ 1551{
1537 ev_clear_pending (EV_A_ (W)w); 1552 ev_clear_pending (EV_A_ (W)w);
1538 if (expect_false (!ev_is_active (w))) 1553 if (expect_false (!ev_is_active (w)))
1539 return; 1554 return;
1540 1555
1541 idles [((W)w)->active - 1] = idles [--idlecnt]; 1556 idles [((W)w)->active - 1] = idles [--idlecnt];
1542 ev_stop (EV_A_ (W)w); 1557 ev_stop (EV_A_ (W)w);
1543} 1558}
1544 1559
1545void 1560void
1546ev_prepare_start (EV_P_ struct ev_prepare *w) 1561ev_prepare_start (EV_P_ ev_prepare *w)
1547{ 1562{
1548 if (expect_false (ev_is_active (w))) 1563 if (expect_false (ev_is_active (w)))
1549 return; 1564 return;
1550 1565
1551 ev_start (EV_A_ (W)w, ++preparecnt); 1566 ev_start (EV_A_ (W)w, ++preparecnt);
1552 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 1567 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1553 prepares [preparecnt - 1] = w; 1568 prepares [preparecnt - 1] = w;
1554} 1569}
1555 1570
1556void 1571void
1557ev_prepare_stop (EV_P_ struct ev_prepare *w) 1572ev_prepare_stop (EV_P_ ev_prepare *w)
1558{ 1573{
1559 ev_clear_pending (EV_A_ (W)w); 1574 ev_clear_pending (EV_A_ (W)w);
1560 if (expect_false (!ev_is_active (w))) 1575 if (expect_false (!ev_is_active (w)))
1561 return; 1576 return;
1562 1577
1563 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1578 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1564 ev_stop (EV_A_ (W)w); 1579 ev_stop (EV_A_ (W)w);
1565} 1580}
1566 1581
1567void 1582void
1568ev_check_start (EV_P_ struct ev_check *w) 1583ev_check_start (EV_P_ ev_check *w)
1569{ 1584{
1570 if (expect_false (ev_is_active (w))) 1585 if (expect_false (ev_is_active (w)))
1571 return; 1586 return;
1572 1587
1573 ev_start (EV_A_ (W)w, ++checkcnt); 1588 ev_start (EV_A_ (W)w, ++checkcnt);
1574 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); 1589 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1575 checks [checkcnt - 1] = w; 1590 checks [checkcnt - 1] = w;
1576} 1591}
1577 1592
1578void 1593void
1579ev_check_stop (EV_P_ struct ev_check *w) 1594ev_check_stop (EV_P_ ev_check *w)
1580{ 1595{
1581 ev_clear_pending (EV_A_ (W)w); 1596 ev_clear_pending (EV_A_ (W)w);
1582 if (expect_false (!ev_is_active (w))) 1597 if (expect_false (!ev_is_active (w)))
1583 return; 1598 return;
1584 1599
1589#ifndef SA_RESTART 1604#ifndef SA_RESTART
1590# define SA_RESTART 0 1605# define SA_RESTART 0
1591#endif 1606#endif
1592 1607
1593void 1608void
1594ev_signal_start (EV_P_ struct ev_signal *w) 1609ev_signal_start (EV_P_ ev_signal *w)
1595{ 1610{
1596#if EV_MULTIPLICITY 1611#if EV_MULTIPLICITY
1597 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1612 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1598#endif 1613#endif
1599 if (expect_false (ev_is_active (w))) 1614 if (expect_false (ev_is_active (w)))
1618#endif 1633#endif
1619 } 1634 }
1620} 1635}
1621 1636
1622void 1637void
1623ev_signal_stop (EV_P_ struct ev_signal *w) 1638ev_signal_stop (EV_P_ ev_signal *w)
1624{ 1639{
1625 ev_clear_pending (EV_A_ (W)w); 1640 ev_clear_pending (EV_A_ (W)w);
1626 if (expect_false (!ev_is_active (w))) 1641 if (expect_false (!ev_is_active (w)))
1627 return; 1642 return;
1628 1643
1632 if (!signals [w->signum - 1].head) 1647 if (!signals [w->signum - 1].head)
1633 signal (w->signum, SIG_DFL); 1648 signal (w->signum, SIG_DFL);
1634} 1649}
1635 1650
1636void 1651void
1637ev_child_start (EV_P_ struct ev_child *w) 1652ev_child_start (EV_P_ ev_child *w)
1638{ 1653{
1639#if EV_MULTIPLICITY 1654#if EV_MULTIPLICITY
1640 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1655 assert (("child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1641#endif 1656#endif
1642 if (expect_false (ev_is_active (w))) 1657 if (expect_false (ev_is_active (w)))
1645 ev_start (EV_A_ (W)w, 1); 1660 ev_start (EV_A_ (W)w, 1);
1646 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1661 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1647} 1662}
1648 1663
1649void 1664void
1650ev_child_stop (EV_P_ struct ev_child *w) 1665ev_child_stop (EV_P_ ev_child *w)
1651{ 1666{
1652 ev_clear_pending (EV_A_ (W)w); 1667 ev_clear_pending (EV_A_ (W)w);
1653 if (expect_false (!ev_is_active (w))) 1668 if (expect_false (!ev_is_active (w)))
1654 return; 1669 return;
1655 1670
1656 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1671 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1657 ev_stop (EV_A_ (W)w); 1672 ev_stop (EV_A_ (W)w);
1658} 1673}
1659 1674
1675#if EV_MULTIPLICITY
1676void
1677ev_embed_sweep (EV_P_ ev_embed *w)
1678{
1679 ev_loop (w->loop, EVLOOP_NONBLOCK);
1680}
1681
1682static void
1683embed_cb (EV_P_ ev_io *io, int revents)
1684{
1685 ev_embed *w = (ev_embed *)(((char *)io) - offsetof (ev_embed, io));
1686
1687 if (ev_cb (w))
1688 ev_feed_event (EV_A_ (W)w, EV_EMBED);
1689 else
1690 ev_embed_sweep (loop, w);
1691}
1692
1693void
1694ev_embed_start (EV_P_ ev_embed *w)
1695{
1696 if (expect_false (ev_is_active (w)))
1697 return;
1698
1699 {
1700 struct ev_loop *loop = w->loop;
1701 assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
1702 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
1703 }
1704
1705 ev_set_priority (&w->io, ev_priority (w));
1706 ev_io_start (EV_A_ &w->io);
1707 ev_start (EV_A_ (W)w, 1);
1708}
1709
1710void
1711ev_embed_stop (EV_P_ ev_embed *w)
1712{
1713 ev_clear_pending (EV_A_ (W)w);
1714 if (expect_false (!ev_is_active (w)))
1715 return;
1716
1717 ev_io_stop (EV_A_ &w->io);
1718 ev_stop (EV_A_ (W)w);
1719}
1720#endif
1721
1660/*****************************************************************************/ 1722/*****************************************************************************/
1661 1723
1662struct ev_once 1724struct ev_once
1663{ 1725{
1664 struct ev_io io; 1726 ev_io io;
1665 struct ev_timer to; 1727 ev_timer to;
1666 void (*cb)(int revents, void *arg); 1728 void (*cb)(int revents, void *arg);
1667 void *arg; 1729 void *arg;
1668}; 1730};
1669 1731
1670static void 1732static void
1679 1741
1680 cb (revents, arg); 1742 cb (revents, arg);
1681} 1743}
1682 1744
1683static void 1745static void
1684once_cb_io (EV_P_ struct ev_io *w, int revents) 1746once_cb_io (EV_P_ ev_io *w, int revents)
1685{ 1747{
1686 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents); 1748 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, io)), revents);
1687} 1749}
1688 1750
1689static void 1751static void
1690once_cb_to (EV_P_ struct ev_timer *w, int revents) 1752once_cb_to (EV_P_ ev_timer *w, int revents)
1691{ 1753{
1692 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents); 1754 once_cb (EV_A_ (struct ev_once *)(((char *)w) - offsetof (struct ev_once, to)), revents);
1693} 1755}
1694 1756
1695void 1757void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines