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

Comparing libev/ev.c (file contents):
Revision 1.377 by root, Wed Jun 8 13:11:55 2011 UTC vs.
Revision 1.380 by root, Mon Jun 27 19:20:01 2011 UTC

464#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 464#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
465 465
466#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) 466#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
467#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) 467#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0)
468 468
469#if __GNUC__ >= 4 469/* the following are taken from libecb */
470# define expect(expr,value) __builtin_expect ((expr),(value)) 470/* ecb.h start */
471# define noinline __attribute__ ((noinline)) 471
472/* many compilers define _GNUC_ to some versions but then only implement
473 * what their idiot authors think are the "more important" extensions,
474 * causing enourmous grief in return for some better fake benchmark numbers.
475 * or so.
476 * we try to detect these and simply assume they are not gcc - if they have
477 * an issue with that they should have done it right in the first place.
478 */
479#ifndef ECB_GCC_VERSION
480 #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__)
481 #define ECB_GCC_VERSION(major,minor) 0
482 #else
483 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
484 #endif
485#endif
486
487#if __cplusplus
488 #define ecb_inline static inline
489#elif ECB_GCC_VERSION(2,5)
490 #define ecb_inline static __inline__
491#elif ECB_C99
492 #define ecb_inline static inline
472#else 493#else
473# define expect(expr,value) (expr) 494 #define ecb_inline static
474# define noinline
475# if __STDC_VERSION__ < 199901L && __GNUC__ < 2
476# define inline
477# endif 495#endif
478#endif
479 496
497#if ECB_GCC_VERSION(3,1)
498 #define ecb_attribute(attrlist) __attribute__(attrlist)
499 #define ecb_is_constant(expr) __builtin_constant_p (expr)
500 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
501 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
502#else
503 #define ecb_attribute(attrlist)
504 #define ecb_is_constant(expr) 0
505 #define ecb_expect(expr,value) (expr)
506 #define ecb_prefetch(addr,rw,locality)
507#endif
508
509#define ecb_noinline ecb_attribute ((__noinline__))
510#define ecb_noreturn ecb_attribute ((__noreturn__))
511#define ecb_unused ecb_attribute ((__unused__))
512#define ecb_const ecb_attribute ((__const__))
513#define ecb_pure ecb_attribute ((__pure__))
514
515#if ECB_GCC_VERSION(4,3)
516 #define ecb_artificial ecb_attribute ((__artificial__))
517 #define ecb_hot ecb_attribute ((__hot__))
518 #define ecb_cold ecb_attribute ((__cold__))
519#else
520 #define ecb_artificial
521 #define ecb_hot
522 #define ecb_cold
523#endif
524
525/* put around conditional expressions if you are very sure that the */
526/* expression is mostly true or mostly false. note that these return */
527/* booleans, not the expression. */
480#define expect_false(expr) expect ((expr) != 0, 0) 528#define ecb_expect_false(expr) ecb_expect (!!(expr), 0)
481#define expect_true(expr) expect ((expr) != 0, 1) 529#define ecb_expect_true(expr) ecb_expect (!!(expr), 1)
530/* ecb.h end */
531
532#define expect_false(cond) ecb_expect_false (cond)
533#define expect_true(cond) ecb_expect_true (cond)
534#define noinline ecb_noinline
535
482#define inline_size static inline 536#define inline_size ecb_inline
483 537
484#if EV_FEATURE_CODE 538#if EV_FEATURE_CODE
485# define inline_speed static inline 539# define inline_speed ecb_inline
486#else 540#else
487# define inline_speed static noinline 541# define inline_speed static noinline
488#endif 542#endif
489 543
490#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 544#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
581 635
582#ifdef __linux 636#ifdef __linux
583# include <sys/utsname.h> 637# include <sys/utsname.h>
584#endif 638#endif
585 639
586static unsigned int noinline 640static unsigned int noinline ecb_cold
587ev_linux_version (void) 641ev_linux_version (void)
588{ 642{
589#ifdef __linux 643#ifdef __linux
590 unsigned int v = 0; 644 unsigned int v = 0;
591 struct utsname buf; 645 struct utsname buf;
620} 674}
621 675
622/*****************************************************************************/ 676/*****************************************************************************/
623 677
624#if EV_AVOID_STDIO 678#if EV_AVOID_STDIO
625static void noinline 679static void noinline ecb_cold
626ev_printerr (const char *msg) 680ev_printerr (const char *msg)
627{ 681{
628 write (STDERR_FILENO, msg, strlen (msg)); 682 write (STDERR_FILENO, msg, strlen (msg));
629} 683}
630#endif 684#endif
631 685
632static void (*syserr_cb)(const char *msg); 686static void (*syserr_cb)(const char *msg);
633 687
634void 688void ecb_cold
635ev_set_syserr_cb (void (*cb)(const char *msg)) 689ev_set_syserr_cb (void (*cb)(const char *msg))
636{ 690{
637 syserr_cb = cb; 691 syserr_cb = cb;
638} 692}
639 693
640static void noinline 694static void noinline ecb_cold
641ev_syserr (const char *msg) 695ev_syserr (const char *msg)
642{ 696{
643 if (!msg) 697 if (!msg)
644 msg = "(libev) system error"; 698 msg = "(libev) system error";
645 699
678#endif 732#endif
679} 733}
680 734
681static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 735static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
682 736
683void 737void ecb_cold
684ev_set_allocator (void *(*cb)(void *ptr, long size)) 738ev_set_allocator (void *(*cb)(void *ptr, long size))
685{ 739{
686 alloc = cb; 740 alloc = cb;
687} 741}
688 742
897 } 951 }
898 952
899 return ncur; 953 return ncur;
900} 954}
901 955
902static noinline void * 956static void * noinline ecb_cold
903array_realloc (int elem, void *base, int *cur, int cnt) 957array_realloc (int elem, void *base, int *cur, int cnt)
904{ 958{
905 *cur = array_nextsize (elem, *cur, cnt); 959 *cur = array_nextsize (elem, *cur, cnt);
906 return ev_realloc (base, elem * *cur); 960 return ev_realloc (base, elem * *cur);
907} 961}
1090 fdchanges [fdchangecnt - 1] = fd; 1144 fdchanges [fdchangecnt - 1] = fd;
1091 } 1145 }
1092} 1146}
1093 1147
1094/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 1148/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
1095inline_speed void 1149inline_speed void ecb_cold
1096fd_kill (EV_P_ int fd) 1150fd_kill (EV_P_ int fd)
1097{ 1151{
1098 ev_io *w; 1152 ev_io *w;
1099 1153
1100 while ((w = (ev_io *)anfds [fd].head)) 1154 while ((w = (ev_io *)anfds [fd].head))
1103 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 1157 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
1104 } 1158 }
1105} 1159}
1106 1160
1107/* check whether the given fd is actually valid, for error recovery */ 1161/* check whether the given fd is actually valid, for error recovery */
1108inline_size int 1162inline_size int ecb_cold
1109fd_valid (int fd) 1163fd_valid (int fd)
1110{ 1164{
1111#ifdef _WIN32 1165#ifdef _WIN32
1112 return EV_FD_TO_WIN32_HANDLE (fd) != -1; 1166 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
1113#else 1167#else
1114 return fcntl (fd, F_GETFD) != -1; 1168 return fcntl (fd, F_GETFD) != -1;
1115#endif 1169#endif
1116} 1170}
1117 1171
1118/* called on EBADF to verify fds */ 1172/* called on EBADF to verify fds */
1119static void noinline 1173static void noinline ecb_cold
1120fd_ebadf (EV_P) 1174fd_ebadf (EV_P)
1121{ 1175{
1122 int fd; 1176 int fd;
1123 1177
1124 for (fd = 0; fd < anfdmax; ++fd) 1178 for (fd = 0; fd < anfdmax; ++fd)
1126 if (!fd_valid (fd) && errno == EBADF) 1180 if (!fd_valid (fd) && errno == EBADF)
1127 fd_kill (EV_A_ fd); 1181 fd_kill (EV_A_ fd);
1128} 1182}
1129 1183
1130/* called on ENOMEM in select/poll to kill some fds and retry */ 1184/* called on ENOMEM in select/poll to kill some fds and retry */
1131static void noinline 1185static void noinline ecb_cold
1132fd_enomem (EV_P) 1186fd_enomem (EV_P)
1133{ 1187{
1134 int fd; 1188 int fd;
1135 1189
1136 for (fd = anfdmax; fd--; ) 1190 for (fd = anfdmax; fd--; )
1331 1385
1332/*****************************************************************************/ 1386/*****************************************************************************/
1333 1387
1334#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 1388#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
1335 1389
1336static void noinline 1390static void noinline ecb_cold
1337evpipe_init (EV_P) 1391evpipe_init (EV_P)
1338{ 1392{
1339 if (!ev_is_active (&pipe_w)) 1393 if (!ev_is_active (&pipe_w))
1340 { 1394 {
1341# if EV_USE_EVENTFD 1395# if EV_USE_EVENTFD
1363 ev_io_start (EV_A_ &pipe_w); 1417 ev_io_start (EV_A_ &pipe_w);
1364 ev_unref (EV_A); /* watcher should not keep loop alive */ 1418 ev_unref (EV_A); /* watcher should not keep loop alive */
1365 } 1419 }
1366} 1420}
1367 1421
1368inline_size void 1422inline_speed void
1369evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1423evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1370{ 1424{
1371 if (!*flag) 1425 if (!*flag)
1372 { 1426 {
1373 int old_errno = errno; /* save errno because write might clobber it */
1374 char dummy;
1375
1376 *flag = 1; 1427 *flag = 1;
1377 1428
1429 pipe_write_skipped = 1;
1430
1431 if (pipe_write_wanted)
1432 {
1433 int old_errno;
1434
1435 pipe_write_skipped = 0;
1436
1437 old_errno = errno; /* save errno because write will clobber it */
1438
1378#if EV_USE_EVENTFD 1439#if EV_USE_EVENTFD
1379 if (evfd >= 0) 1440 if (evfd >= 0)
1380 { 1441 {
1381 uint64_t counter = 1; 1442 uint64_t counter = 1;
1382 write (evfd, &counter, sizeof (uint64_t)); 1443 write (evfd, &counter, sizeof (uint64_t));
1444 }
1445 else
1446#endif
1447 {
1448 /* win32 people keep sending patches that change this write() to send() */
1449 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1450 /* so when you think this write should be a send instead, please find out */
1451 /* where your send() is from - it's definitely not the microsoft send, and */
1452 /* tell me. thank you. */
1453 write (evpipe [1], &(evpipe [1]), 1);
1454 }
1455
1456 errno = old_errno;
1383 } 1457 }
1384 else
1385#endif
1386 /* win32 people keep sending patches that change this write() to send() */
1387 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1388 /* so when you think this write should be a send instead, please find out */
1389 /* where your send() is from - it's definitely not the microsoft send, and */
1390 /* tell me. thank you. */
1391 write (evpipe [1], &dummy, 1);
1392
1393 errno = old_errno;
1394 } 1458 }
1395} 1459}
1396 1460
1397/* called whenever the libev signal pipe */ 1461/* called whenever the libev signal pipe */
1398/* got some events (signal, async) */ 1462/* got some events (signal, async) */
1399static void 1463static void
1400pipecb (EV_P_ ev_io *iow, int revents) 1464pipecb (EV_P_ ev_io *iow, int revents)
1401{ 1465{
1402 int i; 1466 int i;
1403 1467
1468 if (revents & EV_READ)
1469 {
1404#if EV_USE_EVENTFD 1470#if EV_USE_EVENTFD
1405 if (evfd >= 0) 1471 if (evfd >= 0)
1406 { 1472 {
1407 uint64_t counter; 1473 uint64_t counter;
1408 read (evfd, &counter, sizeof (uint64_t)); 1474 read (evfd, &counter, sizeof (uint64_t));
1409 } 1475 }
1410 else 1476 else
1411#endif 1477#endif
1412 { 1478 {
1413 char dummy; 1479 char dummy;
1414 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1480 /* see discussion in evpipe_write when you think this read should be recv in win32 */
1415 read (evpipe [0], &dummy, 1); 1481 read (evpipe [0], &dummy, 1);
1482 }
1416 } 1483 }
1484
1485 pipe_write_skipped = 0;
1417 1486
1418#if EV_SIGNAL_ENABLE 1487#if EV_SIGNAL_ENABLE
1419 if (sig_pending) 1488 if (sig_pending)
1420 { 1489 {
1421 sig_pending = 0; 1490 sig_pending = 0;
1450 EV_P = signals [signum - 1].loop; 1519 EV_P = signals [signum - 1].loop;
1451 1520
1452 if (!EV_A) 1521 if (!EV_A)
1453 return; 1522 return;
1454#endif 1523#endif
1524
1525 evpipe_init (EV_A);
1455 1526
1456 signals [signum - 1].pending = 1; 1527 signals [signum - 1].pending = 1;
1457 evpipe_write (EV_A_ &sig_pending); 1528 evpipe_write (EV_A_ &sig_pending);
1458} 1529}
1459 1530
1591#endif 1662#endif
1592#if EV_USE_SELECT 1663#if EV_USE_SELECT
1593# include "ev_select.c" 1664# include "ev_select.c"
1594#endif 1665#endif
1595 1666
1596int 1667int ecb_cold
1597ev_version_major (void) 1668ev_version_major (void)
1598{ 1669{
1599 return EV_VERSION_MAJOR; 1670 return EV_VERSION_MAJOR;
1600} 1671}
1601 1672
1602int 1673int ecb_cold
1603ev_version_minor (void) 1674ev_version_minor (void)
1604{ 1675{
1605 return EV_VERSION_MINOR; 1676 return EV_VERSION_MINOR;
1606} 1677}
1607 1678
1608/* return true if we are running with elevated privileges and should ignore env variables */ 1679/* return true if we are running with elevated privileges and should ignore env variables */
1609int inline_size 1680int inline_size ecb_cold
1610enable_secure (void) 1681enable_secure (void)
1611{ 1682{
1612#ifdef _WIN32 1683#ifdef _WIN32
1613 return 0; 1684 return 0;
1614#else 1685#else
1615 return getuid () != geteuid () 1686 return getuid () != geteuid ()
1616 || getgid () != getegid (); 1687 || getgid () != getegid ();
1617#endif 1688#endif
1618} 1689}
1619 1690
1620unsigned int 1691unsigned int ecb_cold
1621ev_supported_backends (void) 1692ev_supported_backends (void)
1622{ 1693{
1623 unsigned int flags = 0; 1694 unsigned int flags = 0;
1624 1695
1625 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 1696 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
1629 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 1700 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
1630 1701
1631 return flags; 1702 return flags;
1632} 1703}
1633 1704
1634unsigned int 1705unsigned int ecb_cold
1635ev_recommended_backends (void) 1706ev_recommended_backends (void)
1636{ 1707{
1637 unsigned int flags = ev_supported_backends (); 1708 unsigned int flags = ev_supported_backends ();
1638 1709
1639#ifndef __NetBSD__ 1710#ifndef __NetBSD__
1651#endif 1722#endif
1652 1723
1653 return flags; 1724 return flags;
1654} 1725}
1655 1726
1656unsigned int 1727unsigned int ecb_cold
1657ev_embeddable_backends (void) 1728ev_embeddable_backends (void)
1658{ 1729{
1659 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 1730 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
1660 1731
1661 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 1732 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
1706ev_userdata (EV_P) 1777ev_userdata (EV_P)
1707{ 1778{
1708 return userdata; 1779 return userdata;
1709} 1780}
1710 1781
1782void
1711void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 1783ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P))
1712{ 1784{
1713 invoke_cb = invoke_pending_cb; 1785 invoke_cb = invoke_pending_cb;
1714} 1786}
1715 1787
1788void
1716void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 1789ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P))
1717{ 1790{
1718 release_cb = release; 1791 release_cb = release;
1719 acquire_cb = acquire; 1792 acquire_cb = acquire;
1720} 1793}
1721#endif 1794#endif
1722 1795
1723/* initialise a loop structure, must be zero-initialised */ 1796/* initialise a loop structure, must be zero-initialised */
1724static void noinline 1797static void noinline ecb_cold
1725loop_init (EV_P_ unsigned int flags) 1798loop_init (EV_P_ unsigned int flags)
1726{ 1799{
1727 if (!backend) 1800 if (!backend)
1728 { 1801 {
1729 origflags = flags; 1802 origflags = flags;
1757 if (!(flags & EVFLAG_NOENV) 1830 if (!(flags & EVFLAG_NOENV)
1758 && !enable_secure () 1831 && !enable_secure ()
1759 && getenv ("LIBEV_FLAGS")) 1832 && getenv ("LIBEV_FLAGS"))
1760 flags = atoi (getenv ("LIBEV_FLAGS")); 1833 flags = atoi (getenv ("LIBEV_FLAGS"));
1761 1834
1762 ev_rt_now = ev_time (); 1835 ev_rt_now = ev_time ();
1763 mn_now = get_clock (); 1836 mn_now = get_clock ();
1764 now_floor = mn_now; 1837 now_floor = mn_now;
1765 rtmn_diff = ev_rt_now - mn_now; 1838 rtmn_diff = ev_rt_now - mn_now;
1766#if EV_FEATURE_API 1839#if EV_FEATURE_API
1767 invoke_cb = ev_invoke_pending; 1840 invoke_cb = ev_invoke_pending;
1768#endif 1841#endif
1769 1842
1770 io_blocktime = 0.; 1843 io_blocktime = 0.;
1771 timeout_blocktime = 0.; 1844 timeout_blocktime = 0.;
1772 backend = 0; 1845 backend = 0;
1773 backend_fd = -1; 1846 backend_fd = -1;
1774 sig_pending = 0; 1847 sig_pending = 0;
1775#if EV_ASYNC_ENABLE 1848#if EV_ASYNC_ENABLE
1776 async_pending = 0; 1849 async_pending = 0;
1777#endif 1850#endif
1851 pipe_write_skipped = 0;
1852 pipe_write_wanted = 0;
1778#if EV_USE_INOTIFY 1853#if EV_USE_INOTIFY
1779 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; 1854 fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2;
1780#endif 1855#endif
1781#if EV_USE_SIGNALFD 1856#if EV_USE_SIGNALFD
1782 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; 1857 sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1;
1783#endif 1858#endif
1784 1859
1785 if (!(flags & EVBACKEND_MASK)) 1860 if (!(flags & EVBACKEND_MASK))
1786 flags |= ev_recommended_backends (); 1861 flags |= ev_recommended_backends ();
1787 1862
1812#endif 1887#endif
1813 } 1888 }
1814} 1889}
1815 1890
1816/* free up a loop structure */ 1891/* free up a loop structure */
1817void 1892void ecb_cold
1818ev_loop_destroy (EV_P) 1893ev_loop_destroy (EV_P)
1819{ 1894{
1820 int i; 1895 int i;
1821 1896
1822#if EV_MULTIPLICITY 1897#if EV_MULTIPLICITY
1952 infy_fork (EV_A); 2027 infy_fork (EV_A);
1953#endif 2028#endif
1954 2029
1955 if (ev_is_active (&pipe_w)) 2030 if (ev_is_active (&pipe_w))
1956 { 2031 {
1957 /* this "locks" the handlers against writing to the pipe */ 2032 /* pipe_write_wanted must be false now, so modifying fd vars should be safe */
1958 /* while we modify the fd vars */
1959 sig_pending = 1;
1960#if EV_ASYNC_ENABLE
1961 async_pending = 1;
1962#endif
1963 2033
1964 ev_ref (EV_A); 2034 ev_ref (EV_A);
1965 ev_io_stop (EV_A_ &pipe_w); 2035 ev_io_stop (EV_A_ &pipe_w);
1966 2036
1967#if EV_USE_EVENTFD 2037#if EV_USE_EVENTFD
1985 postfork = 0; 2055 postfork = 0;
1986} 2056}
1987 2057
1988#if EV_MULTIPLICITY 2058#if EV_MULTIPLICITY
1989 2059
1990struct ev_loop * 2060struct ev_loop * ecb_cold
1991ev_loop_new (unsigned int flags) 2061ev_loop_new (unsigned int flags)
1992{ 2062{
1993 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2063 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
1994 2064
1995 memset (EV_A, 0, sizeof (struct ev_loop)); 2065 memset (EV_A, 0, sizeof (struct ev_loop));
2003} 2073}
2004 2074
2005#endif /* multiplicity */ 2075#endif /* multiplicity */
2006 2076
2007#if EV_VERIFY 2077#if EV_VERIFY
2008static void noinline 2078static void noinline ecb_cold
2009verify_watcher (EV_P_ W w) 2079verify_watcher (EV_P_ W w)
2010{ 2080{
2011 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 2081 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
2012 2082
2013 if (w->pending) 2083 if (w->pending)
2014 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 2084 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
2015} 2085}
2016 2086
2017static void noinline 2087static void noinline ecb_cold
2018verify_heap (EV_P_ ANHE *heap, int N) 2088verify_heap (EV_P_ ANHE *heap, int N)
2019{ 2089{
2020 int i; 2090 int i;
2021 2091
2022 for (i = HEAP0; i < N + HEAP0; ++i) 2092 for (i = HEAP0; i < N + HEAP0; ++i)
2027 2097
2028 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 2098 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
2029 } 2099 }
2030} 2100}
2031 2101
2032static void noinline 2102static void noinline ecb_cold
2033array_verify (EV_P_ W *ws, int cnt) 2103array_verify (EV_P_ W *ws, int cnt)
2034{ 2104{
2035 while (cnt--) 2105 while (cnt--)
2036 { 2106 {
2037 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 2107 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1));
2039 } 2109 }
2040} 2110}
2041#endif 2111#endif
2042 2112
2043#if EV_FEATURE_API 2113#if EV_FEATURE_API
2044void 2114void ecb_cold
2045ev_verify (EV_P) 2115ev_verify (EV_P)
2046{ 2116{
2047#if EV_VERIFY 2117#if EV_VERIFY
2048 int i; 2118 int i;
2049 WL w; 2119 WL w;
2115#endif 2185#endif
2116} 2186}
2117#endif 2187#endif
2118 2188
2119#if EV_MULTIPLICITY 2189#if EV_MULTIPLICITY
2120struct ev_loop * 2190struct ev_loop * ecb_cold
2121#else 2191#else
2122int 2192int
2123#endif 2193#endif
2124ev_default_loop (unsigned int flags) 2194ev_default_loop (unsigned int flags)
2125{ 2195{
2324 } 2394 }
2325} 2395}
2326 2396
2327/* simply recalculate all periodics */ 2397/* simply recalculate all periodics */
2328/* TODO: maybe ensure that at least one event happens when jumping forward? */ 2398/* TODO: maybe ensure that at least one event happens when jumping forward? */
2329static void noinline 2399static void noinline ecb_cold
2330periodics_reschedule (EV_P) 2400periodics_reschedule (EV_P)
2331{ 2401{
2332 int i; 2402 int i;
2333 2403
2334 /* adjust periodics after time jump */ 2404 /* adjust periodics after time jump */
2347 reheap (periodics, periodiccnt); 2417 reheap (periodics, periodiccnt);
2348} 2418}
2349#endif 2419#endif
2350 2420
2351/* adjust all timers by a given offset */ 2421/* adjust all timers by a given offset */
2352static void noinline 2422static void noinline ecb_cold
2353timers_reschedule (EV_P_ ev_tstamp adjust) 2423timers_reschedule (EV_P_ ev_tstamp adjust)
2354{ 2424{
2355 int i; 2425 int i;
2356 2426
2357 for (i = 0; i < timercnt; ++i) 2427 for (i = 0; i < timercnt; ++i)
2499 ev_tstamp prev_mn_now = mn_now; 2569 ev_tstamp prev_mn_now = mn_now;
2500 2570
2501 /* update time to cancel out callback processing overhead */ 2571 /* update time to cancel out callback processing overhead */
2502 time_update (EV_A_ 1e100); 2572 time_update (EV_A_ 1e100);
2503 2573
2574 /* from now on, we want a pipe-wake-up */
2575 pipe_write_wanted = 1;
2576
2504 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt))) 2577 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
2505 { 2578 {
2506 waittime = MAX_BLOCKTIME; 2579 waittime = MAX_BLOCKTIME;
2507 2580
2508 if (timercnt) 2581 if (timercnt)
2509 { 2582 {
2548 ++loop_count; 2621 ++loop_count;
2549#endif 2622#endif
2550 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ 2623 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2551 backend_poll (EV_A_ waittime); 2624 backend_poll (EV_A_ waittime);
2552 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 2625 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2626
2627 pipe_write_wanted = 0;
2628
2629 if (pipe_write_skipped)
2630 {
2631 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
2632 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
2633 }
2634
2553 2635
2554 /* update ev_rt_now, do magic */ 2636 /* update ev_rt_now, do magic */
2555 time_update (EV_A_ waittime + sleeptime); 2637 time_update (EV_A_ waittime + sleeptime);
2556 } 2638 }
2557 2639
3211 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3293 infy_wd (EV_A_ ev->wd, ev->wd, ev);
3212 ofs += sizeof (struct inotify_event) + ev->len; 3294 ofs += sizeof (struct inotify_event) + ev->len;
3213 } 3295 }
3214} 3296}
3215 3297
3216inline_size void 3298inline_size void ecb_cold
3217ev_check_2625 (EV_P) 3299ev_check_2625 (EV_P)
3218{ 3300{
3219 /* kernels < 2.6.25 are borked 3301 /* kernels < 2.6.25 are borked
3220 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3302 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3221 */ 3303 */
3846} 3928}
3847 3929
3848/*****************************************************************************/ 3930/*****************************************************************************/
3849 3931
3850#if EV_WALK_ENABLE 3932#if EV_WALK_ENABLE
3851void 3933void ecb_cold
3852ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 3934ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w))
3853{ 3935{
3854 int i, j; 3936 int i, j;
3855 ev_watcher_list *wl, *wn; 3937 ev_watcher_list *wl, *wn;
3856 3938

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines