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

Comparing libev/ev.c (file contents):
Revision 1.169 by root, Sat Dec 8 14:27:39 2007 UTC vs.
Revision 1.173 by root, Sun Dec 9 19:42:57 2007 UTC

418 } 418 }
419 419
420 return ncur; 420 return ncur;
421} 421}
422 422
423inline_speed void * 423static noinline void *
424array_realloc (int elem, void *base, int *cur, int cnt) 424array_realloc (int elem, void *base, int *cur, int cnt)
425{ 425{
426 *cur = array_nextsize (elem, *cur, cnt); 426 *cur = array_nextsize (elem, *cur, cnt);
427 return ev_realloc (base, elem * *cur); 427 return ev_realloc (base, elem * *cur);
428} 428}
453 453
454void noinline 454void noinline
455ev_feed_event (EV_P_ void *w, int revents) 455ev_feed_event (EV_P_ void *w, int revents)
456{ 456{
457 W w_ = (W)w; 457 W w_ = (W)w;
458 int pri = ABSPRI (w_);
458 459
459 if (expect_false (w_->pending)) 460 if (expect_false (w_->pending))
461 pendings [pri][w_->pending - 1].events |= revents;
462 else
460 { 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_;
461 pendings [ABSPRI (w_)][w_->pending - 1].events |= revents; 467 pendings [pri][w_->pending - 1].events = revents;
462 return;
463 } 468 }
464
465 w_->pending = ++pendingcnt [ABSPRI (w_)];
466 array_needsize (ANPENDING, pendings [ABSPRI (w_)], pendingmax [ABSPRI (w_)], pendingcnt [ABSPRI (w_)], EMPTY2);
467 pendings [ABSPRI (w_)][w_->pending - 1].w = w_;
468 pendings [ABSPRI (w_)][w_->pending - 1].events = revents;
469} 469}
470 470
471void inline_size 471void inline_size
472queue_events (EV_P_ W *events, int eventcnt, int type) 472queue_events (EV_P_ W *events, int eventcnt, int type)
473{ 473{
749 for (signum = signalmax; signum--; ) 749 for (signum = signalmax; signum--; )
750 if (signals [signum].gotsig) 750 if (signals [signum].gotsig)
751 ev_feed_signal_event (EV_A_ signum + 1); 751 ev_feed_signal_event (EV_A_ signum + 1);
752} 752}
753 753
754void inline_size 754void inline_speed
755fd_intern (int fd) 755fd_intern (int fd)
756{ 756{
757#ifdef _WIN32 757#ifdef _WIN32
758 int arg = 1; 758 int arg = 1;
759 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg); 759 ioctlsocket (_get_osfhandle (fd), FIONBIO, &arg);
1237 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now)); 1237 assert (("ev_periodic reschedule callback returned time in the past", ((WT)w)->at > ev_rt_now));
1238 downheap ((WT *)periodics, periodiccnt, 0); 1238 downheap ((WT *)periodics, periodiccnt, 0);
1239 } 1239 }
1240 else if (w->interval) 1240 else if (w->interval)
1241 { 1241 {
1242 ((WT)w)->at += floor ((ev_rt_now - ((WT)w)->at) / w->interval + 1.) * w->interval; 1242 ((WT)w)->at = w->offset + floor ((ev_rt_now - w->offset) / w->interval + 1.) * w->interval;
1243 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now)); 1243 assert (("ev_periodic timeout in the past detected while processing timers, negative interval?", ((WT)w)->at > ev_rt_now));
1244 downheap ((WT *)periodics, periodiccnt, 0); 1244 downheap ((WT *)periodics, periodiccnt, 0);
1245 } 1245 }
1246 else 1246 else
1247 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */ 1247 ev_periodic_stop (EV_A_ w); /* nonrepeating: stop timer */
1261 ev_periodic *w = periodics [i]; 1261 ev_periodic *w = periodics [i];
1262 1262
1263 if (w->reschedule_cb) 1263 if (w->reschedule_cb)
1264 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1264 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1265 else if (w->interval) 1265 else if (w->interval)
1266 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; 1266 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1267 } 1267 }
1268 1268
1269 /* now rebuild the heap */ 1269 /* now rebuild the heap */
1270 for (i = periodiccnt >> 1; i--; ) 1270 for (i = periodiccnt >> 1; i--; )
1271 downheap ((WT *)periodics, periodiccnt, i); 1271 downheap ((WT *)periodics, periodiccnt, i);
1414 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 1414 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
1415 call_pending (EV_A); 1415 call_pending (EV_A);
1416 } 1416 }
1417#endif 1417#endif
1418 1418
1419 /* queue check watchers (and execute them) */ 1419 /* queue prepare watchers (and execute them) */
1420 if (expect_false (preparecnt)) 1420 if (expect_false (preparecnt))
1421 { 1421 {
1422 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 1422 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
1423 call_pending (EV_A); 1423 call_pending (EV_A);
1424 } 1424 }
1546ev_clear_pending (EV_P_ void *w) 1546ev_clear_pending (EV_P_ void *w)
1547{ 1547{
1548 W w_ = (W)w; 1548 W w_ = (W)w;
1549 int pending = w_->pending; 1549 int pending = w_->pending;
1550 1550
1551 if (!pending) 1551 if (expect_true (pending))
1552 {
1553 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
1554 w_->pending = 0;
1555 p->w = 0;
1556 return p->events;
1557 }
1558 else
1552 return 0; 1559 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}
1560 1561
1561void inline_size 1562void inline_size
1562pri_adjust (EV_P_ W w) 1563pri_adjust (EV_P_ W w)
1563{ 1564{
1582 w->active = 0; 1583 w->active = 0;
1583} 1584}
1584 1585
1585/*****************************************************************************/ 1586/*****************************************************************************/
1586 1587
1587void 1588void noinline
1588ev_io_start (EV_P_ ev_io *w) 1589ev_io_start (EV_P_ ev_io *w)
1589{ 1590{
1590 int fd = w->fd; 1591 int fd = w->fd;
1591 1592
1592 if (expect_false (ev_is_active (w))) 1593 if (expect_false (ev_is_active (w)))
1599 wlist_add ((WL *)&anfds[fd].head, (WL)w); 1600 wlist_add ((WL *)&anfds[fd].head, (WL)w);
1600 1601
1601 fd_change (EV_A_ fd); 1602 fd_change (EV_A_ fd);
1602} 1603}
1603 1604
1604void 1605void noinline
1605ev_io_stop (EV_P_ ev_io *w) 1606ev_io_stop (EV_P_ ev_io *w)
1606{ 1607{
1607 clear_pending (EV_A_ (W)w); 1608 clear_pending (EV_A_ (W)w);
1608 if (expect_false (!ev_is_active (w))) 1609 if (expect_false (!ev_is_active (w)))
1609 return; 1610 return;
1614 ev_stop (EV_A_ (W)w); 1615 ev_stop (EV_A_ (W)w);
1615 1616
1616 fd_change (EV_A_ w->fd); 1617 fd_change (EV_A_ w->fd);
1617} 1618}
1618 1619
1619void 1620void noinline
1620ev_timer_start (EV_P_ ev_timer *w) 1621ev_timer_start (EV_P_ ev_timer *w)
1621{ 1622{
1622 if (expect_false (ev_is_active (w))) 1623 if (expect_false (ev_is_active (w)))
1623 return; 1624 return;
1624 1625
1632 upheap ((WT *)timers, timercnt - 1); 1633 upheap ((WT *)timers, timercnt - 1);
1633 1634
1634 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/ 1635 /*assert (("internal timer heap corruption", timers [((W)w)->active - 1] == w));*/
1635} 1636}
1636 1637
1637void 1638void noinline
1638ev_timer_stop (EV_P_ ev_timer *w) 1639ev_timer_stop (EV_P_ ev_timer *w)
1639{ 1640{
1640 clear_pending (EV_A_ (W)w); 1641 clear_pending (EV_A_ (W)w);
1641 if (expect_false (!ev_is_active (w))) 1642 if (expect_false (!ev_is_active (w)))
1642 return; 1643 return;
1656 ((WT)w)->at -= mn_now; 1657 ((WT)w)->at -= mn_now;
1657 1658
1658 ev_stop (EV_A_ (W)w); 1659 ev_stop (EV_A_ (W)w);
1659} 1660}
1660 1661
1661void 1662void noinline
1662ev_timer_again (EV_P_ ev_timer *w) 1663ev_timer_again (EV_P_ ev_timer *w)
1663{ 1664{
1664 if (ev_is_active (w)) 1665 if (ev_is_active (w))
1665 { 1666 {
1666 if (w->repeat) 1667 if (w->repeat)
1677 ev_timer_start (EV_A_ w); 1678 ev_timer_start (EV_A_ w);
1678 } 1679 }
1679} 1680}
1680 1681
1681#if EV_PERIODIC_ENABLE 1682#if EV_PERIODIC_ENABLE
1682void 1683void noinline
1683ev_periodic_start (EV_P_ ev_periodic *w) 1684ev_periodic_start (EV_P_ ev_periodic *w)
1684{ 1685{
1685 if (expect_false (ev_is_active (w))) 1686 if (expect_false (ev_is_active (w)))
1686 return; 1687 return;
1687 1688
1689 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now); 1690 ((WT)w)->at = w->reschedule_cb (w, ev_rt_now);
1690 else if (w->interval) 1691 else if (w->interval)
1691 { 1692 {
1692 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.)); 1693 assert (("ev_periodic_start called with negative interval value", w->interval >= 0.));
1693 /* this formula differs from the one in periodic_reify because we do not always round up */ 1694 /* this formula differs from the one in periodic_reify because we do not always round up */
1694 ((WT)w)->at += ceil ((ev_rt_now - ((WT)w)->at) / w->interval) * w->interval; 1695 ((WT)w)->at = w->offset + ceil ((ev_rt_now - w->offset) / w->interval) * w->interval;
1695 } 1696 }
1697 else
1698 ((WT)w)->at = w->offset;
1696 1699
1697 ev_start (EV_A_ (W)w, ++periodiccnt); 1700 ev_start (EV_A_ (W)w, ++periodiccnt);
1698 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2); 1701 array_needsize (ev_periodic *, periodics, periodicmax, periodiccnt, EMPTY2);
1699 periodics [periodiccnt - 1] = w; 1702 periodics [periodiccnt - 1] = w;
1700 upheap ((WT *)periodics, periodiccnt - 1); 1703 upheap ((WT *)periodics, periodiccnt - 1);
1701 1704
1702 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/ 1705 /*assert (("internal periodic heap corruption", periodics [((W)w)->active - 1] == w));*/
1703} 1706}
1704 1707
1705void 1708void noinline
1706ev_periodic_stop (EV_P_ ev_periodic *w) 1709ev_periodic_stop (EV_P_ ev_periodic *w)
1707{ 1710{
1708 clear_pending (EV_A_ (W)w); 1711 clear_pending (EV_A_ (W)w);
1709 if (expect_false (!ev_is_active (w))) 1712 if (expect_false (!ev_is_active (w)))
1710 return; 1713 return;
1722 } 1725 }
1723 1726
1724 ev_stop (EV_A_ (W)w); 1727 ev_stop (EV_A_ (W)w);
1725} 1728}
1726 1729
1727void 1730void noinline
1728ev_periodic_again (EV_P_ ev_periodic *w) 1731ev_periodic_again (EV_P_ ev_periodic *w)
1729{ 1732{
1730 /* TODO: use adjustheap and recalculation */ 1733 /* TODO: use adjustheap and recalculation */
1731 ev_periodic_stop (EV_A_ w); 1734 ev_periodic_stop (EV_A_ w);
1732 ev_periodic_start (EV_A_ w); 1735 ev_periodic_start (EV_A_ w);
1735 1738
1736#ifndef SA_RESTART 1739#ifndef SA_RESTART
1737# define SA_RESTART 0 1740# define SA_RESTART 0
1738#endif 1741#endif
1739 1742
1740void 1743void noinline
1741ev_signal_start (EV_P_ ev_signal *w) 1744ev_signal_start (EV_P_ ev_signal *w)
1742{ 1745{
1743#if EV_MULTIPLICITY 1746#if EV_MULTIPLICITY
1744 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 1747 assert (("signal watchers are only supported in the default loop", loop == ev_default_loop_ptr));
1745#endif 1748#endif
1764 sigaction (w->signum, &sa, 0); 1767 sigaction (w->signum, &sa, 0);
1765#endif 1768#endif
1766 } 1769 }
1767} 1770}
1768 1771
1769void 1772void noinline
1770ev_signal_stop (EV_P_ ev_signal *w) 1773ev_signal_stop (EV_P_ ev_signal *w)
1771{ 1774{
1772 clear_pending (EV_A_ (W)w); 1775 clear_pending (EV_A_ (W)w);
1773 if (expect_false (!ev_is_active (w))) 1776 if (expect_false (!ev_is_active (w)))
1774 return; 1777 return;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines