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

Comparing libev/ev.c (file contents):
Revision 1.134 by root, Fri Nov 23 19:13:33 2007 UTC vs.
Revision 1.136 by root, Sat Nov 24 07:14:26 2007 UTC

202#define ABSPRI(w) ((w)->priority - EV_MINPRI) 202#define ABSPRI(w) ((w)->priority - EV_MINPRI)
203 203
204#define EMPTY0 /* required for microsofts broken pseudo-c compiler */ 204#define EMPTY0 /* required for microsofts broken pseudo-c compiler */
205#define EMPTY2(a,b) /* used to suppress some warnings */ 205#define EMPTY2(a,b) /* used to suppress some warnings */
206 206
207typedef struct ev_watcher *W; 207typedef ev_watcher *W;
208typedef struct ev_watcher_list *WL; 208typedef ev_watcher_list *WL;
209typedef struct ev_watcher_time *WT; 209typedef ev_watcher_time *WT;
210 210
211static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */ 211static int have_monotonic; /* did clock_gettime (CLOCK_MONOTONIC) work? */
212 212
213#ifdef _WIN32 213#ifdef _WIN32
214# include "ev_win32.c" 214# include "ev_win32.c"
397 { 397 {
398 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 398 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents;
399 return; 399 return;
400 } 400 }
401 401
402 if (expect_false (!w_->cb))
403 return;
404
405 w_->pending = ++pendingcnt [ABSPRI (w_)]; 402 w_->pending = ++pendingcnt [ABSPRI (w_)];
406 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2); 403 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
407 pendings [ABSPRI (w_)][w_->pending - 1].w = w_; 404 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
408 pendings [ABSPRI (w_)][w_->pending - 1].events = revents; 405 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
409} 406}
419 416
420inline void 417inline void
421fd_event (EV_P_ int fd, int revents) 418fd_event (EV_P_ int fd, int revents)
422{ 419{
423 ANFD *anfd = anfds + fd; 420 ANFD *anfd = anfds + fd;
424 struct ev_io *w; 421 ev_io *w;
425 422
426 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)
427 { 424 {
428 int ev = w->events & revents; 425 int ev = w->events & revents;
429 426
430 if (ev) 427 if (ev)
431 ev_feed_event (EV_A_ (W)w, ev); 428 ev_feed_event (EV_A_ (W)w, ev);
447 444
448 for (i = 0; i < fdchangecnt; ++i) 445 for (i = 0; i < fdchangecnt; ++i)
449 { 446 {
450 int fd = fdchanges [i]; 447 int fd = fdchanges [i];
451 ANFD *anfd = anfds + fd; 448 ANFD *anfd = anfds + fd;
452 struct ev_io *w; 449 ev_io *w;
453 450
454 int events = 0; 451 int events = 0;
455 452
456 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)
457 events |= w->events; 454 events |= w->events;
458 455
459#if EV_SELECT_IS_WINSOCKET 456#if EV_SELECT_IS_WINSOCKET
460 if (events) 457 if (events)
461 { 458 {
488} 485}
489 486
490static void 487static void
491fd_kill (EV_P_ int fd) 488fd_kill (EV_P_ int fd)
492{ 489{
493 struct ev_io *w; 490 ev_io *w;
494 491
495 while ((w = (struct ev_io *)anfds [fd].head)) 492 while ((w = (ev_io *)anfds [fd].head))
496 { 493 {
497 ev_io_stop (EV_A_ w); 494 ev_io_stop (EV_A_ w);
498 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);
499 } 496 }
500} 497}
611static ANSIG *signals; 608static ANSIG *signals;
612static int signalmax; 609static int signalmax;
613 610
614static int sigpipe [2]; 611static int sigpipe [2];
615static sig_atomic_t volatile gotsig; 612static sig_atomic_t volatile gotsig;
616static struct ev_io sigev; 613static ev_io sigev;
617 614
618static void 615static void
619signals_init (ANSIG *base, int count) 616signals_init (ANSIG *base, int count)
620{ 617{
621 while (count--) 618 while (count--)
664 for (w = signals [signum].head; w; w = w->next) 661 for (w = signals [signum].head; w; w = w->next)
665 ev_feed_event (EV_A_ (W)w, EV_SIGNAL); 662 ev_feed_event (EV_A_ (W)w, EV_SIGNAL);
666} 663}
667 664
668static void 665static void
669sigcb (EV_P_ struct ev_io *iow, int revents) 666sigcb (EV_P_ ev_io *iow, int revents)
670{ 667{
671 int signum; 668 int signum;
672 669
673 read (sigpipe [0], &revents, 1); 670 read (sigpipe [0], &revents, 1);
674 gotsig = 0; 671 gotsig = 0;
701 ev_unref (EV_A); /* child watcher should not keep loop alive */ 698 ev_unref (EV_A); /* child watcher should not keep loop alive */
702} 699}
703 700
704/*****************************************************************************/ 701/*****************************************************************************/
705 702
706static struct ev_child *childs [PID_HASHSIZE]; 703static ev_child *childs [PID_HASHSIZE];
707 704
708#ifndef _WIN32 705#ifndef _WIN32
709 706
710static struct ev_signal childev; 707static ev_signal childev;
711 708
712#ifndef WCONTINUED 709#ifndef WCONTINUED
713# define WCONTINUED 0 710# define WCONTINUED 0
714#endif 711#endif
715 712
716static void 713static void
717child_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)
718{ 715{
719 struct ev_child *w; 716 ev_child *w;
720 717
721 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)
722 if (w->pid == pid || !w->pid) 719 if (w->pid == pid || !w->pid)
723 { 720 {
724 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 721 ev_priority (w) = ev_priority (sw); /* need to do it *now* */
725 w->rpid = pid; 722 w->rpid = pid;
726 w->rstatus = status; 723 w->rstatus = status;
727 ev_feed_event (EV_A_ (W)w, EV_CHILD); 724 ev_feed_event (EV_A_ (W)w, EV_CHILD);
728 } 725 }
729} 726}
730 727
731static void 728static void
732childcb (EV_P_ struct ev_signal *sw, int revents) 729childcb (EV_P_ ev_signal *sw, int revents)
733{ 730{
734 int pid, status; 731 int pid, status;
735 732
736 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED))) 733 if (0 < (pid = waitpid (-1, &status, WNOHANG | WUNTRACED | WCONTINUED)))
737 { 734 {
1088inline void 1085inline void
1089timers_reify (EV_P) 1086timers_reify (EV_P)
1090{ 1087{
1091 while (timercnt && ((WT)timers [0])->at <= mn_now) 1088 while (timercnt && ((WT)timers [0])->at <= mn_now)
1092 { 1089 {
1093 struct ev_timer *w = timers [0]; 1090 ev_timer *w = timers [0];
1094 1091
1095 assert (("inactive timer on timer heap detected", ev_is_active (w))); 1092 assert (("inactive timer on timer heap detected", ev_is_active (w)));
1096 1093
1097 /* first reschedule or stop timer */ 1094 /* first reschedule or stop timer */
1098 if (w->repeat) 1095 if (w->repeat)
1116inline void 1113inline void
1117periodics_reify (EV_P) 1114periodics_reify (EV_P)
1118{ 1115{
1119 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now) 1116 while (periodiccnt && ((WT)periodics [0])->at <= ev_rt_now)
1120 { 1117 {
1121 struct ev_periodic *w = periodics [0]; 1118 ev_periodic *w = periodics [0];
1122 1119
1123 assert (("inactive timer on periodic heap detected", ev_is_active (w))); 1120 assert (("inactive timer on periodic heap detected", ev_is_active (w)));
1124 1121
1125 /* first reschedule or stop timer */ 1122 /* first reschedule or stop timer */
1126 if (w->reschedule_cb) 1123 if (w->reschedule_cb)
1148 int i; 1145 int i;
1149 1146
1150 /* adjust periodics after time jump */ 1147 /* adjust periodics after time jump */
1151 for (i = 0; i < periodiccnt; ++i) 1148 for (i = 0; i < periodiccnt; ++i)
1152 { 1149 {
1153 struct ev_periodic *w = periodics [i]; 1150 ev_periodic *w = periodics [i];
1154 1151
1155 if (w->reschedule_cb) 1152 if (w->reschedule_cb)
1156 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1153 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1157 else if (w->interval) 1154 else if (w->interval)
1158 ((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;
1248static int loop_done; 1245static int loop_done;
1249 1246
1250void 1247void
1251ev_loop (EV_P_ int flags) 1248ev_loop (EV_P_ int flags)
1252{ 1249{
1253 double block;
1254 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK) ? 1 : 0; 1250 loop_done = flags & (EVLOOP_ONESHOT | EVLOOP_NONBLOCK)
1251 ? EVUNLOOP_ONE
1252 : EVUNLOOP_CANCEL;
1255 1253
1256 while (activecnt) 1254 while (activecnt)
1257 { 1255 {
1258 /* queue check watchers (and execute them) */ 1256 /* queue check watchers (and execute them) */
1259 if (expect_false (preparecnt)) 1257 if (expect_false (preparecnt))
1268 1266
1269 /* update fd-related kernel structures */ 1267 /* update fd-related kernel structures */
1270 fd_reify (EV_A); 1268 fd_reify (EV_A);
1271 1269
1272 /* calculate blocking time */ 1270 /* calculate blocking time */
1271 {
1272 double block;
1273 1273
1274 /* we only need this for !monotonic clock or timers, but as we basically 1274 if (flags & EVLOOP_NONBLOCK || idlecnt)
1275 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 */
1276#if EV_USE_MONOTONIC 1279#if EV_USE_MONOTONIC
1277 if (expect_true (have_monotonic)) 1280 if (expect_true (have_monotonic))
1278 time_update_monotonic (EV_A); 1281 time_update_monotonic (EV_A);
1279 else 1282 else
1280#endif 1283#endif
1281 { 1284 {
1282 ev_rt_now = ev_time (); 1285 ev_rt_now = ev_time ();
1283 mn_now = ev_rt_now; 1286 mn_now = ev_rt_now;
1284 } 1287 }
1285 1288
1286 if (flags & EVLOOP_NONBLOCK || idlecnt)
1287 block = 0.;
1288 else
1289 {
1290 block = MAX_BLOCKTIME; 1289 block = MAX_BLOCKTIME;
1291 1290
1292 if (timercnt) 1291 if (timercnt)
1293 { 1292 {
1294 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge; 1293 ev_tstamp to = ((WT)timers [0])->at - mn_now + backend_fudge;
1295 if (block > to) block = to; 1294 if (block > to) block = to;
1296 } 1295 }
1297 1296
1298#if EV_PERIODICS 1297#if EV_PERIODICS
1299 if (periodiccnt) 1298 if (periodiccnt)
1300 { 1299 {
1301 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;
1302 if (block > to) block = to; 1301 if (block > to) block = to;
1303 } 1302 }
1304#endif 1303#endif
1305 1304
1306 if (expect_false (block < 0.)) block = 0.; 1305 if (expect_false (block < 0.)) block = 0.;
1307 } 1306 }
1308 1307
1309 backend_poll (EV_A_ block); 1308 backend_poll (EV_A_ block);
1309 }
1310 1310
1311 /* update ev_rt_now, do magic */ 1311 /* update ev_rt_now, do magic */
1312 time_update (EV_A); 1312 time_update (EV_A);
1313 1313
1314 /* queue pending timers and reschedule them */ 1314 /* queue pending timers and reschedule them */
1329 1329
1330 if (expect_false (loop_done)) 1330 if (expect_false (loop_done))
1331 break; 1331 break;
1332 } 1332 }
1333 1333
1334 if (loop_done != 2) 1334 if (loop_done == EVUNLOOP_ONE)
1335 loop_done = 0; 1335 loop_done = EVUNLOOP_CANCEL;
1336} 1336}
1337 1337
1338void 1338void
1339ev_unloop (EV_P_ int how) 1339ev_unloop (EV_P_ int how)
1340{ 1340{
1393} 1393}
1394 1394
1395/*****************************************************************************/ 1395/*****************************************************************************/
1396 1396
1397void 1397void
1398ev_io_start (EV_P_ struct ev_io *w) 1398ev_io_start (EV_P_ ev_io *w)
1399{ 1399{
1400 int fd = w->fd; 1400 int fd = w->fd;
1401 1401
1402 if (expect_false (ev_is_active (w))) 1402 if (expect_false (ev_is_active (w)))
1403 return; 1403 return;
1410 1410
1411 fd_change (EV_A_ fd); 1411 fd_change (EV_A_ fd);
1412} 1412}
1413 1413
1414void 1414void
1415ev_io_stop (EV_P_ struct ev_io *w) 1415ev_io_stop (EV_P_ ev_io *w)
1416{ 1416{
1417 ev_clear_pending (EV_A_ (W)w); 1417 ev_clear_pending (EV_A_ (W)w);
1418 if (expect_false (!ev_is_active (w))) 1418 if (expect_false (!ev_is_active (w)))
1419 return; 1419 return;
1420 1420
1425 1425
1426 fd_change (EV_A_ w->fd); 1426 fd_change (EV_A_ w->fd);
1427} 1427}
1428 1428
1429void 1429void
1430ev_timer_start (EV_P_ struct ev_timer *w) 1430ev_timer_start (EV_P_ ev_timer *w)
1431{ 1431{
1432 if (expect_false (ev_is_active (w))) 1432 if (expect_false (ev_is_active (w)))
1433 return; 1433 return;
1434 1434
1435 ((WT)w)->at += mn_now; 1435 ((WT)w)->at += mn_now;
1436 1436
1437 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.));
1438 1438
1439 ev_start (EV_A_ (W)w, ++timercnt); 1439 ev_start (EV_A_ (W)w, ++timercnt);
1440 array_needsize (struct ev_timer *, timers, timermax, timercnt, EMPTY2); 1440 array_needsize (ev_timer *, timers, timermax, timercnt, EMPTY2);
1441 timers [timercnt - 1] = w; 1441 timers [timercnt - 1] = w;
1442 upheap ((WT *)timers, timercnt - 1); 1442 upheap ((WT *)timers, timercnt - 1);
1443 1443
1444 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1444 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1445} 1445}
1446 1446
1447void 1447void
1448ev_timer_stop (EV_P_ struct ev_timer *w) 1448ev_timer_stop (EV_P_ ev_timer *w)
1449{ 1449{
1450 ev_clear_pending (EV_A_ (W)w); 1450 ev_clear_pending (EV_A_ (W)w);
1451 if (expect_false (!ev_is_active (w))) 1451 if (expect_false (!ev_is_active (w)))
1452 return; 1452 return;
1453 1453
1463 1463
1464 ev_stop (EV_A_ (W)w); 1464 ev_stop (EV_A_ (W)w);
1465} 1465}
1466 1466
1467void 1467void
1468ev_timer_again (EV_P_ struct ev_timer *w) 1468ev_timer_again (EV_P_ ev_timer *w)
1469{ 1469{
1470 if (ev_is_active (w)) 1470 if (ev_is_active (w))
1471 { 1471 {
1472 if (w->repeat) 1472 if (w->repeat)
1473 { 1473 {
1484 } 1484 }
1485} 1485}
1486 1486
1487#if EV_PERIODICS 1487#if EV_PERIODICS
1488void 1488void
1489ev_periodic_start (EV_P_ struct ev_periodic *w) 1489ev_periodic_start (EV_P_ ev_periodic *w)
1490{ 1490{
1491 if (expect_false (ev_is_active (w))) 1491 if (expect_false (ev_is_active (w)))
1492 return; 1492 return;
1493 1493
1494 if (w->reschedule_cb) 1494 if (w->reschedule_cb)
1499 /* 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 */
1500 ((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;
1501 } 1501 }
1502 1502
1503 ev_start (EV_A_ (W)w, ++periodiccnt); 1503 ev_start (EV_A_ (W)w, ++periodiccnt);
1504 array_needsize (struct ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); 1504 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
1505 periodics [periodiccnt - 1] = w; 1505 periodics [periodiccnt - 1] = w;
1506 upheap ((WT *)periodics, periodiccnt - 1); 1506 upheap ((WT *)periodics, periodiccnt - 1);
1507 1507
1508 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1508 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1509} 1509}
1510 1510
1511void 1511void
1512ev_periodic_stop (EV_P_ struct ev_periodic *w) 1512ev_periodic_stop (EV_P_ ev_periodic *w)
1513{ 1513{
1514 ev_clear_pending (EV_A_ (W)w); 1514 ev_clear_pending (EV_A_ (W)w);
1515 if (expect_false (!ev_is_active (w))) 1515 if (expect_false (!ev_is_active (w)))
1516 return; 1516 return;
1517 1517
1525 1525
1526 ev_stop (EV_A_ (W)w); 1526 ev_stop (EV_A_ (W)w);
1527} 1527}
1528 1528
1529void 1529void
1530ev_periodic_again (EV_P_ struct ev_periodic *w) 1530ev_periodic_again (EV_P_ ev_periodic *w)
1531{ 1531{
1532 /* TODO: use adjustheap and recalculation */ 1532 /* TODO: use adjustheap and recalculation */
1533 ev_periodic_stop (EV_A_ w); 1533 ev_periodic_stop (EV_A_ w);
1534 ev_periodic_start (EV_A_ w); 1534 ev_periodic_start (EV_A_ w);
1535} 1535}
1536#endif 1536#endif
1537 1537
1538void 1538void
1539ev_idle_start (EV_P_ struct ev_idle *w) 1539ev_idle_start (EV_P_ ev_idle *w)
1540{ 1540{
1541 if (expect_false (ev_is_active (w))) 1541 if (expect_false (ev_is_active (w)))
1542 return; 1542 return;
1543 1543
1544 ev_start (EV_A_ (W)w, ++idlecnt); 1544 ev_start (EV_A_ (W)w, ++idlecnt);
1545 array_needsize (struct ev_idle *, idles, idlemax, idlecnt, EMPTY2); 1545 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2);
1546 idles [idlecnt - 1] = w; 1546 idles [idlecnt - 1] = w;
1547} 1547}
1548 1548
1549void 1549void
1550ev_idle_stop (EV_P_ struct ev_idle *w) 1550ev_idle_stop (EV_P_ ev_idle *w)
1551{ 1551{
1552 ev_clear_pending (EV_A_ (W)w); 1552 ev_clear_pending (EV_A_ (W)w);
1553 if (expect_false (!ev_is_active (w))) 1553 if (expect_false (!ev_is_active (w)))
1554 return; 1554 return;
1555 1555
1556 idles [((W)w)->active - 1] = idles [--idlecnt]; 1556 idles [((W)w)->active - 1] = idles [--idlecnt];
1557 ev_stop (EV_A_ (W)w); 1557 ev_stop (EV_A_ (W)w);
1558} 1558}
1559 1559
1560void 1560void
1561ev_prepare_start (EV_P_ struct ev_prepare *w) 1561ev_prepare_start (EV_P_ ev_prepare *w)
1562{ 1562{
1563 if (expect_false (ev_is_active (w))) 1563 if (expect_false (ev_is_active (w)))
1564 return; 1564 return;
1565 1565
1566 ev_start (EV_A_ (W)w, ++preparecnt); 1566 ev_start (EV_A_ (W)w, ++preparecnt);
1567 array_needsize (struct ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 1567 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2);
1568 prepares [preparecnt - 1] = w; 1568 prepares [preparecnt - 1] = w;
1569} 1569}
1570 1570
1571void 1571void
1572ev_prepare_stop (EV_P_ struct ev_prepare *w) 1572ev_prepare_stop (EV_P_ ev_prepare *w)
1573{ 1573{
1574 ev_clear_pending (EV_A_ (W)w); 1574 ev_clear_pending (EV_A_ (W)w);
1575 if (expect_false (!ev_is_active (w))) 1575 if (expect_false (!ev_is_active (w)))
1576 return; 1576 return;
1577 1577
1578 prepares [((W)w)->active - 1] = prepares [--preparecnt]; 1578 prepares [((W)w)->active - 1] = prepares [--preparecnt];
1579 ev_stop (EV_A_ (W)w); 1579 ev_stop (EV_A_ (W)w);
1580} 1580}
1581 1581
1582void 1582void
1583ev_check_start (EV_P_ struct ev_check *w) 1583ev_check_start (EV_P_ ev_check *w)
1584{ 1584{
1585 if (expect_false (ev_is_active (w))) 1585 if (expect_false (ev_is_active (w)))
1586 return; 1586 return;
1587 1587
1588 ev_start (EV_A_ (W)w, ++checkcnt); 1588 ev_start (EV_A_ (W)w, ++checkcnt);
1589 array_needsize (struct ev_check *, checks, checkmax, checkcnt, EMPTY2); 1589 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2);
1590 checks [checkcnt - 1] = w; 1590 checks [checkcnt - 1] = w;
1591} 1591}
1592 1592
1593void 1593void
1594ev_check_stop (EV_P_ struct ev_check *w) 1594ev_check_stop (EV_P_ ev_check *w)
1595{ 1595{
1596 ev_clear_pending (EV_A_ (W)w); 1596 ev_clear_pending (EV_A_ (W)w);
1597 if (expect_false (!ev_is_active (w))) 1597 if (expect_false (!ev_is_active (w)))
1598 return; 1598 return;
1599 1599
1604#ifndef SA_RESTART 1604#ifndef SA_RESTART
1605# define SA_RESTART 0 1605# define SA_RESTART 0
1606#endif 1606#endif
1607 1607
1608void 1608void
1609ev_signal_start (EV_P_ struct ev_signal *w) 1609ev_signal_start (EV_P_ ev_signal *w)
1610{ 1610{
1611#if EV_MULTIPLICITY 1611#if EV_MULTIPLICITY
1612 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));
1613#endif 1613#endif
1614 if (expect_false (ev_is_active (w))) 1614 if (expect_false (ev_is_active (w)))
1633#endif 1633#endif
1634 } 1634 }
1635} 1635}
1636 1636
1637void 1637void
1638ev_signal_stop (EV_P_ struct ev_signal *w) 1638ev_signal_stop (EV_P_ ev_signal *w)
1639{ 1639{
1640 ev_clear_pending (EV_A_ (W)w); 1640 ev_clear_pending (EV_A_ (W)w);
1641 if (expect_false (!ev_is_active (w))) 1641 if (expect_false (!ev_is_active (w)))
1642 return; 1642 return;
1643 1643
1647 if (!signals [w->signum - 1].head) 1647 if (!signals [w->signum - 1].head)
1648 signal (w->signum, SIG_DFL); 1648 signal (w->signum, SIG_DFL);
1649} 1649}
1650 1650
1651void 1651void
1652ev_child_start (EV_P_ struct ev_child *w) 1652ev_child_start (EV_P_ ev_child *w)
1653{ 1653{
1654#if EV_MULTIPLICITY 1654#if EV_MULTIPLICITY
1655 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));
1656#endif 1656#endif
1657 if (expect_false (ev_is_active (w))) 1657 if (expect_false (ev_is_active (w)))
1660 ev_start (EV_A_ (W)w, 1); 1660 ev_start (EV_A_ (W)w, 1);
1661 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1661 wlist_add ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1662} 1662}
1663 1663
1664void 1664void
1665ev_child_stop (EV_P_ struct ev_child *w) 1665ev_child_stop (EV_P_ ev_child *w)
1666{ 1666{
1667 ev_clear_pending (EV_A_ (W)w); 1667 ev_clear_pending (EV_A_ (W)w);
1668 if (expect_false (!ev_is_active (w))) 1668 if (expect_false (!ev_is_active (w)))
1669 return; 1669 return;
1670 1670
1671 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w); 1671 wlist_del ((WL *)&childs [w->pid & (PID_HASHSIZE - 1)], (WL)w);
1672 ev_stop (EV_A_ (W)w); 1672 ev_stop (EV_A_ (W)w);
1673} 1673}
1674 1674
1675#if EV_MULTIPLICITY 1675#if EV_MULTIPLICITY
1676static void 1676void
1677embed_cb (EV_P_ struct ev_io *io, int revents) 1677ev_embed_loop (EV_P_ ev_embed *w)
1678{ 1678{
1679 struct ev_embed *w = (struct ev_embed *)(((char *)io) - offsetof (struct ev_embed, io));
1680
1681 ev_feed_event (EV_A_ (W)w, EV_EMBED);
1682 ev_loop (w->loop, EVLOOP_NONBLOCK); 1679 ev_loop (w->loop, EVLOOP_NONBLOCK);
1683} 1680}
1684 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_loop (loop, w);
1691}
1692
1685void 1693void
1686ev_embed_start (EV_P_ struct ev_embed *w) 1694ev_embed_start (EV_P_ ev_embed *w)
1687{ 1695{
1688 if (expect_false (ev_is_active (w))) 1696 if (expect_false (ev_is_active (w)))
1689 return; 1697 return;
1690 1698
1691 { 1699 {
1692 struct ev_loop *loop = w->loop; 1700 struct ev_loop *loop = w->loop;
1693 assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); 1701 assert (("loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
1694 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ); 1702 ev_io_init (&w->io, embed_cb, backend_fd, EV_READ);
1695 } 1703 }
1696 1704
1705 ev_set_priority (&w->io, ev_priority (w));
1697 ev_io_start (EV_A_ &w->io); 1706 ev_io_start (EV_A_ &w->io);
1698 ev_start (EV_A_ (W)w, 1); 1707 ev_start (EV_A_ (W)w, 1);
1699} 1708}
1700 1709
1701void 1710void
1702ev_embed_stop (EV_P_ struct ev_embed *w) 1711ev_embed_stop (EV_P_ ev_embed *w)
1703{ 1712{
1704 ev_clear_pending (EV_A_ (W)w); 1713 ev_clear_pending (EV_A_ (W)w);
1705 if (expect_false (!ev_is_active (w))) 1714 if (expect_false (!ev_is_active (w)))
1706 return; 1715 return;
1707 1716
1712 1721
1713/*****************************************************************************/ 1722/*****************************************************************************/
1714 1723
1715struct ev_once 1724struct ev_once
1716{ 1725{
1717 struct ev_io io; 1726 ev_io io;
1718 struct ev_timer to; 1727 ev_timer to;
1719 void (*cb)(int revents, void *arg); 1728 void (*cb)(int revents, void *arg);
1720 void *arg; 1729 void *arg;
1721}; 1730};
1722 1731
1723static void 1732static void
1732 1741
1733 cb (revents, arg); 1742 cb (revents, arg);
1734} 1743}
1735 1744
1736static void 1745static void
1737once_cb_io (EV_P_ struct ev_io *w, int revents) 1746once_cb_io (EV_P_ ev_io *w, int revents)
1738{ 1747{
1739 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);
1740} 1749}
1741 1750
1742static void 1751static void
1743once_cb_to (EV_P_ struct ev_timer *w, int revents) 1752once_cb_to (EV_P_ ev_timer *w, int revents)
1744{ 1753{
1745 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);
1746} 1755}
1747 1756
1748void 1757void

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines