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

Comparing libev/ev.c (file contents):
Revision 1.161 by root, Sat Dec 1 23:43:45 2007 UTC vs.
Revision 1.171 by root, Sun Dec 9 02:12:43 2007 UTC

222#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 222#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
223/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */ 223/*#define CLEANUP_INTERVAL (MAX_BLOCKTIME * 5.) /* how often to try to free memory and re-check fds */
224 224
225#if __GNUC__ >= 3 225#if __GNUC__ >= 3
226# define expect(expr,value) __builtin_expect ((expr),(value)) 226# define expect(expr,value) __builtin_expect ((expr),(value))
227# define inline_size static inline /* inline for codesize */
228# if EV_MINIMAL
229# define noinline __attribute__ ((noinline)) 227# define noinline __attribute__ ((noinline))
230# define inline_speed static noinline
231# else
232# define noinline
233# define inline_speed static inline
234# endif
235#else 228#else
236# define expect(expr,value) (expr) 229# define expect(expr,value) (expr)
237# define inline_speed static
238# define inline_size static
239# define noinline 230# define noinline
231# if __STDC_VERSION__ < 199901L
232# define inline
233# endif
240#endif 234#endif
241 235
242#define expect_false(expr) expect ((expr) != 0, 0) 236#define expect_false(expr) expect ((expr) != 0, 0)
243#define expect_true(expr) expect ((expr) != 0, 1) 237#define expect_true(expr) expect ((expr) != 0, 1)
238#define inline_size static inline
239
240#if EV_MINIMAL
241# define inline_speed static noinline
242#else
243# define inline_speed static inline
244#endif
244 245
245#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 246#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
246#define ABSPRI(w) ((w)->priority - EV_MINPRI) 247#define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
247 248
248#define EMPTY0 /* required for microsofts broken pseudo-c compiler */ 249#define EMPTY /* required for microsofts broken pseudo-c compiler */
249#define EMPTY2(a,b) /* used to suppress some warnings */ 250#define EMPTY2(a,b) /* used to suppress some warnings */
250 251
251typedef ev_watcher *W; 252typedef ev_watcher *W;
252typedef ev_watcher_list *WL; 253typedef ev_watcher_list *WL;
253typedef ev_watcher_time *WT; 254typedef ev_watcher_time *WT;
396{ 397{
397 return ev_rt_now; 398 return ev_rt_now;
398} 399}
399#endif 400#endif
400 401
401#define array_roundsize(type,n) (((n) | 4) & ~3) 402int inline_size
403array_nextsize (int elem, int cur, int cnt)
404{
405 int ncur = cur + 1;
406
407 do
408 ncur <<= 1;
409 while (cnt > ncur);
410
411 /* if size > 4096, round to 4096 - 4 * longs to accomodate malloc overhead */
412 if (elem * ncur > 4096)
413 {
414 ncur *= elem;
415 ncur = (ncur + elem + 4095 + sizeof (void *) * 4) & ~4095;
416 ncur = ncur - sizeof (void *) * 4;
417 ncur /= elem;
418 }
419
420 return ncur;
421}
422
423static noinline void *
424array_realloc (int elem, void *base, int *cur, int cnt)
425{
426 *cur = array_nextsize (elem, *cur, cnt);
427 return ev_realloc (base, elem * *cur);
428}
402 429
403#define array_needsize(type,base,cur,cnt,init) \ 430#define array_needsize(type,base,cur,cnt,init) \
404 if (expect_false ((cnt) > cur)) \ 431 if (expect_false ((cnt) > (cur))) \
405 { \ 432 { \
406 int newcnt = cur; \ 433 int ocur_ = (cur); \
407 do \ 434 (base) = (type *)array_realloc \
408 { \ 435 (sizeof (type), (base), &(cur), (cnt)); \
409 newcnt = array_roundsize (type, newcnt << 1); \ 436 init ((base) + (ocur_), (cur) - ocur_); \
410 } \
411 while ((cnt) > newcnt); \
412 \
413 base = (type *)ev_realloc (base, sizeof (type) * (newcnt));\
414 init (base + cur, newcnt - cur); \
415 cur = newcnt; \
416 } 437 }
417 438
439#if 0
418#define array_slim(type,stem) \ 440#define array_slim(type,stem) \
419 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 441 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
420 { \ 442 { \
421 stem ## max = array_roundsize (stem ## cnt >> 1); \ 443 stem ## max = array_roundsize (stem ## cnt >> 1); \
422 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\ 444 base = (type *)ev_realloc (base, sizeof (type) * (stem ## max));\
423 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\ 445 fprintf (stderr, "slimmed down " # stem " to %d\n", stem ## max);/*D*/\
424 } 446 }
447#endif
425 448
426#define array_free(stem, idx) \ 449#define array_free(stem, idx) \
427 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; 450 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0;
428 451
429/*****************************************************************************/ 452/*****************************************************************************/
430 453
431void noinline 454void noinline
432ev_feed_event (EV_P_ void *w, int revents) 455ev_feed_event (EV_P_ void *w, int revents)
433{ 456{
434 W w_ = (W)w; 457 W w_ = (W)w;
458 int pri = ABSPRI (w_);
435 459
436 if (expect_false (w_->pending)) 460 if (expect_false (w_->pending))
461 pendings [pri][w_->pending - 1].events |= revents;
462 else
437 { 463 {
464 w_->pending = ++pendingcnt [pri];
465 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2);
466 pendings [pri][w_->pending - 1].w = w_;
438 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 467 pendings [pri][w_->pending - 1].events = revents;
439 return;
440 } 468 }
441
442 w_->pending = ++pendingcnt [ABSPRI (w_)];
443 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
444 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
445 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
446} 469}
447 470
448void inline_size 471void inline_size
449queue_events (EV_P_ W *events, int eventcnt, int type) 472queue_events (EV_P_ W *events, int eventcnt, int type)
450{ 473{
485} 508}
486 509
487void 510void
488ev_feed_fd_event (EV_P_ int fd, int revents) 511ev_feed_fd_event (EV_P_ int fd, int revents)
489{ 512{
513 if (fd >= 0 && fd < anfdmax)
490 fd_event (EV_A_ fd, revents); 514 fd_event (EV_A_ fd, revents);
491} 515}
492 516
493void inline_size 517void inline_size
494fd_reify (EV_P) 518fd_reify (EV_P)
495{ 519{
725 for (signum = signalmax; signum--; ) 749 for (signum = signalmax; signum--; )
726 if (signals [signum].gotsig) 750 if (signals [signum].gotsig)
727 ev_feed_signal_event (EV_A_ signum + 1); 751 ev_feed_signal_event (EV_A_ signum + 1);
728} 752}
729 753
730void inline_size 754void inline_speed
731fd_intern (int fd) 755fd_intern (int fd)
732{ 756{
733#ifdef _WIN32 757#ifdef _WIN32
734 int arg = 1; 758 int arg = 1;
735 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 759 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
764 ev_child *w; 788 ev_child *w;
765 789
766 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next) 790 for (w = (ev_child *)childs [chain & (EV_PID_HASHSIZE - 1)]; w; w = (ev_child *)((WL)w)->next)
767 if (w->pid == pid || !w->pid) 791 if (w->pid == pid || !w->pid)
768 { 792 {
769 ev_priority (w) = ev_priority (sw); /* need to do it *now* */ 793 ev_set_priority (w, ev_priority (sw)); /* need to do it *now* */
770 w->rpid = pid; 794 w->rpid = pid;
771 w->rstatus = status; 795 w->rstatus = status;
772 ev_feed_event (EV_A_ (W)w, EV_CHILD); 796 ev_feed_event (EV_A_ (W)w, EV_CHILD);
773 } 797 }
774} 798}
775 799
776#ifndef WCONTINUED 800#ifndef WCONTINUED
886ev_backend (EV_P) 910ev_backend (EV_P)
887{ 911{
888 return backend; 912 return backend;
889} 913}
890 914
915unsigned int
916ev_loop_count (EV_P)
917{
918 return loop_count;
919}
920
891static void noinline 921static void noinline
892loop_init (EV_P_ unsigned int flags) 922loop_init (EV_P_ unsigned int flags)
893{ 923{
894 if (!backend) 924 if (!backend)
895 { 925 {
975#if EV_USE_SELECT 1005#if EV_USE_SELECT
976 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 1006 if (backend == EVBACKEND_SELECT) select_destroy (EV_A);
977#endif 1007#endif
978 1008
979 for (i = NUMPRI; i--; ) 1009 for (i = NUMPRI; i--; )
1010 {
980 array_free (pending, [i]); 1011 array_free (pending, [i]);
1012#if EV_IDLE_ENABLE
1013 array_free (idle, [i]);
1014#endif
1015 }
981 1016
982 /* have to use the microsoft-never-gets-it-right macro */ 1017 /* have to use the microsoft-never-gets-it-right macro */
983 array_free (fdchange, EMPTY0); 1018 array_free (fdchange, EMPTY);
984 array_free (timer, EMPTY0); 1019 array_free (timer, EMPTY);
985#if EV_PERIODIC_ENABLE 1020#if EV_PERIODIC_ENABLE
986 array_free (periodic, EMPTY0); 1021 array_free (periodic, EMPTY);
987#endif 1022#endif
988 array_free (idle, EMPTY0);
989 array_free (prepare, EMPTY0); 1023 array_free (prepare, EMPTY);
990 array_free (check, EMPTY0); 1024 array_free (check, EMPTY);
991 1025
992 backend = 0; 1026 backend = 0;
993} 1027}
994 1028
995void inline_size infy_fork (EV_P); 1029void inline_size infy_fork (EV_P);
1131 postfork = 1; 1165 postfork = 1;
1132} 1166}
1133 1167
1134/*****************************************************************************/ 1168/*****************************************************************************/
1135 1169
1136int inline_size 1170void
1137any_pending (EV_P) 1171ev_invoke (EV_P_ void *w, int revents)
1138{ 1172{
1139 int pri; 1173 EV_CB_INVOKE ((W)w, revents);
1140
1141 for (pri = NUMPRI; pri--; )
1142 if (pendingcnt [pri])
1143 return 1;
1144
1145 return 0;
1146} 1174}
1147 1175
1148void inline_speed 1176void inline_speed
1149call_pending (EV_P) 1177call_pending (EV_P)
1150{ 1178{
1242 for (i = periodiccnt >> 1; i--; ) 1270 for (i = periodiccnt >> 1; i--; )
1243 downheap ((WT *)periodics, periodiccnt, i); 1271 downheap ((WT *)periodics, periodiccnt, i);
1244} 1272}
1245#endif 1273#endif
1246 1274
1275#if EV_IDLE_ENABLE
1276void inline_size
1277idle_reify (EV_P)
1278{
1279 if (expect_false (idleall))
1280 {
1281 int pri;
1282
1283 for (pri = NUMPRI; pri--; )
1284 {
1285 if (pendingcnt [pri])
1286 break;
1287
1288 if (idlecnt [pri])
1289 {
1290 queue_events (EV_A_ (W *)idles [pri], idlecnt [pri], EV_IDLE);
1291 break;
1292 }
1293 }
1294 }
1295}
1296#endif
1297
1247int inline_size 1298int inline_size
1248time_update_monotonic (EV_P) 1299time_update_monotonic (EV_P)
1249{ 1300{
1250 mn_now = get_clock (); 1301 mn_now = get_clock ();
1251 1302
1363 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 1414 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1364 call_pending (EV_A); 1415 call_pending (EV_A);
1365 } 1416 }
1366#endif 1417#endif
1367 1418
1368 /* queue check watchers (and execute them) */ 1419 /* queue prepare watchers (and execute them) */
1369 if (expect_false (preparecnt)) 1420 if (expect_false (preparecnt))
1370 { 1421 {
1371 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1422 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1372 call_pending (EV_A); 1423 call_pending (EV_A);
1373 } 1424 }
1384 1435
1385 /* calculate blocking time */ 1436 /* calculate blocking time */
1386 { 1437 {
1387 ev_tstamp block; 1438 ev_tstamp block;
1388 1439
1389 if (expect_false (flags & EVLOOP_NONBLOCK || idlecnt || !activecnt)) 1440 if (expect_false (flags & EVLOOP_NONBLOCK || idleall || !activecnt))
1390 block = 0.; /* do not block at all */ 1441 block = 0.; /* do not block at all */
1391 else 1442 else
1392 { 1443 {
1393 /* update time to cancel out callback processing overhead */ 1444 /* update time to cancel out callback processing overhead */
1394#if EV_USE_MONOTONIC 1445#if EV_USE_MONOTONIC
1418#endif 1469#endif
1419 1470
1420 if (expect_false (block < 0.)) block = 0.; 1471 if (expect_false (block < 0.)) block = 0.;
1421 } 1472 }
1422 1473
1474 ++loop_count;
1423 backend_poll (EV_A_ block); 1475 backend_poll (EV_A_ block);
1424 } 1476 }
1425 1477
1426 /* update ev_rt_now, do magic */ 1478 /* update ev_rt_now, do magic */
1427 time_update (EV_A); 1479 time_update (EV_A);
1430 timers_reify (EV_A); /* relative timers called last */ 1482 timers_reify (EV_A); /* relative timers called last */
1431#if EV_PERIODIC_ENABLE 1483#if EV_PERIODIC_ENABLE
1432 periodics_reify (EV_A); /* absolute timers called first */ 1484 periodics_reify (EV_A); /* absolute timers called first */
1433#endif 1485#endif
1434 1486
1487#if EV_IDLE_ENABLE
1435 /* queue idle watchers unless other events are pending */ 1488 /* queue idle watchers unless other events are pending */
1436 if (idlecnt && !any_pending (EV_A)) 1489 idle_reify (EV_A);
1437 queue_events (EV_A_ (W *)idles, idlecnt, EV_IDLE); 1490#endif
1438 1491
1439 /* queue check watchers, to be executed first */ 1492 /* queue check watchers, to be executed first */
1440 if (expect_false (checkcnt)) 1493 if (expect_false (checkcnt))
1441 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 1494 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
1442 1495
1478 head = &(*head)->next; 1531 head = &(*head)->next;
1479 } 1532 }
1480} 1533}
1481 1534
1482void inline_speed 1535void inline_speed
1483ev_clear_pending (EV_P_ W w) 1536clear_pending (EV_P_ W w)
1484{ 1537{
1485 if (w->pending) 1538 if (w->pending)
1486 { 1539 {
1487 pendings [ABSPRI (w)][w->pending - 1].w = 0; 1540 pendings [ABSPRI (w)][w->pending - 1].w = 0;
1488 w->pending = 0; 1541 w->pending = 0;
1489 } 1542 }
1490} 1543}
1491 1544
1545int
1546ev_clear_pending (EV_P_ void *w)
1547{
1548 W w_ = (W)w;
1549 int pending = w_->pending;
1550
1551 if (!pending)
1552 return 0;
1553
1554 w_->pending = 0;
1555 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
1556 p->w = 0;
1557
1558 return p->events;
1559}
1560
1561void inline_size
1562pri_adjust (EV_P_ W w)
1563{
1564 int pri = w->priority;
1565 pri = pri < EV_MINPRI ? EV_MINPRI : pri;
1566 pri = pri > EV_MAXPRI ? EV_MAXPRI : pri;
1567 w->priority = pri;
1568}
1569
1492void inline_speed 1570void inline_speed
1493ev_start (EV_P_ W w, int active) 1571ev_start (EV_P_ W w, int active)
1494{ 1572{
1495 if (w->priority < EV_MINPRI) w->priority = EV_MINPRI; 1573 pri_adjust (EV_A_ w);
1496 if (w->priority > EV_MAXPRI) w->priority = EV_MAXPRI;
1497
1498 w->active = active; 1574 w->active = active;
1499 ev_ref (EV_A); 1575 ev_ref (EV_A);
1500} 1576}
1501 1577
1502void inline_size 1578void inline_size
1506 w->active = 0; 1582 w->active = 0;
1507} 1583}
1508 1584
1509/*****************************************************************************/ 1585/*****************************************************************************/
1510 1586
1511void 1587void noinline
1512ev_io_start (EV_P_ ev_io *w) 1588ev_io_start (EV_P_ ev_io *w)
1513{ 1589{
1514 int fd = w->fd; 1590 int fd = w->fd;
1515 1591
1516 if (expect_false (ev_is_active (w))) 1592 if (expect_false (ev_is_active (w)))
1523 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1599 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1524 1600
1525 fd_change (EV_A_ fd); 1601 fd_change (EV_A_ fd);
1526} 1602}
1527 1603
1528void 1604void noinline
1529ev_io_stop (EV_P_ ev_io *w) 1605ev_io_stop (EV_P_ ev_io *w)
1530{ 1606{
1531 ev_clear_pending (EV_A_ (W)w); 1607 clear_pending (EV_A_ (W)w);
1532 if (expect_false (!ev_is_active (w))) 1608 if (expect_false (!ev_is_active (w)))
1533 return; 1609 return;
1534 1610
1535 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 1611 assert (("ev_io_start called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
1536 1612
1538 ev_stop (EV_A_ (W)w); 1614 ev_stop (EV_A_ (W)w);
1539 1615
1540 fd_change (EV_A_ w->fd); 1616 fd_change (EV_A_ w->fd);
1541} 1617}
1542 1618
1543void 1619void noinline
1544ev_timer_start (EV_P_ ev_timer *w) 1620ev_timer_start (EV_P_ ev_timer *w)
1545{ 1621{
1546 if (expect_false (ev_is_active (w))) 1622 if (expect_false (ev_is_active (w)))
1547 return; 1623 return;
1548 1624
1556 upheap ((WT *)timers, timercnt - 1); 1632 upheap ((WT *)timers, timercnt - 1);
1557 1633
1558 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1634 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/
1559} 1635}
1560 1636
1561void 1637void noinline
1562ev_timer_stop (EV_P_ ev_timer *w) 1638ev_timer_stop (EV_P_ ev_timer *w)
1563{ 1639{
1564 ev_clear_pending (EV_A_ (W)w); 1640 clear_pending (EV_A_ (W)w);
1565 if (expect_false (!ev_is_active (w))) 1641 if (expect_false (!ev_is_active (w)))
1566 return; 1642 return;
1567 1643
1568 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w)); 1644 assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));
1569 1645
1580 ((WT)w)->at -= mn_now; 1656 ((WT)w)->at -= mn_now;
1581 1657
1582 ev_stop (EV_A_ (W)w); 1658 ev_stop (EV_A_ (W)w);
1583} 1659}
1584 1660
1585void 1661void noinline
1586ev_timer_again (EV_P_ ev_timer *w) 1662ev_timer_again (EV_P_ ev_timer *w)
1587{ 1663{
1588 if (ev_is_active (w)) 1664 if (ev_is_active (w))
1589 { 1665 {
1590 if (w->repeat) 1666 if (w->repeat)
1601 ev_timer_start (EV_A_ w); 1677 ev_timer_start (EV_A_ w);
1602 } 1678 }
1603} 1679}
1604 1680
1605#if EV_PERIODIC_ENABLE 1681#if EV_PERIODIC_ENABLE
1606void 1682void noinline
1607ev_periodic_start (EV_P_ ev_periodic *w) 1683ev_periodic_start (EV_P_ ev_periodic *w)
1608{ 1684{
1609 if (expect_false (ev_is_active (w))) 1685 if (expect_false (ev_is_active (w)))
1610 return; 1686 return;
1611 1687
1624 upheap ((WT *)periodics, periodiccnt - 1); 1700 upheap ((WT *)periodics, periodiccnt - 1);
1625 1701
1626 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1702 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/
1627} 1703}
1628 1704
1629void 1705void noinline
1630ev_periodic_stop (EV_P_ ev_periodic *w) 1706ev_periodic_stop (EV_P_ ev_periodic *w)
1631{ 1707{
1632 ev_clear_pending (EV_A_ (W)w); 1708 clear_pending (EV_A_ (W)w);
1633 if (expect_false (!ev_is_active (w))) 1709 if (expect_false (!ev_is_active (w)))
1634 return; 1710 return;
1635 1711
1636 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w)); 1712 assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));
1637 1713
1646 } 1722 }
1647 1723
1648 ev_stop (EV_A_ (W)w); 1724 ev_stop (EV_A_ (W)w);
1649} 1725}
1650 1726
1651void 1727void noinline
1652ev_periodic_again (EV_P_ ev_periodic *w) 1728ev_periodic_again (EV_P_ ev_periodic *w)
1653{ 1729{
1654 /* TODO: use adjustheap and recalculation */ 1730 /* TODO: use adjustheap and recalculation */
1655 ev_periodic_stop (EV_A_ w); 1731 ev_periodic_stop (EV_A_ w);
1656 ev_periodic_start (EV_A_ w); 1732 ev_periodic_start (EV_A_ w);
1659 1735
1660#ifndef SA_RESTART 1736#ifndef SA_RESTART
1661# define SA_RESTART 0 1737# define SA_RESTART 0
1662#endif 1738#endif
1663 1739
1664void 1740void noinline
1665ev_signal_start (EV_P_ ev_signal *w) 1741ev_signal_start (EV_P_ ev_signal *w)
1666{ 1742{
1667#if EV_MULTIPLICITY 1743#if EV_MULTIPLICITY
1668 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1744 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1669#endif 1745#endif
1688 sigaction (w->signum, &sa, 0); 1764 sigaction (w->signum, &sa, 0);
1689#endif 1765#endif
1690 } 1766 }
1691} 1767}
1692 1768
1693void 1769void noinline
1694ev_signal_stop (EV_P_ ev_signal *w) 1770ev_signal_stop (EV_P_ ev_signal *w)
1695{ 1771{
1696 ev_clear_pending (EV_A_ (W)w); 1772 clear_pending (EV_A_ (W)w);
1697 if (expect_false (!ev_is_active (w))) 1773 if (expect_false (!ev_is_active (w)))
1698 return; 1774 return;
1699 1775
1700 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w); 1776 wlist_del ((WL *)&signals [w->signum - 1].head, (WL)w);
1701 ev_stop (EV_A_ (W)w); 1777 ev_stop (EV_A_ (W)w);
1718} 1794}
1719 1795
1720void 1796void
1721ev_child_stop (EV_P_ ev_child *w) 1797ev_child_stop (EV_P_ ev_child *w)
1722{ 1798{
1723 ev_clear_pending (EV_A_ (W)w); 1799 clear_pending (EV_A_ (W)w);
1724 if (expect_false (!ev_is_active (w))) 1800 if (expect_false (!ev_is_active (w)))
1725 return; 1801 return;
1726 1802
1727 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w); 1803 wlist_del ((WL *)&childs [w->pid & (EV_PID_HASHSIZE - 1)], (WL)w);
1728 ev_stop (EV_A_ (W)w); 1804 ev_stop (EV_A_ (W)w);
1964} 2040}
1965 2041
1966void 2042void
1967ev_stat_stop (EV_P_ ev_stat *w) 2043ev_stat_stop (EV_P_ ev_stat *w)
1968{ 2044{
1969 ev_clear_pending (EV_A_ (W)w); 2045 clear_pending (EV_A_ (W)w);
1970 if (expect_false (!ev_is_active (w))) 2046 if (expect_false (!ev_is_active (w)))
1971 return; 2047 return;
1972 2048
1973#if EV_USE_INOTIFY 2049#if EV_USE_INOTIFY
1974 infy_del (EV_A_ w); 2050 infy_del (EV_A_ w);
1977 2053
1978 ev_stop (EV_A_ (W)w); 2054 ev_stop (EV_A_ (W)w);
1979} 2055}
1980#endif 2056#endif
1981 2057
2058#if EV_IDLE_ENABLE
1982void 2059void
1983ev_idle_start (EV_P_ ev_idle *w) 2060ev_idle_start (EV_P_ ev_idle *w)
1984{ 2061{
1985 if (expect_false (ev_is_active (w))) 2062 if (expect_false (ev_is_active (w)))
1986 return; 2063 return;
1987 2064
2065 pri_adjust (EV_A_ (W)w);
2066
2067 {
2068 int active = ++idlecnt [ABSPRI (w)];
2069
2070 ++idleall;
1988 ev_start (EV_A_ (W)w, ++idlecnt); 2071 ev_start (EV_A_ (W)w, active);
2072
1989 array_needsize (ev_idle *, idles, idlemax, idlecnt, EMPTY2); 2073 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2);
1990 idles [idlecnt - 1] = w; 2074 idles [ABSPRI (w)][active - 1] = w;
2075 }
1991} 2076}
1992 2077
1993void 2078void
1994ev_idle_stop (EV_P_ ev_idle *w) 2079ev_idle_stop (EV_P_ ev_idle *w)
1995{ 2080{
1996 ev_clear_pending (EV_A_ (W)w); 2081 clear_pending (EV_A_ (W)w);
1997 if (expect_false (!ev_is_active (w))) 2082 if (expect_false (!ev_is_active (w)))
1998 return; 2083 return;
1999 2084
2000 { 2085 {
2001 int active = ((W)w)->active; 2086 int active = ((W)w)->active;
2002 idles [active - 1] = idles [--idlecnt]; 2087
2088 idles [ABSPRI (w)][active - 1] = idles [ABSPRI (w)][--idlecnt [ABSPRI (w)]];
2003 ((W)idles [active - 1])->active = active; 2089 ((W)idles [ABSPRI (w)][active - 1])->active = active;
2090
2091 ev_stop (EV_A_ (W)w);
2092 --idleall;
2004 } 2093 }
2005
2006 ev_stop (EV_A_ (W)w);
2007} 2094}
2095#endif
2008 2096
2009void 2097void
2010ev_prepare_start (EV_P_ ev_prepare *w) 2098ev_prepare_start (EV_P_ ev_prepare *w)
2011{ 2099{
2012 if (expect_false (ev_is_active (w))) 2100 if (expect_false (ev_is_active (w)))
2018} 2106}
2019 2107
2020void 2108void
2021ev_prepare_stop (EV_P_ ev_prepare *w) 2109ev_prepare_stop (EV_P_ ev_prepare *w)
2022{ 2110{
2023 ev_clear_pending (EV_A_ (W)w); 2111 clear_pending (EV_A_ (W)w);
2024 if (expect_false (!ev_is_active (w))) 2112 if (expect_false (!ev_is_active (w)))
2025 return; 2113 return;
2026 2114
2027 { 2115 {
2028 int active = ((W)w)->active; 2116 int active = ((W)w)->active;
2045} 2133}
2046 2134
2047void 2135void
2048ev_check_stop (EV_P_ ev_check *w) 2136ev_check_stop (EV_P_ ev_check *w)
2049{ 2137{
2050 ev_clear_pending (EV_A_ (W)w); 2138 clear_pending (EV_A_ (W)w);
2051 if (expect_false (!ev_is_active (w))) 2139 if (expect_false (!ev_is_active (w)))
2052 return; 2140 return;
2053 2141
2054 { 2142 {
2055 int active = ((W)w)->active; 2143 int active = ((W)w)->active;
2097} 2185}
2098 2186
2099void 2187void
2100ev_embed_stop (EV_P_ ev_embed *w) 2188ev_embed_stop (EV_P_ ev_embed *w)
2101{ 2189{
2102 ev_clear_pending (EV_A_ (W)w); 2190 clear_pending (EV_A_ (W)w);
2103 if (expect_false (!ev_is_active (w))) 2191 if (expect_false (!ev_is_active (w)))
2104 return; 2192 return;
2105 2193
2106 ev_io_stop (EV_A_ &w->io); 2194 ev_io_stop (EV_A_ &w->io);
2107 2195
2122} 2210}
2123 2211
2124void 2212void
2125ev_fork_stop (EV_P_ ev_fork *w) 2213ev_fork_stop (EV_P_ ev_fork *w)
2126{ 2214{
2127 ev_clear_pending (EV_A_ (W)w); 2215 clear_pending (EV_A_ (W)w);
2128 if (expect_false (!ev_is_active (w))) 2216 if (expect_false (!ev_is_active (w)))
2129 return; 2217 return;
2130 2218
2131 { 2219 {
2132 int active = ((W)w)->active; 2220 int active = ((W)w)->active;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines