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

Comparing libev/ev.c (file contents):
Revision 1.378 by root, Mon Jun 13 09:52:36 2011 UTC vs.
Revision 1.388 by root, Fri Jul 29 12:17:26 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
496
497#ifndef ECB_MEMORY_FENCE
498 #if ECB_GCC_VERSION(2,5)
499 #if __x86
500 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
501 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
502 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE /* better be safe than sorry */
503 #elif __amd64
504 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
505 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
506 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence")
507 #endif
478#endif 508 #endif
509#endif
479 510
511#ifndef ECB_MEMORY_FENCE
512 #if ECB_GCC_VERSION(4,4)
513 #define ECB_MEMORY_FENCE __sync_synchronize ()
514 #define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); })
515 #define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); })
516 #elif _MSC_VER >= 1400 && 0 /* TODO: only true when using volatiles */
517 #define ECB_MEMORY_FENCE do { } while (0)
518 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
519 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
520 #elif defined(_WIN32)
521 #include <WinNT.h>
522 #define ECB_MEMORY_FENCE MemoryBarrier ()
523 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
524 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
525 #endif
526#endif
527
528#ifndef ECB_MEMORY_FENCE
529 #include <pthread.h>
530
531 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
532 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
533 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
534 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
535#endif
536
537#if ECB_GCC_VERSION(3,1)
538 #define ecb_attribute(attrlist) __attribute__(attrlist)
539 #define ecb_is_constant(expr) __builtin_constant_p (expr)
540 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
541 #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality)
542#else
543 #define ecb_attribute(attrlist)
544 #define ecb_is_constant(expr) 0
545 #define ecb_expect(expr,value) (expr)
546 #define ecb_prefetch(addr,rw,locality)
547#endif
548
549#define ecb_noinline ecb_attribute ((__noinline__))
550#define ecb_noreturn ecb_attribute ((__noreturn__))
551#define ecb_unused ecb_attribute ((__unused__))
552#define ecb_const ecb_attribute ((__const__))
553#define ecb_pure ecb_attribute ((__pure__))
554
555#if ECB_GCC_VERSION(4,3)
556 #define ecb_artificial ecb_attribute ((__artificial__))
557 #define ecb_hot ecb_attribute ((__hot__))
558 #define ecb_cold ecb_attribute ((__cold__))
559#else
560 #define ecb_artificial
561 #define ecb_hot
562 #define ecb_cold
563#endif
564
565/* put around conditional expressions if you are very sure that the */
566/* expression is mostly true or mostly false. note that these return */
567/* booleans, not the expression. */
480#define expect_false(expr) expect ((expr) != 0, 0) 568#define ecb_expect_false(expr) ecb_expect (!!(expr), 0)
481#define expect_true(expr) expect ((expr) != 0, 1) 569#define ecb_expect_true(expr) ecb_expect (!!(expr), 1)
570/* ecb.h end */
571
572#define expect_false(cond) ecb_expect_false (cond)
573#define expect_true(cond) ecb_expect_true (cond)
574#define noinline ecb_noinline
575
482#define inline_size static inline 576#define inline_size ecb_inline
483 577
484#if EV_FEATURE_CODE 578#if EV_FEATURE_CODE
485# define inline_speed static inline 579# define inline_speed ecb_inline
486#else 580#else
487# define inline_speed static noinline 581# define inline_speed static noinline
488#endif 582#endif
489 583
490#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 584#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
581 675
582#ifdef __linux 676#ifdef __linux
583# include <sys/utsname.h> 677# include <sys/utsname.h>
584#endif 678#endif
585 679
586static unsigned int noinline 680static unsigned int noinline ecb_cold
587ev_linux_version (void) 681ev_linux_version (void)
588{ 682{
589#ifdef __linux 683#ifdef __linux
590 unsigned int v = 0; 684 unsigned int v = 0;
591 struct utsname buf; 685 struct utsname buf;
620} 714}
621 715
622/*****************************************************************************/ 716/*****************************************************************************/
623 717
624#if EV_AVOID_STDIO 718#if EV_AVOID_STDIO
625static void noinline 719static void noinline ecb_cold
626ev_printerr (const char *msg) 720ev_printerr (const char *msg)
627{ 721{
628 write (STDERR_FILENO, msg, strlen (msg)); 722 write (STDERR_FILENO, msg, strlen (msg));
629} 723}
630#endif 724#endif
631 725
632static void (*syserr_cb)(const char *msg); 726static void (*syserr_cb)(const char *msg);
633 727
634void 728void ecb_cold
635ev_set_syserr_cb (void (*cb)(const char *msg)) 729ev_set_syserr_cb (void (*cb)(const char *msg))
636{ 730{
637 syserr_cb = cb; 731 syserr_cb = cb;
638} 732}
639 733
640static void noinline 734static void noinline ecb_cold
641ev_syserr (const char *msg) 735ev_syserr (const char *msg)
642{ 736{
643 if (!msg) 737 if (!msg)
644 msg = "(libev) system error"; 738 msg = "(libev) system error";
645 739
678#endif 772#endif
679} 773}
680 774
681static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 775static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
682 776
683void 777void ecb_cold
684ev_set_allocator (void *(*cb)(void *ptr, long size)) 778ev_set_allocator (void *(*cb)(void *ptr, long size))
685{ 779{
686 alloc = cb; 780 alloc = cb;
687} 781}
688 782
897 } 991 }
898 992
899 return ncur; 993 return ncur;
900} 994}
901 995
902static noinline void * 996static void * noinline ecb_cold
903array_realloc (int elem, void *base, int *cur, int cnt) 997array_realloc (int elem, void *base, int *cur, int cnt)
904{ 998{
905 *cur = array_nextsize (elem, *cur, cnt); 999 *cur = array_nextsize (elem, *cur, cnt);
906 return ev_realloc (base, elem * *cur); 1000 return ev_realloc (base, elem * *cur);
907} 1001}
910 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1004 memset ((void *)(base), 0, sizeof (*(base)) * (count))
911 1005
912#define array_needsize(type,base,cur,cnt,init) \ 1006#define array_needsize(type,base,cur,cnt,init) \
913 if (expect_false ((cnt) > (cur))) \ 1007 if (expect_false ((cnt) > (cur))) \
914 { \ 1008 { \
915 int ocur_ = (cur); \ 1009 int ecb_unused ocur_ = (cur); \
916 (base) = (type *)array_realloc \ 1010 (base) = (type *)array_realloc \
917 (sizeof (type), (base), &(cur), (cnt)); \ 1011 (sizeof (type), (base), &(cur), (cnt)); \
918 init ((base) + (ocur_), (cur) - ocur_); \ 1012 init ((base) + (ocur_), (cur) - ocur_); \
919 } 1013 }
920 1014
1090 fdchanges [fdchangecnt - 1] = fd; 1184 fdchanges [fdchangecnt - 1] = fd;
1091 } 1185 }
1092} 1186}
1093 1187
1094/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 1188/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
1095inline_speed void 1189inline_speed void ecb_cold
1096fd_kill (EV_P_ int fd) 1190fd_kill (EV_P_ int fd)
1097{ 1191{
1098 ev_io *w; 1192 ev_io *w;
1099 1193
1100 while ((w = (ev_io *)anfds [fd].head)) 1194 while ((w = (ev_io *)anfds [fd].head))
1103 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 1197 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
1104 } 1198 }
1105} 1199}
1106 1200
1107/* check whether the given fd is actually valid, for error recovery */ 1201/* check whether the given fd is actually valid, for error recovery */
1108inline_size int 1202inline_size int ecb_cold
1109fd_valid (int fd) 1203fd_valid (int fd)
1110{ 1204{
1111#ifdef _WIN32 1205#ifdef _WIN32
1112 return EV_FD_TO_WIN32_HANDLE (fd) != -1; 1206 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
1113#else 1207#else
1114 return fcntl (fd, F_GETFD) != -1; 1208 return fcntl (fd, F_GETFD) != -1;
1115#endif 1209#endif
1116} 1210}
1117 1211
1118/* called on EBADF to verify fds */ 1212/* called on EBADF to verify fds */
1119static void noinline 1213static void noinline ecb_cold
1120fd_ebadf (EV_P) 1214fd_ebadf (EV_P)
1121{ 1215{
1122 int fd; 1216 int fd;
1123 1217
1124 for (fd = 0; fd < anfdmax; ++fd) 1218 for (fd = 0; fd < anfdmax; ++fd)
1126 if (!fd_valid (fd) && errno == EBADF) 1220 if (!fd_valid (fd) && errno == EBADF)
1127 fd_kill (EV_A_ fd); 1221 fd_kill (EV_A_ fd);
1128} 1222}
1129 1223
1130/* called on ENOMEM in select/poll to kill some fds and retry */ 1224/* called on ENOMEM in select/poll to kill some fds and retry */
1131static void noinline 1225static void noinline ecb_cold
1132fd_enomem (EV_P) 1226fd_enomem (EV_P)
1133{ 1227{
1134 int fd; 1228 int fd;
1135 1229
1136 for (fd = anfdmax; fd--; ) 1230 for (fd = anfdmax; fd--; )
1331 1425
1332/*****************************************************************************/ 1426/*****************************************************************************/
1333 1427
1334#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 1428#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
1335 1429
1336static void noinline 1430static void noinline ecb_cold
1337evpipe_init (EV_P) 1431evpipe_init (EV_P)
1338{ 1432{
1339 if (!ev_is_active (&pipe_w)) 1433 if (!ev_is_active (&pipe_w))
1340 { 1434 {
1341# if EV_USE_EVENTFD 1435# if EV_USE_EVENTFD
1363 ev_io_start (EV_A_ &pipe_w); 1457 ev_io_start (EV_A_ &pipe_w);
1364 ev_unref (EV_A); /* watcher should not keep loop alive */ 1458 ev_unref (EV_A); /* watcher should not keep loop alive */
1365 } 1459 }
1366} 1460}
1367 1461
1368inline_size void 1462inline_speed void
1369evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1463evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1370{ 1464{
1371 if (!*flag) 1465 if (expect_true (*flag))
1372 { 1466 return;
1467
1373 *flag = 1; 1468 *flag = 1;
1374 1469
1470 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
1471
1375 pipe_write_skipped = 1; 1472 pipe_write_skipped = 1;
1376 1473
1474 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */
1475
1377 if (pipe_write_wanted) 1476 if (pipe_write_wanted)
1477 {
1478 int old_errno;
1479
1480 pipe_write_skipped = 0; /* just an optimsiation, no fence needed */
1481
1482 old_errno = errno; /* save errno because write will clobber it */
1483
1484#if EV_USE_EVENTFD
1485 if (evfd >= 0)
1378 { 1486 {
1379 int old_errno = errno; /* save errno because write will clobber it */
1380 char dummy;
1381
1382 pipe_write_skipped = 0;
1383
1384#if EV_USE_EVENTFD
1385 if (evfd >= 0)
1386 {
1387 uint64_t counter = 1; 1487 uint64_t counter = 1;
1388 write (evfd, &counter, sizeof (uint64_t)); 1488 write (evfd, &counter, sizeof (uint64_t));
1389 }
1390 else
1391#endif
1392 {
1393 /* win32 people keep sending patches that change this write() to send() */
1394 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1395 /* so when you think this write should be a send instead, please find out */
1396 /* where your send() is from - it's definitely not the microsoft send, and */
1397 /* tell me. thank you. */
1398 write (evpipe [1], &dummy, 1);
1399 }
1400
1401 errno = old_errno;
1402 } 1489 }
1490 else
1491#endif
1492 {
1493 /* win32 people keep sending patches that change this write() to send() */
1494 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1495 /* so when you think this write should be a send instead, please find out */
1496 /* where your send() is from - it's definitely not the microsoft send, and */
1497 /* tell me. thank you. */
1498 write (evpipe [1], &(evpipe [1]), 1);
1499 }
1500
1501 errno = old_errno;
1403 } 1502 }
1404} 1503}
1405 1504
1406/* called whenever the libev signal pipe */ 1505/* called whenever the libev signal pipe */
1407/* got some events (signal, async) */ 1506/* got some events (signal, async) */
1465 1564
1466 if (!EV_A) 1565 if (!EV_A)
1467 return; 1566 return;
1468#endif 1567#endif
1469 1568
1470 evpipe_init (EV_A); 1569 if (!ev_active (&pipe_w))
1570 return;
1471 1571
1472 signals [signum - 1].pending = 1; 1572 signals [signum - 1].pending = 1;
1473 evpipe_write (EV_A_ &sig_pending); 1573 evpipe_write (EV_A_ &sig_pending);
1474} 1574}
1475 1575
1607#endif 1707#endif
1608#if EV_USE_SELECT 1708#if EV_USE_SELECT
1609# include "ev_select.c" 1709# include "ev_select.c"
1610#endif 1710#endif
1611 1711
1612int 1712int ecb_cold
1613ev_version_major (void) 1713ev_version_major (void)
1614{ 1714{
1615 return EV_VERSION_MAJOR; 1715 return EV_VERSION_MAJOR;
1616} 1716}
1617 1717
1618int 1718int ecb_cold
1619ev_version_minor (void) 1719ev_version_minor (void)
1620{ 1720{
1621 return EV_VERSION_MINOR; 1721 return EV_VERSION_MINOR;
1622} 1722}
1623 1723
1624/* return true if we are running with elevated privileges and should ignore env variables */ 1724/* return true if we are running with elevated privileges and should ignore env variables */
1625int inline_size 1725int inline_size ecb_cold
1626enable_secure (void) 1726enable_secure (void)
1627{ 1727{
1628#ifdef _WIN32 1728#ifdef _WIN32
1629 return 0; 1729 return 0;
1630#else 1730#else
1631 return getuid () != geteuid () 1731 return getuid () != geteuid ()
1632 || getgid () != getegid (); 1732 || getgid () != getegid ();
1633#endif 1733#endif
1634} 1734}
1635 1735
1636unsigned int 1736unsigned int ecb_cold
1637ev_supported_backends (void) 1737ev_supported_backends (void)
1638{ 1738{
1639 unsigned int flags = 0; 1739 unsigned int flags = 0;
1640 1740
1641 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 1741 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
1645 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 1745 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT;
1646 1746
1647 return flags; 1747 return flags;
1648} 1748}
1649 1749
1650unsigned int 1750unsigned int ecb_cold
1651ev_recommended_backends (void) 1751ev_recommended_backends (void)
1652{ 1752{
1653 unsigned int flags = ev_supported_backends (); 1753 unsigned int flags = ev_supported_backends ();
1654 1754
1655#ifndef __NetBSD__ 1755#ifndef __NetBSD__
1667#endif 1767#endif
1668 1768
1669 return flags; 1769 return flags;
1670} 1770}
1671 1771
1672unsigned int 1772unsigned int ecb_cold
1673ev_embeddable_backends (void) 1773ev_embeddable_backends (void)
1674{ 1774{
1675 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 1775 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
1676 1776
1677 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 1777 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
1722ev_userdata (EV_P) 1822ev_userdata (EV_P)
1723{ 1823{
1724 return userdata; 1824 return userdata;
1725} 1825}
1726 1826
1827void
1727void ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 1828ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P))
1728{ 1829{
1729 invoke_cb = invoke_pending_cb; 1830 invoke_cb = invoke_pending_cb;
1730} 1831}
1731 1832
1833void
1732void ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 1834ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P))
1733{ 1835{
1734 release_cb = release; 1836 release_cb = release;
1735 acquire_cb = acquire; 1837 acquire_cb = acquire;
1736} 1838}
1737#endif 1839#endif
1738 1840
1739/* initialise a loop structure, must be zero-initialised */ 1841/* initialise a loop structure, must be zero-initialised */
1740static void noinline 1842static void noinline ecb_cold
1741loop_init (EV_P_ unsigned int flags) 1843loop_init (EV_P_ unsigned int flags)
1742{ 1844{
1743 if (!backend) 1845 if (!backend)
1744 { 1846 {
1745 origflags = flags; 1847 origflags = flags;
1830#endif 1932#endif
1831 } 1933 }
1832} 1934}
1833 1935
1834/* free up a loop structure */ 1936/* free up a loop structure */
1835void 1937void ecb_cold
1836ev_loop_destroy (EV_P) 1938ev_loop_destroy (EV_P)
1837{ 1939{
1838 int i; 1940 int i;
1839 1941
1840#if EV_MULTIPLICITY 1942#if EV_MULTIPLICITY
1998 postfork = 0; 2100 postfork = 0;
1999} 2101}
2000 2102
2001#if EV_MULTIPLICITY 2103#if EV_MULTIPLICITY
2002 2104
2003struct ev_loop * 2105struct ev_loop * ecb_cold
2004ev_loop_new (unsigned int flags) 2106ev_loop_new (unsigned int flags)
2005{ 2107{
2006 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2108 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2007 2109
2008 memset (EV_A, 0, sizeof (struct ev_loop)); 2110 memset (EV_A, 0, sizeof (struct ev_loop));
2016} 2118}
2017 2119
2018#endif /* multiplicity */ 2120#endif /* multiplicity */
2019 2121
2020#if EV_VERIFY 2122#if EV_VERIFY
2021static void noinline 2123static void noinline ecb_cold
2022verify_watcher (EV_P_ W w) 2124verify_watcher (EV_P_ W w)
2023{ 2125{
2024 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 2126 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
2025 2127
2026 if (w->pending) 2128 if (w->pending)
2027 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 2129 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
2028} 2130}
2029 2131
2030static void noinline 2132static void noinline ecb_cold
2031verify_heap (EV_P_ ANHE *heap, int N) 2133verify_heap (EV_P_ ANHE *heap, int N)
2032{ 2134{
2033 int i; 2135 int i;
2034 2136
2035 for (i = HEAP0; i < N + HEAP0; ++i) 2137 for (i = HEAP0; i < N + HEAP0; ++i)
2040 2142
2041 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 2143 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
2042 } 2144 }
2043} 2145}
2044 2146
2045static void noinline 2147static void noinline ecb_cold
2046array_verify (EV_P_ W *ws, int cnt) 2148array_verify (EV_P_ W *ws, int cnt)
2047{ 2149{
2048 while (cnt--) 2150 while (cnt--)
2049 { 2151 {
2050 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 2152 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1));
2052 } 2154 }
2053} 2155}
2054#endif 2156#endif
2055 2157
2056#if EV_FEATURE_API 2158#if EV_FEATURE_API
2057void 2159void ecb_cold
2058ev_verify (EV_P) 2160ev_verify (EV_P)
2059{ 2161{
2060#if EV_VERIFY 2162#if EV_VERIFY
2061 int i; 2163 int i;
2062 WL w; 2164 WL w;
2128#endif 2230#endif
2129} 2231}
2130#endif 2232#endif
2131 2233
2132#if EV_MULTIPLICITY 2234#if EV_MULTIPLICITY
2133struct ev_loop * 2235struct ev_loop * ecb_cold
2134#else 2236#else
2135int 2237int
2136#endif 2238#endif
2137ev_default_loop (unsigned int flags) 2239ev_default_loop (unsigned int flags)
2138{ 2240{
2337 } 2439 }
2338} 2440}
2339 2441
2340/* simply recalculate all periodics */ 2442/* simply recalculate all periodics */
2341/* TODO: maybe ensure that at least one event happens when jumping forward? */ 2443/* TODO: maybe ensure that at least one event happens when jumping forward? */
2342static void noinline 2444static void noinline ecb_cold
2343periodics_reschedule (EV_P) 2445periodics_reschedule (EV_P)
2344{ 2446{
2345 int i; 2447 int i;
2346 2448
2347 /* adjust periodics after time jump */ 2449 /* adjust periodics after time jump */
2360 reheap (periodics, periodiccnt); 2462 reheap (periodics, periodiccnt);
2361} 2463}
2362#endif 2464#endif
2363 2465
2364/* adjust all timers by a given offset */ 2466/* adjust all timers by a given offset */
2365static void noinline 2467static void noinline ecb_cold
2366timers_reschedule (EV_P_ ev_tstamp adjust) 2468timers_reschedule (EV_P_ ev_tstamp adjust)
2367{ 2469{
2368 int i; 2470 int i;
2369 2471
2370 for (i = 0; i < timercnt; ++i) 2472 for (i = 0; i < timercnt; ++i)
2515 time_update (EV_A_ 1e100); 2617 time_update (EV_A_ 1e100);
2516 2618
2517 /* from now on, we want a pipe-wake-up */ 2619 /* from now on, we want a pipe-wake-up */
2518 pipe_write_wanted = 1; 2620 pipe_write_wanted = 1;
2519 2621
2622 ECB_MEMORY_FENCE; /* amke sure pipe_write_wanted is visible before we check for potential skips */
2623
2520 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 2624 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
2521 { 2625 {
2522 waittime = MAX_BLOCKTIME; 2626 waittime = MAX_BLOCKTIME;
2523 2627
2524 if (timercnt) 2628 if (timercnt)
2565#endif 2669#endif
2566 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ 2670 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2567 backend_poll (EV_A_ waittime); 2671 backend_poll (EV_A_ waittime);
2568 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 2672 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2569 2673
2570 pipe_write_wanted = 0; 2674 pipe_write_wanted = 0; /* just an optimsiation, no fence needed */
2571 2675
2572 if (pipe_write_skipped) 2676 if (pipe_write_skipped)
2573 { 2677 {
2574 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 2678 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
2575 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 2679 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3236 infy_wd (EV_A_ ev->wd, ev->wd, ev); 3340 infy_wd (EV_A_ ev->wd, ev->wd, ev);
3237 ofs += sizeof (struct inotify_event) + ev->len; 3341 ofs += sizeof (struct inotify_event) + ev->len;
3238 } 3342 }
3239} 3343}
3240 3344
3241inline_size void 3345inline_size void ecb_cold
3242ev_check_2625 (EV_P) 3346ev_check_2625 (EV_P)
3243{ 3347{
3244 /* kernels < 2.6.25 are borked 3348 /* kernels < 2.6.25 are borked
3245 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 3349 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
3246 */ 3350 */
3871} 3975}
3872 3976
3873/*****************************************************************************/ 3977/*****************************************************************************/
3874 3978
3875#if EV_WALK_ENABLE 3979#if EV_WALK_ENABLE
3876void 3980void ecb_cold
3877ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 3981ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w))
3878{ 3982{
3879 int i, j; 3983 int i, j;
3880 ev_watcher_list *wl, *wn; 3984 ev_watcher_list *wl, *wn;
3881 3985

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines