… | |
… | |
332 | # else |
332 | # else |
333 | # define EV_USE_LINUXAIO 0 |
333 | # define EV_USE_LINUXAIO 0 |
334 | # endif |
334 | # endif |
335 | #endif |
335 | #endif |
336 | |
336 | |
|
|
337 | #ifndef EV_USE_IOURING |
|
|
338 | # if __linux |
|
|
339 | # define EV_USE_IOURING 0 |
|
|
340 | # else |
|
|
341 | # define EV_USE_IOURING 0 |
|
|
342 | # endif |
|
|
343 | #endif |
|
|
344 | |
337 | #ifndef EV_USE_INOTIFY |
345 | #ifndef EV_USE_INOTIFY |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
346 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
347 | # define EV_USE_INOTIFY EV_FEATURE_OS |
340 | # else |
348 | # else |
341 | # define EV_USE_INOTIFY 0 |
349 | # define EV_USE_INOTIFY 0 |
… | |
… | |
406 | # include <sys/syscall.h> |
414 | # include <sys/syscall.h> |
407 | # ifdef SYS_clock_gettime |
415 | # ifdef SYS_clock_gettime |
408 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
416 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
409 | # undef EV_USE_MONOTONIC |
417 | # undef EV_USE_MONOTONIC |
410 | # define EV_USE_MONOTONIC 1 |
418 | # define EV_USE_MONOTONIC 1 |
|
|
419 | # define EV_NEED_SYSCALL 1 |
411 | # else |
420 | # else |
412 | # undef EV_USE_CLOCK_SYSCALL |
421 | # undef EV_USE_CLOCK_SYSCALL |
413 | # define EV_USE_CLOCK_SYSCALL 0 |
422 | # define EV_USE_CLOCK_SYSCALL 0 |
414 | # endif |
423 | # endif |
415 | #endif |
424 | #endif |
… | |
… | |
438 | # endif |
447 | # endif |
439 | #endif |
448 | #endif |
440 | |
449 | |
441 | #if EV_USE_LINUXAIO |
450 | #if EV_USE_LINUXAIO |
442 | # include <sys/syscall.h> |
451 | # include <sys/syscall.h> |
443 | # if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */ |
452 | # if SYS_io_getevents && EV_USE_EPOLL /* linuxaio backend requires epoll backend */ |
|
|
453 | # define EV_NEED_SYSCALL 1 |
|
|
454 | # else |
444 | # undef EV_USE_LINUXAIO |
455 | # undef EV_USE_LINUXAIO |
445 | # define EV_USE_LINUXAIO 0 |
456 | # define EV_USE_LINUXAIO 0 |
|
|
457 | # endif |
|
|
458 | #endif |
|
|
459 | |
|
|
460 | #if EV_USE_IOURING |
|
|
461 | # include <sys/syscall.h> |
|
|
462 | # if !SYS_io_uring_setup && __linux && !__alpha |
|
|
463 | # define SYS_io_uring_setup 425 |
|
|
464 | # define SYS_io_uring_enter 426 |
|
|
465 | # define SYS_io_uring_wregister 427 |
|
|
466 | # endif |
|
|
467 | # if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */ |
|
|
468 | # define EV_NEED_SYSCALL 1 |
|
|
469 | # else |
|
|
470 | # undef EV_USE_IOURING |
|
|
471 | # define EV_USE_IOURING 0 |
446 | # endif |
472 | # endif |
447 | #endif |
473 | #endif |
448 | |
474 | |
449 | #if EV_USE_INOTIFY |
475 | #if EV_USE_INOTIFY |
450 | # include <sys/statfs.h> |
476 | # include <sys/statfs.h> |
… | |
… | |
492 | uint32_t ssi_signo; |
518 | uint32_t ssi_signo; |
493 | char pad[128 - sizeof (uint32_t)]; |
519 | char pad[128 - sizeof (uint32_t)]; |
494 | }; |
520 | }; |
495 | #endif |
521 | #endif |
496 | |
522 | |
497 | /**/ |
523 | /*****************************************************************************/ |
498 | |
524 | |
499 | #if EV_VERIFY >= 3 |
525 | #if EV_VERIFY >= 3 |
500 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
526 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
501 | #else |
527 | #else |
502 | # define EV_FREQUENT_CHECK do { } while (0) |
528 | # define EV_FREQUENT_CHECK do { } while (0) |
… | |
… | |
507 | * This value is good at least till the year 4000. |
533 | * This value is good at least till the year 4000. |
508 | */ |
534 | */ |
509 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
535 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
510 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
536 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
511 | |
537 | |
512 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
538 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
513 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
539 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
514 | |
540 | |
|
|
541 | /* find a portable timestamp that is "always" in the future but fits into time_t. |
|
|
542 | * this is quite hard, and we are mostly guessing - we handle 32 bit signed/unsigned time_t, |
|
|
543 | * and sizes larger than 32 bit, and maybe the unlikely floating point time_t */ |
|
|
544 | #define EV_TSTAMP_HUGE \ |
|
|
545 | (sizeof (time_t) >= 8 ? 10000000000000. \ |
|
|
546 | : 0 < (time_t)4294967295 ? 4294967295. \ |
|
|
547 | : 2147483647.) \ |
|
|
548 | |
|
|
549 | #ifndef EV_TS_CONST |
|
|
550 | # define EV_TS_CONST(nv) nv |
|
|
551 | # define EV_TS_TO_MSEC(a) a * 1e3 + 0.9999 |
|
|
552 | # define EV_TS_FROM_USEC(us) us * 1e-6 |
515 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
553 | # define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
516 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
554 | # define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
|
|
555 | # define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e-6) |
|
|
556 | # define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e-9) |
|
|
557 | #endif |
517 | |
558 | |
518 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
559 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
519 | /* ECB.H BEGIN */ |
560 | /* ECB.H BEGIN */ |
520 | /* |
561 | /* |
521 | * libecb - http://software.schmorp.de/pkg/libecb |
562 | * libecb - http://software.schmorp.de/pkg/libecb |
… | |
… | |
1536 | /* ECB.H END */ |
1577 | /* ECB.H END */ |
1537 | |
1578 | |
1538 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1579 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1539 | /* if your architecture doesn't need memory fences, e.g. because it is |
1580 | /* if your architecture doesn't need memory fences, e.g. because it is |
1540 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
1581 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
1541 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
1582 | * from multiple threads, then you can define ECB_NO_THREADS when compiling |
1542 | * libev, in which cases the memory fences become nops. |
1583 | * libev, in which cases the memory fences become nops. |
1543 | * alternatively, you can remove this #error and link against libpthread, |
1584 | * alternatively, you can remove this #error and link against libpthread, |
1544 | * which will then provide the memory fences. |
1585 | * which will then provide the memory fences. |
1545 | */ |
1586 | */ |
1546 | # error "memory fences not defined for your architecture, please report" |
1587 | # error "memory fences not defined for your architecture, please report" |
… | |
… | |
1550 | # define ECB_MEMORY_FENCE do { } while (0) |
1591 | # define ECB_MEMORY_FENCE do { } while (0) |
1551 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1592 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1552 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1593 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1553 | #endif |
1594 | #endif |
1554 | |
1595 | |
1555 | #define expect_false(cond) ecb_expect_false (cond) |
|
|
1556 | #define expect_true(cond) ecb_expect_true (cond) |
|
|
1557 | #define noinline ecb_noinline |
|
|
1558 | |
|
|
1559 | #define inline_size ecb_inline |
1596 | #define inline_size ecb_inline |
1560 | |
1597 | |
1561 | #if EV_FEATURE_CODE |
1598 | #if EV_FEATURE_CODE |
1562 | # define inline_speed ecb_inline |
1599 | # define inline_speed ecb_inline |
1563 | #else |
1600 | #else |
1564 | # define inline_speed noinline static |
1601 | # define inline_speed ecb_noinline static |
1565 | #endif |
1602 | #endif |
|
|
1603 | |
|
|
1604 | /*****************************************************************************/ |
|
|
1605 | /* raw syscall wrappers */ |
|
|
1606 | |
|
|
1607 | #if EV_NEED_SYSCALL |
|
|
1608 | |
|
|
1609 | #include <sys/syscall.h> |
|
|
1610 | |
|
|
1611 | /* |
|
|
1612 | * define some syscall wrappers for common architectures |
|
|
1613 | * this is mostly for nice looks during debugging, not performance. |
|
|
1614 | * our syscalls return < 0, not == -1, on error. which is good |
|
|
1615 | * enough for linux aio. |
|
|
1616 | * TODO: arm is also common nowadays, maybe even mips and x86 |
|
|
1617 | * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove... |
|
|
1618 | */ |
|
|
1619 | #if __GNUC__ && __linux && ECB_AMD64 && !defined __OPTIMIZE_SIZE__ |
|
|
1620 | /* the costly errno access probably kills this for size optimisation */ |
|
|
1621 | |
|
|
1622 | #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5,arg6) \ |
|
|
1623 | ({ \ |
|
|
1624 | long res; \ |
|
|
1625 | register unsigned long r6 __asm__ ("r9" ); \ |
|
|
1626 | register unsigned long r5 __asm__ ("r8" ); \ |
|
|
1627 | register unsigned long r4 __asm__ ("r10"); \ |
|
|
1628 | register unsigned long r3 __asm__ ("rdx"); \ |
|
|
1629 | register unsigned long r2 __asm__ ("rsi"); \ |
|
|
1630 | register unsigned long r1 __asm__ ("rdi"); \ |
|
|
1631 | if (narg >= 6) r6 = (unsigned long)(arg6); \ |
|
|
1632 | if (narg >= 5) r5 = (unsigned long)(arg5); \ |
|
|
1633 | if (narg >= 4) r4 = (unsigned long)(arg4); \ |
|
|
1634 | if (narg >= 3) r3 = (unsigned long)(arg3); \ |
|
|
1635 | if (narg >= 2) r2 = (unsigned long)(arg2); \ |
|
|
1636 | if (narg >= 1) r1 = (unsigned long)(arg1); \ |
|
|
1637 | __asm__ __volatile__ ( \ |
|
|
1638 | "syscall\n\t" \ |
|
|
1639 | : "=a" (res) \ |
|
|
1640 | : "0" (nr), "r" (r1), "r" (r2), "r" (r3), "r" (r4), "r" (r5) \ |
|
|
1641 | : "cc", "r11", "cx", "memory"); \ |
|
|
1642 | errno = -res; \ |
|
|
1643 | res; \ |
|
|
1644 | }) |
|
|
1645 | |
|
|
1646 | #endif |
|
|
1647 | |
|
|
1648 | #ifdef ev_syscall |
|
|
1649 | #define ev_syscall0(nr) ev_syscall (nr, 0, 0, 0, 0, 0, 0, 0) |
|
|
1650 | #define ev_syscall1(nr,arg1) ev_syscall (nr, 1, arg1, 0, 0, 0, 0, 0) |
|
|
1651 | #define ev_syscall2(nr,arg1,arg2) ev_syscall (nr, 2, arg1, arg2, 0, 0, 0, 0) |
|
|
1652 | #define ev_syscall3(nr,arg1,arg2,arg3) ev_syscall (nr, 3, arg1, arg2, arg3, 0, 0, 0) |
|
|
1653 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) ev_syscall (nr, 3, arg1, arg2, arg3, arg4, 0, 0) |
|
|
1654 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) ev_syscall (nr, 5, arg1, arg2, arg3, arg4, arg5, 0) |
|
|
1655 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) ev_syscall (nr, 6, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1656 | #else |
|
|
1657 | #define ev_syscall0(nr) syscall (nr) |
|
|
1658 | #define ev_syscall1(nr,arg1) syscall (nr, arg1) |
|
|
1659 | #define ev_syscall2(nr,arg1,arg2) syscall (nr, arg1, arg2) |
|
|
1660 | #define ev_syscall3(nr,arg1,arg2,arg3) syscall (nr, arg1, arg2, arg3) |
|
|
1661 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) syscall (nr, arg1, arg2, arg3, arg4) |
|
|
1662 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) syscall (nr, arg1, arg2, arg3, arg4, arg5) |
|
|
1663 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) syscall (nr, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1664 | #endif |
|
|
1665 | |
|
|
1666 | #endif |
|
|
1667 | |
|
|
1668 | /*****************************************************************************/ |
1566 | |
1669 | |
1567 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1670 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1568 | |
1671 | |
1569 | #if EV_MINPRI == EV_MAXPRI |
1672 | #if EV_MINPRI == EV_MAXPRI |
1570 | # define ABSPRI(w) (((W)w), 0) |
1673 | # define ABSPRI(w) (((W)w), 0) |
… | |
… | |
1619 | #else |
1722 | #else |
1620 | |
1723 | |
1621 | #include <float.h> |
1724 | #include <float.h> |
1622 | |
1725 | |
1623 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1726 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1624 | noinline |
1727 | ecb_noinline |
1625 | static ev_tstamp |
1728 | static ev_tstamp |
1626 | ev_floor (ev_tstamp v) |
1729 | ev_floor (ev_tstamp v) |
1627 | { |
1730 | { |
1628 | /* the choice of shift factor is not terribly important */ |
1731 | /* the choice of shift factor is not terribly important */ |
1629 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1732 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1630 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1733 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1631 | #else |
1734 | #else |
1632 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1735 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1633 | #endif |
1736 | #endif |
1634 | |
1737 | |
|
|
1738 | /* special treatment for negative arguments */ |
|
|
1739 | if (ecb_expect_false (v < 0.)) |
|
|
1740 | { |
|
|
1741 | ev_tstamp f = -ev_floor (-v); |
|
|
1742 | |
|
|
1743 | return f - (f == v ? 0 : 1); |
|
|
1744 | } |
|
|
1745 | |
1635 | /* argument too large for an unsigned long? */ |
1746 | /* argument too large for an unsigned long? then reduce it */ |
1636 | if (expect_false (v >= shift)) |
1747 | if (ecb_expect_false (v >= shift)) |
1637 | { |
1748 | { |
1638 | ev_tstamp f; |
1749 | ev_tstamp f; |
1639 | |
1750 | |
1640 | if (v == v - 1.) |
1751 | if (v == v - 1.) |
1641 | return v; /* very large number */ |
1752 | return v; /* very large numbers are assumed to be integer */ |
1642 | |
1753 | |
1643 | f = shift * ev_floor (v * (1. / shift)); |
1754 | f = shift * ev_floor (v * (1. / shift)); |
1644 | return f + ev_floor (v - f); |
1755 | return f + ev_floor (v - f); |
1645 | } |
1756 | } |
1646 | |
1757 | |
1647 | /* special treatment for negative args? */ |
|
|
1648 | if (expect_false (v < 0.)) |
|
|
1649 | { |
|
|
1650 | ev_tstamp f = -ev_floor (-v); |
|
|
1651 | |
|
|
1652 | return f - (f == v ? 0 : 1); |
|
|
1653 | } |
|
|
1654 | |
|
|
1655 | /* fits into an unsigned long */ |
1758 | /* fits into an unsigned long */ |
1656 | return (unsigned long)v; |
1759 | return (unsigned long)v; |
1657 | } |
1760 | } |
1658 | |
1761 | |
1659 | #endif |
1762 | #endif |
… | |
… | |
1662 | |
1765 | |
1663 | #ifdef __linux |
1766 | #ifdef __linux |
1664 | # include <sys/utsname.h> |
1767 | # include <sys/utsname.h> |
1665 | #endif |
1768 | #endif |
1666 | |
1769 | |
1667 | noinline ecb_cold |
1770 | ecb_noinline ecb_cold |
1668 | static unsigned int |
1771 | static unsigned int |
1669 | ev_linux_version (void) |
1772 | ev_linux_version (void) |
1670 | { |
1773 | { |
1671 | #ifdef __linux |
1774 | #ifdef __linux |
1672 | unsigned int v = 0; |
1775 | unsigned int v = 0; |
… | |
… | |
1702 | } |
1805 | } |
1703 | |
1806 | |
1704 | /*****************************************************************************/ |
1807 | /*****************************************************************************/ |
1705 | |
1808 | |
1706 | #if EV_AVOID_STDIO |
1809 | #if EV_AVOID_STDIO |
1707 | noinline ecb_cold |
1810 | ecb_noinline ecb_cold |
1708 | static void |
1811 | static void |
1709 | ev_printerr (const char *msg) |
1812 | ev_printerr (const char *msg) |
1710 | { |
1813 | { |
1711 | write (STDERR_FILENO, msg, strlen (msg)); |
1814 | write (STDERR_FILENO, msg, strlen (msg)); |
1712 | } |
1815 | } |
… | |
… | |
1719 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1822 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1720 | { |
1823 | { |
1721 | syserr_cb = cb; |
1824 | syserr_cb = cb; |
1722 | } |
1825 | } |
1723 | |
1826 | |
1724 | noinline ecb_cold |
1827 | ecb_noinline ecb_cold |
1725 | static void |
1828 | static void |
1726 | ev_syserr (const char *msg) |
1829 | ev_syserr (const char *msg) |
1727 | { |
1830 | { |
1728 | if (!msg) |
1831 | if (!msg) |
1729 | msg = "(libev) system error"; |
1832 | msg = "(libev) system error"; |
… | |
… | |
1801 | { |
1904 | { |
1802 | WL head; |
1905 | WL head; |
1803 | unsigned char events; /* the events watched for */ |
1906 | unsigned char events; /* the events watched for */ |
1804 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1907 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1805 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1908 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1806 | unsigned char unused; |
1909 | unsigned char eflags; /* flags field for use by backends */ |
1807 | #if EV_USE_EPOLL |
1910 | #if EV_USE_EPOLL |
1808 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1911 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1809 | #endif |
1912 | #endif |
1810 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1913 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1811 | SOCKET handle; |
1914 | SOCKET handle; |
… | |
… | |
1865 | static struct ev_loop default_loop_struct; |
1968 | static struct ev_loop default_loop_struct; |
1866 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1969 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1867 | |
1970 | |
1868 | #else |
1971 | #else |
1869 | |
1972 | |
1870 | EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */ |
1973 | EV_API_DECL ev_tstamp ev_rt_now = EV_TS_CONST (0.); /* needs to be initialised to make it a definition despite extern */ |
1871 | #define VAR(name,decl) static decl; |
1974 | #define VAR(name,decl) static decl; |
1872 | #include "ev_vars.h" |
1975 | #include "ev_vars.h" |
1873 | #undef VAR |
1976 | #undef VAR |
1874 | |
1977 | |
1875 | static int ev_default_loop_ptr; |
1978 | static int ev_default_loop_ptr; |
1876 | |
1979 | |
1877 | #endif |
1980 | #endif |
1878 | |
1981 | |
1879 | #if EV_FEATURE_API |
1982 | #if EV_FEATURE_API |
1880 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
1983 | # define EV_RELEASE_CB if (ecb_expect_false (release_cb)) release_cb (EV_A) |
1881 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
1984 | # define EV_ACQUIRE_CB if (ecb_expect_false (acquire_cb)) acquire_cb (EV_A) |
1882 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
1985 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
1883 | #else |
1986 | #else |
1884 | # define EV_RELEASE_CB (void)0 |
1987 | # define EV_RELEASE_CB (void)0 |
1885 | # define EV_ACQUIRE_CB (void)0 |
1988 | # define EV_ACQUIRE_CB (void)0 |
1886 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
1989 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
… | |
… | |
1893 | #ifndef EV_HAVE_EV_TIME |
1996 | #ifndef EV_HAVE_EV_TIME |
1894 | ev_tstamp |
1997 | ev_tstamp |
1895 | ev_time (void) EV_NOEXCEPT |
1998 | ev_time (void) EV_NOEXCEPT |
1896 | { |
1999 | { |
1897 | #if EV_USE_REALTIME |
2000 | #if EV_USE_REALTIME |
1898 | if (expect_true (have_realtime)) |
2001 | if (ecb_expect_true (have_realtime)) |
1899 | { |
2002 | { |
1900 | struct timespec ts; |
2003 | struct timespec ts; |
1901 | clock_gettime (CLOCK_REALTIME, &ts); |
2004 | clock_gettime (CLOCK_REALTIME, &ts); |
1902 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2005 | return EV_TS_GET (ts); |
1903 | } |
2006 | } |
1904 | #endif |
2007 | #endif |
1905 | |
2008 | |
1906 | struct timeval tv; |
2009 | struct timeval tv; |
1907 | gettimeofday (&tv, 0); |
2010 | gettimeofday (&tv, 0); |
1908 | return tv.tv_sec + tv.tv_usec * 1e-6; |
2011 | return EV_TV_GET (tv); |
1909 | } |
2012 | } |
1910 | #endif |
2013 | #endif |
1911 | |
2014 | |
1912 | inline_size ev_tstamp |
2015 | inline_size ev_tstamp |
1913 | get_clock (void) |
2016 | get_clock (void) |
1914 | { |
2017 | { |
1915 | #if EV_USE_MONOTONIC |
2018 | #if EV_USE_MONOTONIC |
1916 | if (expect_true (have_monotonic)) |
2019 | if (ecb_expect_true (have_monotonic)) |
1917 | { |
2020 | { |
1918 | struct timespec ts; |
2021 | struct timespec ts; |
1919 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2022 | clock_gettime (CLOCK_MONOTONIC, &ts); |
1920 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2023 | return EV_TS_GET (ts); |
1921 | } |
2024 | } |
1922 | #endif |
2025 | #endif |
1923 | |
2026 | |
1924 | return ev_time (); |
2027 | return ev_time (); |
1925 | } |
2028 | } |
… | |
… | |
1933 | #endif |
2036 | #endif |
1934 | |
2037 | |
1935 | void |
2038 | void |
1936 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
2039 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1937 | { |
2040 | { |
1938 | if (delay > 0.) |
2041 | if (delay > EV_TS_CONST (0.)) |
1939 | { |
2042 | { |
1940 | #if EV_USE_NANOSLEEP |
2043 | #if EV_USE_NANOSLEEP |
1941 | struct timespec ts; |
2044 | struct timespec ts; |
1942 | |
2045 | |
1943 | EV_TS_SET (ts, delay); |
2046 | EV_TS_SET (ts, delay); |
1944 | nanosleep (&ts, 0); |
2047 | nanosleep (&ts, 0); |
1945 | #elif defined _WIN32 |
2048 | #elif defined _WIN32 |
1946 | /* maybe this should round up, as ms is very low resolution */ |
2049 | /* maybe this should round up, as ms is very low resolution */ |
1947 | /* compared to select (µs) or nanosleep (ns) */ |
2050 | /* compared to select (µs) or nanosleep (ns) */ |
1948 | Sleep ((unsigned long)(delay * 1e3)); |
2051 | Sleep ((unsigned long)(EV_TS_TO_MSEC (delay))); |
1949 | #else |
2052 | #else |
1950 | struct timeval tv; |
2053 | struct timeval tv; |
1951 | |
2054 | |
1952 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
2055 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1953 | /* something not guaranteed by newer posix versions, but guaranteed */ |
2056 | /* something not guaranteed by newer posix versions, but guaranteed */ |
… | |
… | |
1983 | } |
2086 | } |
1984 | |
2087 | |
1985 | return ncur; |
2088 | return ncur; |
1986 | } |
2089 | } |
1987 | |
2090 | |
1988 | noinline ecb_cold |
2091 | ecb_noinline ecb_cold |
1989 | static void * |
2092 | static void * |
1990 | array_realloc (int elem, void *base, int *cur, int cnt) |
2093 | array_realloc (int elem, void *base, int *cur, int cnt) |
1991 | { |
2094 | { |
1992 | *cur = array_nextsize (elem, *cur, cnt); |
2095 | *cur = array_nextsize (elem, *cur, cnt); |
1993 | return ev_realloc (base, elem * *cur); |
2096 | return ev_realloc (base, elem * *cur); |
… | |
… | |
1997 | |
2100 | |
1998 | #define array_needsize_zerofill(base,offset,count) \ |
2101 | #define array_needsize_zerofill(base,offset,count) \ |
1999 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
2102 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
2000 | |
2103 | |
2001 | #define array_needsize(type,base,cur,cnt,init) \ |
2104 | #define array_needsize(type,base,cur,cnt,init) \ |
2002 | if (expect_false ((cnt) > (cur))) \ |
2105 | if (ecb_expect_false ((cnt) > (cur))) \ |
2003 | { \ |
2106 | { \ |
2004 | ecb_unused int ocur_ = (cur); \ |
2107 | ecb_unused int ocur_ = (cur); \ |
2005 | (base) = (type *)array_realloc \ |
2108 | (base) = (type *)array_realloc \ |
2006 | (sizeof (type), (base), &(cur), (cnt)); \ |
2109 | (sizeof (type), (base), &(cur), (cnt)); \ |
2007 | init ((base), ocur_, ((cur) - ocur_)); \ |
2110 | init ((base), ocur_, ((cur) - ocur_)); \ |
… | |
… | |
2021 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2124 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2022 | |
2125 | |
2023 | /*****************************************************************************/ |
2126 | /*****************************************************************************/ |
2024 | |
2127 | |
2025 | /* dummy callback for pending events */ |
2128 | /* dummy callback for pending events */ |
2026 | noinline |
2129 | ecb_noinline |
2027 | static void |
2130 | static void |
2028 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2131 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2029 | { |
2132 | { |
2030 | } |
2133 | } |
2031 | |
2134 | |
2032 | noinline |
2135 | ecb_noinline |
2033 | void |
2136 | void |
2034 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2137 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2035 | { |
2138 | { |
2036 | W w_ = (W)w; |
2139 | W w_ = (W)w; |
2037 | int pri = ABSPRI (w_); |
2140 | int pri = ABSPRI (w_); |
2038 | |
2141 | |
2039 | if (expect_false (w_->pending)) |
2142 | if (ecb_expect_false (w_->pending)) |
2040 | pendings [pri][w_->pending - 1].events |= revents; |
2143 | pendings [pri][w_->pending - 1].events |= revents; |
2041 | else |
2144 | else |
2042 | { |
2145 | { |
2043 | w_->pending = ++pendingcnt [pri]; |
2146 | w_->pending = ++pendingcnt [pri]; |
2044 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2147 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
… | |
… | |
2095 | inline_speed void |
2198 | inline_speed void |
2096 | fd_event (EV_P_ int fd, int revents) |
2199 | fd_event (EV_P_ int fd, int revents) |
2097 | { |
2200 | { |
2098 | ANFD *anfd = anfds + fd; |
2201 | ANFD *anfd = anfds + fd; |
2099 | |
2202 | |
2100 | if (expect_true (!anfd->reify)) |
2203 | if (ecb_expect_true (!anfd->reify)) |
2101 | fd_event_nocheck (EV_A_ fd, revents); |
2204 | fd_event_nocheck (EV_A_ fd, revents); |
2102 | } |
2205 | } |
2103 | |
2206 | |
2104 | void |
2207 | void |
2105 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2208 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
… | |
… | |
2149 | unsigned char o_events = anfd->events; |
2252 | unsigned char o_events = anfd->events; |
2150 | unsigned char o_reify = anfd->reify; |
2253 | unsigned char o_reify = anfd->reify; |
2151 | |
2254 | |
2152 | anfd->reify = 0; |
2255 | anfd->reify = 0; |
2153 | |
2256 | |
2154 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2257 | /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2155 | { |
2258 | { |
2156 | anfd->events = 0; |
2259 | anfd->events = 0; |
2157 | |
2260 | |
2158 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2261 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2159 | anfd->events |= (unsigned char)w->events; |
2262 | anfd->events |= (unsigned char)w->events; |
… | |
… | |
2175 | fd_change (EV_P_ int fd, int flags) |
2278 | fd_change (EV_P_ int fd, int flags) |
2176 | { |
2279 | { |
2177 | unsigned char reify = anfds [fd].reify; |
2280 | unsigned char reify = anfds [fd].reify; |
2178 | anfds [fd].reify |= flags; |
2281 | anfds [fd].reify |= flags; |
2179 | |
2282 | |
2180 | if (expect_true (!reify)) |
2283 | if (ecb_expect_true (!reify)) |
2181 | { |
2284 | { |
2182 | ++fdchangecnt; |
2285 | ++fdchangecnt; |
2183 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2286 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2184 | fdchanges [fdchangecnt - 1] = fd; |
2287 | fdchanges [fdchangecnt - 1] = fd; |
2185 | } |
2288 | } |
… | |
… | |
2208 | return fcntl (fd, F_GETFD) != -1; |
2311 | return fcntl (fd, F_GETFD) != -1; |
2209 | #endif |
2312 | #endif |
2210 | } |
2313 | } |
2211 | |
2314 | |
2212 | /* called on EBADF to verify fds */ |
2315 | /* called on EBADF to verify fds */ |
2213 | noinline ecb_cold |
2316 | ecb_noinline ecb_cold |
2214 | static void |
2317 | static void |
2215 | fd_ebadf (EV_P) |
2318 | fd_ebadf (EV_P) |
2216 | { |
2319 | { |
2217 | int fd; |
2320 | int fd; |
2218 | |
2321 | |
… | |
… | |
2221 | if (!fd_valid (fd) && errno == EBADF) |
2324 | if (!fd_valid (fd) && errno == EBADF) |
2222 | fd_kill (EV_A_ fd); |
2325 | fd_kill (EV_A_ fd); |
2223 | } |
2326 | } |
2224 | |
2327 | |
2225 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2328 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2226 | noinline ecb_cold |
2329 | ecb_noinline ecb_cold |
2227 | static void |
2330 | static void |
2228 | fd_enomem (EV_P) |
2331 | fd_enomem (EV_P) |
2229 | { |
2332 | { |
2230 | int fd; |
2333 | int fd; |
2231 | |
2334 | |
… | |
… | |
2236 | break; |
2339 | break; |
2237 | } |
2340 | } |
2238 | } |
2341 | } |
2239 | |
2342 | |
2240 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2343 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2241 | noinline |
2344 | ecb_noinline |
2242 | static void |
2345 | static void |
2243 | fd_rearm_all (EV_P) |
2346 | fd_rearm_all (EV_P) |
2244 | { |
2347 | { |
2245 | int fd; |
2348 | int fd; |
2246 | |
2349 | |
… | |
… | |
2300 | ev_tstamp minat; |
2403 | ev_tstamp minat; |
2301 | ANHE *minpos; |
2404 | ANHE *minpos; |
2302 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2405 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2303 | |
2406 | |
2304 | /* find minimum child */ |
2407 | /* find minimum child */ |
2305 | if (expect_true (pos + DHEAP - 1 < E)) |
2408 | if (ecb_expect_true (pos + DHEAP - 1 < E)) |
2306 | { |
2409 | { |
2307 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2410 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2308 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2411 | if ( minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2309 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2412 | if ( minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2310 | if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2413 | if ( minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2311 | } |
2414 | } |
2312 | else if (pos < E) |
2415 | else if (pos < E) |
2313 | { |
2416 | { |
2314 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2417 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2315 | if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2418 | if (pos + 1 < E && minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2316 | if (pos + 2 < E && ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2419 | if (pos + 2 < E && minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2317 | if (pos + 3 < E && ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2420 | if (pos + 3 < E && minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2318 | } |
2421 | } |
2319 | else |
2422 | else |
2320 | break; |
2423 | break; |
2321 | |
2424 | |
2322 | if (ANHE_at (he) <= minat) |
2425 | if (ANHE_at (he) <= minat) |
… | |
… | |
2330 | |
2433 | |
2331 | heap [k] = he; |
2434 | heap [k] = he; |
2332 | ev_active (ANHE_w (he)) = k; |
2435 | ev_active (ANHE_w (he)) = k; |
2333 | } |
2436 | } |
2334 | |
2437 | |
2335 | #else /* 4HEAP */ |
2438 | #else /* not 4HEAP */ |
2336 | |
2439 | |
2337 | #define HEAP0 1 |
2440 | #define HEAP0 1 |
2338 | #define HPARENT(k) ((k) >> 1) |
2441 | #define HPARENT(k) ((k) >> 1) |
2339 | #define UPHEAP_DONE(p,k) (!(p)) |
2442 | #define UPHEAP_DONE(p,k) (!(p)) |
2340 | |
2443 | |
… | |
… | |
2428 | |
2531 | |
2429 | /*****************************************************************************/ |
2532 | /*****************************************************************************/ |
2430 | |
2533 | |
2431 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2534 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2432 | |
2535 | |
2433 | noinline ecb_cold |
2536 | ecb_noinline ecb_cold |
2434 | static void |
2537 | static void |
2435 | evpipe_init (EV_P) |
2538 | evpipe_init (EV_P) |
2436 | { |
2539 | { |
2437 | if (!ev_is_active (&pipe_w)) |
2540 | if (!ev_is_active (&pipe_w)) |
2438 | { |
2541 | { |
… | |
… | |
2479 | inline_speed void |
2582 | inline_speed void |
2480 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2583 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2481 | { |
2584 | { |
2482 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2585 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2483 | |
2586 | |
2484 | if (expect_true (*flag)) |
2587 | if (ecb_expect_true (*flag)) |
2485 | return; |
2588 | return; |
2486 | |
2589 | |
2487 | *flag = 1; |
2590 | *flag = 1; |
2488 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2591 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2489 | |
2592 | |
… | |
… | |
2566 | sig_pending = 0; |
2669 | sig_pending = 0; |
2567 | |
2670 | |
2568 | ECB_MEMORY_FENCE; |
2671 | ECB_MEMORY_FENCE; |
2569 | |
2672 | |
2570 | for (i = EV_NSIG - 1; i--; ) |
2673 | for (i = EV_NSIG - 1; i--; ) |
2571 | if (expect_false (signals [i].pending)) |
2674 | if (ecb_expect_false (signals [i].pending)) |
2572 | ev_feed_signal_event (EV_A_ i + 1); |
2675 | ev_feed_signal_event (EV_A_ i + 1); |
2573 | } |
2676 | } |
2574 | #endif |
2677 | #endif |
2575 | |
2678 | |
2576 | #if EV_ASYNC_ENABLE |
2679 | #if EV_ASYNC_ENABLE |
… | |
… | |
2617 | #endif |
2720 | #endif |
2618 | |
2721 | |
2619 | ev_feed_signal (signum); |
2722 | ev_feed_signal (signum); |
2620 | } |
2723 | } |
2621 | |
2724 | |
2622 | noinline |
2725 | ecb_noinline |
2623 | void |
2726 | void |
2624 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2727 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2625 | { |
2728 | { |
2626 | WL w; |
2729 | WL w; |
2627 | |
2730 | |
2628 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2731 | if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG)) |
2629 | return; |
2732 | return; |
2630 | |
2733 | |
2631 | --signum; |
2734 | --signum; |
2632 | |
2735 | |
2633 | #if EV_MULTIPLICITY |
2736 | #if EV_MULTIPLICITY |
2634 | /* it is permissible to try to feed a signal to the wrong loop */ |
2737 | /* it is permissible to try to feed a signal to the wrong loop */ |
2635 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
2738 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
2636 | |
2739 | |
2637 | if (expect_false (signals [signum].loop != EV_A)) |
2740 | if (ecb_expect_false (signals [signum].loop != EV_A)) |
2638 | return; |
2741 | return; |
2639 | #endif |
2742 | #endif |
2640 | |
2743 | |
2641 | signals [signum].pending = 0; |
2744 | signals [signum].pending = 0; |
2642 | ECB_MEMORY_FENCE_RELEASE; |
2745 | ECB_MEMORY_FENCE_RELEASE; |
… | |
… | |
2741 | # include "ev_epoll.c" |
2844 | # include "ev_epoll.c" |
2742 | #endif |
2845 | #endif |
2743 | #if EV_USE_LINUXAIO |
2846 | #if EV_USE_LINUXAIO |
2744 | # include "ev_linuxaio.c" |
2847 | # include "ev_linuxaio.c" |
2745 | #endif |
2848 | #endif |
|
|
2849 | #if EV_USE_IOURING |
|
|
2850 | # include "ev_iouring.c" |
|
|
2851 | #endif |
2746 | #if EV_USE_POLL |
2852 | #if EV_USE_POLL |
2747 | # include "ev_poll.c" |
2853 | # include "ev_poll.c" |
2748 | #endif |
2854 | #endif |
2749 | #if EV_USE_SELECT |
2855 | #if EV_USE_SELECT |
2750 | # include "ev_select.c" |
2856 | # include "ev_select.c" |
… | |
… | |
2782 | |
2888 | |
2783 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2889 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2784 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2890 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2785 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2891 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2786 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2892 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
|
|
2893 | if (EV_USE_IOURING ) flags |= EVBACKEND_IOURING; |
2787 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2894 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2788 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2895 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2789 | |
2896 | |
2790 | return flags; |
2897 | return flags; |
2791 | } |
2898 | } |
… | |
… | |
2812 | |
2919 | |
2813 | /* TODO: linuxaio is very experimental */ |
2920 | /* TODO: linuxaio is very experimental */ |
2814 | #if !EV_RECOMMEND_LINUXAIO |
2921 | #if !EV_RECOMMEND_LINUXAIO |
2815 | flags &= ~EVBACKEND_LINUXAIO; |
2922 | flags &= ~EVBACKEND_LINUXAIO; |
2816 | #endif |
2923 | #endif |
|
|
2924 | /* TODO: linuxaio is super experimental */ |
|
|
2925 | #if !EV_RECOMMEND_IOURING |
|
|
2926 | flags &= ~EVBACKEND_IOURING; |
|
|
2927 | #endif |
2817 | |
2928 | |
2818 | return flags; |
2929 | return flags; |
2819 | } |
2930 | } |
2820 | |
2931 | |
2821 | ecb_cold |
2932 | ecb_cold |
… | |
… | |
2826 | |
2937 | |
2827 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2938 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2828 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2939 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2829 | flags &= ~EVBACKEND_EPOLL; |
2940 | flags &= ~EVBACKEND_EPOLL; |
2830 | |
2941 | |
|
|
2942 | /* EVBACKEND_LINUXAIO is theoretically embeddable, but suffers from a performance overhead */ |
|
|
2943 | |
|
|
2944 | /* EVBACKEND_IOURING is practically embeddable, but the current implementation is not |
|
|
2945 | * because our backend_fd is the epoll fd we need as fallback. |
|
|
2946 | * if the kernel ever is fixed, this might change... |
|
|
2947 | */ |
|
|
2948 | |
2831 | return flags; |
2949 | return flags; |
2832 | } |
2950 | } |
2833 | |
2951 | |
2834 | unsigned int |
2952 | unsigned int |
2835 | ev_backend (EV_P) EV_NOEXCEPT |
2953 | ev_backend (EV_P) EV_NOEXCEPT |
… | |
… | |
2887 | acquire_cb = acquire; |
3005 | acquire_cb = acquire; |
2888 | } |
3006 | } |
2889 | #endif |
3007 | #endif |
2890 | |
3008 | |
2891 | /* initialise a loop structure, must be zero-initialised */ |
3009 | /* initialise a loop structure, must be zero-initialised */ |
2892 | noinline ecb_cold |
3010 | ecb_noinline ecb_cold |
2893 | static void |
3011 | static void |
2894 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
3012 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2895 | { |
3013 | { |
2896 | if (!backend) |
3014 | if (!backend) |
2897 | { |
3015 | { |
… | |
… | |
2965 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
3083 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2966 | #endif |
3084 | #endif |
2967 | #if EV_USE_KQUEUE |
3085 | #if EV_USE_KQUEUE |
2968 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
3086 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
2969 | #endif |
3087 | #endif |
|
|
3088 | #if EV_USE_IOURING |
|
|
3089 | if (!backend && (flags & EVBACKEND_IOURING )) backend = iouring_init (EV_A_ flags); |
|
|
3090 | #endif |
2970 | #if EV_USE_LINUXAIO |
3091 | #if EV_USE_LINUXAIO |
2971 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
3092 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2972 | #endif |
3093 | #endif |
2973 | #if EV_USE_EPOLL |
3094 | #if EV_USE_EPOLL |
2974 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
3095 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
… | |
… | |
3002 | return; |
3123 | return; |
3003 | #endif |
3124 | #endif |
3004 | |
3125 | |
3005 | #if EV_CLEANUP_ENABLE |
3126 | #if EV_CLEANUP_ENABLE |
3006 | /* queue cleanup watchers (and execute them) */ |
3127 | /* queue cleanup watchers (and execute them) */ |
3007 | if (expect_false (cleanupcnt)) |
3128 | if (ecb_expect_false (cleanupcnt)) |
3008 | { |
3129 | { |
3009 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
3130 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
3010 | EV_INVOKE_PENDING; |
3131 | EV_INVOKE_PENDING; |
3011 | } |
3132 | } |
3012 | #endif |
3133 | #endif |
… | |
… | |
3047 | #if EV_USE_PORT |
3168 | #if EV_USE_PORT |
3048 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3169 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3049 | #endif |
3170 | #endif |
3050 | #if EV_USE_KQUEUE |
3171 | #if EV_USE_KQUEUE |
3051 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
3172 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3173 | #endif |
|
|
3174 | #if EV_USE_IOURING |
|
|
3175 | if (backend == EVBACKEND_IOURING ) iouring_destroy (EV_A); |
3052 | #endif |
3176 | #endif |
3053 | #if EV_USE_LINUXAIO |
3177 | #if EV_USE_LINUXAIO |
3054 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3178 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3055 | #endif |
3179 | #endif |
3056 | #if EV_USE_EPOLL |
3180 | #if EV_USE_EPOLL |
… | |
… | |
3115 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3239 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3116 | #endif |
3240 | #endif |
3117 | #if EV_USE_KQUEUE |
3241 | #if EV_USE_KQUEUE |
3118 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
3242 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
3119 | #endif |
3243 | #endif |
|
|
3244 | #if EV_USE_IOURING |
|
|
3245 | if (backend == EVBACKEND_IOURING ) iouring_fork (EV_A); |
|
|
3246 | #endif |
3120 | #if EV_USE_LINUXAIO |
3247 | #if EV_USE_LINUXAIO |
3121 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3248 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3122 | #endif |
3249 | #endif |
3123 | #if EV_USE_EPOLL |
3250 | #if EV_USE_EPOLL |
3124 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3251 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
… | |
… | |
3166 | } |
3293 | } |
3167 | |
3294 | |
3168 | #endif /* multiplicity */ |
3295 | #endif /* multiplicity */ |
3169 | |
3296 | |
3170 | #if EV_VERIFY |
3297 | #if EV_VERIFY |
3171 | noinline ecb_cold |
3298 | ecb_noinline ecb_cold |
3172 | static void |
3299 | static void |
3173 | verify_watcher (EV_P_ W w) |
3300 | verify_watcher (EV_P_ W w) |
3174 | { |
3301 | { |
3175 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3302 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3176 | |
3303 | |
3177 | if (w->pending) |
3304 | if (w->pending) |
3178 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3305 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3179 | } |
3306 | } |
3180 | |
3307 | |
3181 | noinline ecb_cold |
3308 | ecb_noinline ecb_cold |
3182 | static void |
3309 | static void |
3183 | verify_heap (EV_P_ ANHE *heap, int N) |
3310 | verify_heap (EV_P_ ANHE *heap, int N) |
3184 | { |
3311 | { |
3185 | int i; |
3312 | int i; |
3186 | |
3313 | |
… | |
… | |
3192 | |
3319 | |
3193 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3320 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3194 | } |
3321 | } |
3195 | } |
3322 | } |
3196 | |
3323 | |
3197 | noinline ecb_cold |
3324 | ecb_noinline ecb_cold |
3198 | static void |
3325 | static void |
3199 | array_verify (EV_P_ W *ws, int cnt) |
3326 | array_verify (EV_P_ W *ws, int cnt) |
3200 | { |
3327 | { |
3201 | while (cnt--) |
3328 | while (cnt--) |
3202 | { |
3329 | { |
… | |
… | |
3351 | count += pendingcnt [pri]; |
3478 | count += pendingcnt [pri]; |
3352 | |
3479 | |
3353 | return count; |
3480 | return count; |
3354 | } |
3481 | } |
3355 | |
3482 | |
3356 | noinline |
3483 | ecb_noinline |
3357 | void |
3484 | void |
3358 | ev_invoke_pending (EV_P) |
3485 | ev_invoke_pending (EV_P) |
3359 | { |
3486 | { |
3360 | pendingpri = NUMPRI; |
3487 | pendingpri = NUMPRI; |
3361 | |
3488 | |
… | |
… | |
3380 | /* make idle watchers pending. this handles the "call-idle */ |
3507 | /* make idle watchers pending. this handles the "call-idle */ |
3381 | /* only when higher priorities are idle" logic */ |
3508 | /* only when higher priorities are idle" logic */ |
3382 | inline_size void |
3509 | inline_size void |
3383 | idle_reify (EV_P) |
3510 | idle_reify (EV_P) |
3384 | { |
3511 | { |
3385 | if (expect_false (idleall)) |
3512 | if (ecb_expect_false (idleall)) |
3386 | { |
3513 | { |
3387 | int pri; |
3514 | int pri; |
3388 | |
3515 | |
3389 | for (pri = NUMPRI; pri--; ) |
3516 | for (pri = NUMPRI; pri--; ) |
3390 | { |
3517 | { |
… | |
… | |
3420 | { |
3547 | { |
3421 | ev_at (w) += w->repeat; |
3548 | ev_at (w) += w->repeat; |
3422 | if (ev_at (w) < mn_now) |
3549 | if (ev_at (w) < mn_now) |
3423 | ev_at (w) = mn_now; |
3550 | ev_at (w) = mn_now; |
3424 | |
3551 | |
3425 | assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
3552 | assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > EV_TS_CONST (0.))); |
3426 | |
3553 | |
3427 | ANHE_at_cache (timers [HEAP0]); |
3554 | ANHE_at_cache (timers [HEAP0]); |
3428 | downheap (timers, timercnt, HEAP0); |
3555 | downheap (timers, timercnt, HEAP0); |
3429 | } |
3556 | } |
3430 | else |
3557 | else |
… | |
… | |
3439 | } |
3566 | } |
3440 | } |
3567 | } |
3441 | |
3568 | |
3442 | #if EV_PERIODIC_ENABLE |
3569 | #if EV_PERIODIC_ENABLE |
3443 | |
3570 | |
3444 | noinline |
3571 | ecb_noinline |
3445 | static void |
3572 | static void |
3446 | periodic_recalc (EV_P_ ev_periodic *w) |
3573 | periodic_recalc (EV_P_ ev_periodic *w) |
3447 | { |
3574 | { |
3448 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3575 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3449 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3576 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
… | |
… | |
3452 | while (at <= ev_rt_now) |
3579 | while (at <= ev_rt_now) |
3453 | { |
3580 | { |
3454 | ev_tstamp nat = at + w->interval; |
3581 | ev_tstamp nat = at + w->interval; |
3455 | |
3582 | |
3456 | /* when resolution fails us, we use ev_rt_now */ |
3583 | /* when resolution fails us, we use ev_rt_now */ |
3457 | if (expect_false (nat == at)) |
3584 | if (ecb_expect_false (nat == at)) |
3458 | { |
3585 | { |
3459 | at = ev_rt_now; |
3586 | at = ev_rt_now; |
3460 | break; |
3587 | break; |
3461 | } |
3588 | } |
3462 | |
3589 | |
… | |
… | |
3508 | } |
3635 | } |
3509 | } |
3636 | } |
3510 | |
3637 | |
3511 | /* simply recalculate all periodics */ |
3638 | /* simply recalculate all periodics */ |
3512 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3639 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3513 | noinline ecb_cold |
3640 | ecb_noinline ecb_cold |
3514 | static void |
3641 | static void |
3515 | periodics_reschedule (EV_P) |
3642 | periodics_reschedule (EV_P) |
3516 | { |
3643 | { |
3517 | int i; |
3644 | int i; |
3518 | |
3645 | |
… | |
… | |
3532 | reheap (periodics, periodiccnt); |
3659 | reheap (periodics, periodiccnt); |
3533 | } |
3660 | } |
3534 | #endif |
3661 | #endif |
3535 | |
3662 | |
3536 | /* adjust all timers by a given offset */ |
3663 | /* adjust all timers by a given offset */ |
3537 | noinline ecb_cold |
3664 | ecb_noinline ecb_cold |
3538 | static void |
3665 | static void |
3539 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3666 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3540 | { |
3667 | { |
3541 | int i; |
3668 | int i; |
3542 | |
3669 | |
… | |
… | |
3552 | /* also detect if there was a timejump, and act accordingly */ |
3679 | /* also detect if there was a timejump, and act accordingly */ |
3553 | inline_speed void |
3680 | inline_speed void |
3554 | time_update (EV_P_ ev_tstamp max_block) |
3681 | time_update (EV_P_ ev_tstamp max_block) |
3555 | { |
3682 | { |
3556 | #if EV_USE_MONOTONIC |
3683 | #if EV_USE_MONOTONIC |
3557 | if (expect_true (have_monotonic)) |
3684 | if (ecb_expect_true (have_monotonic)) |
3558 | { |
3685 | { |
3559 | int i; |
3686 | int i; |
3560 | ev_tstamp odiff = rtmn_diff; |
3687 | ev_tstamp odiff = rtmn_diff; |
3561 | |
3688 | |
3562 | mn_now = get_clock (); |
3689 | mn_now = get_clock (); |
3563 | |
3690 | |
3564 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3691 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3565 | /* interpolate in the meantime */ |
3692 | /* interpolate in the meantime */ |
3566 | if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) |
3693 | if (ecb_expect_true (mn_now - now_floor < EV_TS_CONST (MIN_TIMEJUMP * .5))) |
3567 | { |
3694 | { |
3568 | ev_rt_now = rtmn_diff + mn_now; |
3695 | ev_rt_now = rtmn_diff + mn_now; |
3569 | return; |
3696 | return; |
3570 | } |
3697 | } |
3571 | |
3698 | |
… | |
… | |
3585 | ev_tstamp diff; |
3712 | ev_tstamp diff; |
3586 | rtmn_diff = ev_rt_now - mn_now; |
3713 | rtmn_diff = ev_rt_now - mn_now; |
3587 | |
3714 | |
3588 | diff = odiff - rtmn_diff; |
3715 | diff = odiff - rtmn_diff; |
3589 | |
3716 | |
3590 | if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) |
3717 | if (ecb_expect_true ((diff < EV_TS_CONST (0.) ? -diff : diff) < EV_TS_CONST (MIN_TIMEJUMP))) |
3591 | return; /* all is well */ |
3718 | return; /* all is well */ |
3592 | |
3719 | |
3593 | ev_rt_now = ev_time (); |
3720 | ev_rt_now = ev_time (); |
3594 | mn_now = get_clock (); |
3721 | mn_now = get_clock (); |
3595 | now_floor = mn_now; |
3722 | now_floor = mn_now; |
… | |
… | |
3604 | else |
3731 | else |
3605 | #endif |
3732 | #endif |
3606 | { |
3733 | { |
3607 | ev_rt_now = ev_time (); |
3734 | ev_rt_now = ev_time (); |
3608 | |
3735 | |
3609 | if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) |
3736 | if (ecb_expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + EV_TS_CONST (MIN_TIMEJUMP))) |
3610 | { |
3737 | { |
3611 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
3738 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
3612 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3739 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3613 | #if EV_PERIODIC_ENABLE |
3740 | #if EV_PERIODIC_ENABLE |
3614 | periodics_reschedule (EV_A); |
3741 | periodics_reschedule (EV_A); |
… | |
… | |
3637 | #if EV_VERIFY >= 2 |
3764 | #if EV_VERIFY >= 2 |
3638 | ev_verify (EV_A); |
3765 | ev_verify (EV_A); |
3639 | #endif |
3766 | #endif |
3640 | |
3767 | |
3641 | #ifndef _WIN32 |
3768 | #ifndef _WIN32 |
3642 | if (expect_false (curpid)) /* penalise the forking check even more */ |
3769 | if (ecb_expect_false (curpid)) /* penalise the forking check even more */ |
3643 | if (expect_false (getpid () != curpid)) |
3770 | if (ecb_expect_false (getpid () != curpid)) |
3644 | { |
3771 | { |
3645 | curpid = getpid (); |
3772 | curpid = getpid (); |
3646 | postfork = 1; |
3773 | postfork = 1; |
3647 | } |
3774 | } |
3648 | #endif |
3775 | #endif |
3649 | |
3776 | |
3650 | #if EV_FORK_ENABLE |
3777 | #if EV_FORK_ENABLE |
3651 | /* we might have forked, so queue fork handlers */ |
3778 | /* we might have forked, so queue fork handlers */ |
3652 | if (expect_false (postfork)) |
3779 | if (ecb_expect_false (postfork)) |
3653 | if (forkcnt) |
3780 | if (forkcnt) |
3654 | { |
3781 | { |
3655 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3782 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3656 | EV_INVOKE_PENDING; |
3783 | EV_INVOKE_PENDING; |
3657 | } |
3784 | } |
3658 | #endif |
3785 | #endif |
3659 | |
3786 | |
3660 | #if EV_PREPARE_ENABLE |
3787 | #if EV_PREPARE_ENABLE |
3661 | /* queue prepare watchers (and execute them) */ |
3788 | /* queue prepare watchers (and execute them) */ |
3662 | if (expect_false (preparecnt)) |
3789 | if (ecb_expect_false (preparecnt)) |
3663 | { |
3790 | { |
3664 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3791 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3665 | EV_INVOKE_PENDING; |
3792 | EV_INVOKE_PENDING; |
3666 | } |
3793 | } |
3667 | #endif |
3794 | #endif |
3668 | |
3795 | |
3669 | if (expect_false (loop_done)) |
3796 | if (ecb_expect_false (loop_done)) |
3670 | break; |
3797 | break; |
3671 | |
3798 | |
3672 | /* we might have forked, so reify kernel state if necessary */ |
3799 | /* we might have forked, so reify kernel state if necessary */ |
3673 | if (expect_false (postfork)) |
3800 | if (ecb_expect_false (postfork)) |
3674 | loop_fork (EV_A); |
3801 | loop_fork (EV_A); |
3675 | |
3802 | |
3676 | /* update fd-related kernel structures */ |
3803 | /* update fd-related kernel structures */ |
3677 | fd_reify (EV_A); |
3804 | fd_reify (EV_A); |
3678 | |
3805 | |
… | |
… | |
3683 | |
3810 | |
3684 | /* remember old timestamp for io_blocktime calculation */ |
3811 | /* remember old timestamp for io_blocktime calculation */ |
3685 | ev_tstamp prev_mn_now = mn_now; |
3812 | ev_tstamp prev_mn_now = mn_now; |
3686 | |
3813 | |
3687 | /* update time to cancel out callback processing overhead */ |
3814 | /* update time to cancel out callback processing overhead */ |
3688 | time_update (EV_A_ 1e100); |
3815 | time_update (EV_A_ EV_TS_CONST (EV_TSTAMP_HUGE)); |
3689 | |
3816 | |
3690 | /* from now on, we want a pipe-wake-up */ |
3817 | /* from now on, we want a pipe-wake-up */ |
3691 | pipe_write_wanted = 1; |
3818 | pipe_write_wanted = 1; |
3692 | |
3819 | |
3693 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3820 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3694 | |
3821 | |
3695 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3822 | if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3696 | { |
3823 | { |
3697 | waittime = MAX_BLOCKTIME; |
3824 | waittime = EV_TS_CONST (MAX_BLOCKTIME); |
3698 | |
3825 | |
3699 | if (timercnt) |
3826 | if (timercnt) |
3700 | { |
3827 | { |
3701 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3828 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3702 | if (waittime > to) waittime = to; |
3829 | if (waittime > to) waittime = to; |
… | |
… | |
3709 | if (waittime > to) waittime = to; |
3836 | if (waittime > to) waittime = to; |
3710 | } |
3837 | } |
3711 | #endif |
3838 | #endif |
3712 | |
3839 | |
3713 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3840 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3714 | if (expect_false (waittime < timeout_blocktime)) |
3841 | if (ecb_expect_false (waittime < timeout_blocktime)) |
3715 | waittime = timeout_blocktime; |
3842 | waittime = timeout_blocktime; |
3716 | |
3843 | |
3717 | /* at this point, we NEED to wait, so we have to ensure */ |
3844 | /* at this point, we NEED to wait, so we have to ensure */ |
3718 | /* to pass a minimum nonzero value to the backend */ |
3845 | /* to pass a minimum nonzero value to the backend */ |
3719 | if (expect_false (waittime < backend_mintime)) |
3846 | if (ecb_expect_false (waittime < backend_mintime)) |
3720 | waittime = backend_mintime; |
3847 | waittime = backend_mintime; |
3721 | |
3848 | |
3722 | /* extra check because io_blocktime is commonly 0 */ |
3849 | /* extra check because io_blocktime is commonly 0 */ |
3723 | if (expect_false (io_blocktime)) |
3850 | if (ecb_expect_false (io_blocktime)) |
3724 | { |
3851 | { |
3725 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3852 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3726 | |
3853 | |
3727 | if (sleeptime > waittime - backend_mintime) |
3854 | if (sleeptime > waittime - backend_mintime) |
3728 | sleeptime = waittime - backend_mintime; |
3855 | sleeptime = waittime - backend_mintime; |
3729 | |
3856 | |
3730 | if (expect_true (sleeptime > 0.)) |
3857 | if (ecb_expect_true (sleeptime > EV_TS_CONST (0.))) |
3731 | { |
3858 | { |
3732 | ev_sleep (sleeptime); |
3859 | ev_sleep (sleeptime); |
3733 | waittime -= sleeptime; |
3860 | waittime -= sleeptime; |
3734 | } |
3861 | } |
3735 | } |
3862 | } |
… | |
… | |
3749 | { |
3876 | { |
3750 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3877 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3751 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3878 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3752 | } |
3879 | } |
3753 | |
3880 | |
3754 | |
|
|
3755 | /* update ev_rt_now, do magic */ |
3881 | /* update ev_rt_now, do magic */ |
3756 | time_update (EV_A_ waittime + sleeptime); |
3882 | time_update (EV_A_ waittime + sleeptime); |
3757 | } |
3883 | } |
3758 | |
3884 | |
3759 | /* queue pending timers and reschedule them */ |
3885 | /* queue pending timers and reschedule them */ |
… | |
… | |
3767 | idle_reify (EV_A); |
3893 | idle_reify (EV_A); |
3768 | #endif |
3894 | #endif |
3769 | |
3895 | |
3770 | #if EV_CHECK_ENABLE |
3896 | #if EV_CHECK_ENABLE |
3771 | /* queue check watchers, to be executed first */ |
3897 | /* queue check watchers, to be executed first */ |
3772 | if (expect_false (checkcnt)) |
3898 | if (ecb_expect_false (checkcnt)) |
3773 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3899 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3774 | #endif |
3900 | #endif |
3775 | |
3901 | |
3776 | EV_INVOKE_PENDING; |
3902 | EV_INVOKE_PENDING; |
3777 | } |
3903 | } |
3778 | while (expect_true ( |
3904 | while (ecb_expect_true ( |
3779 | activecnt |
3905 | activecnt |
3780 | && !loop_done |
3906 | && !loop_done |
3781 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3907 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3782 | )); |
3908 | )); |
3783 | |
3909 | |
… | |
… | |
3810 | } |
3936 | } |
3811 | |
3937 | |
3812 | void |
3938 | void |
3813 | ev_now_update (EV_P) EV_NOEXCEPT |
3939 | ev_now_update (EV_P) EV_NOEXCEPT |
3814 | { |
3940 | { |
3815 | time_update (EV_A_ 1e100); |
3941 | time_update (EV_A_ EV_TSTAMP_HUGE); |
3816 | } |
3942 | } |
3817 | |
3943 | |
3818 | void |
3944 | void |
3819 | ev_suspend (EV_P) EV_NOEXCEPT |
3945 | ev_suspend (EV_P) EV_NOEXCEPT |
3820 | { |
3946 | { |
… | |
… | |
3847 | inline_size void |
3973 | inline_size void |
3848 | wlist_del (WL *head, WL elem) |
3974 | wlist_del (WL *head, WL elem) |
3849 | { |
3975 | { |
3850 | while (*head) |
3976 | while (*head) |
3851 | { |
3977 | { |
3852 | if (expect_true (*head == elem)) |
3978 | if (ecb_expect_true (*head == elem)) |
3853 | { |
3979 | { |
3854 | *head = elem->next; |
3980 | *head = elem->next; |
3855 | break; |
3981 | break; |
3856 | } |
3982 | } |
3857 | |
3983 | |
… | |
… | |
3874 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
4000 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3875 | { |
4001 | { |
3876 | W w_ = (W)w; |
4002 | W w_ = (W)w; |
3877 | int pending = w_->pending; |
4003 | int pending = w_->pending; |
3878 | |
4004 | |
3879 | if (expect_true (pending)) |
4005 | if (ecb_expect_true (pending)) |
3880 | { |
4006 | { |
3881 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
4007 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
3882 | p->w = (W)&pending_w; |
4008 | p->w = (W)&pending_w; |
3883 | w_->pending = 0; |
4009 | w_->pending = 0; |
3884 | return p->events; |
4010 | return p->events; |
… | |
… | |
3911 | w->active = 0; |
4037 | w->active = 0; |
3912 | } |
4038 | } |
3913 | |
4039 | |
3914 | /*****************************************************************************/ |
4040 | /*****************************************************************************/ |
3915 | |
4041 | |
3916 | noinline |
4042 | ecb_noinline |
3917 | void |
4043 | void |
3918 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
4044 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3919 | { |
4045 | { |
3920 | int fd = w->fd; |
4046 | int fd = w->fd; |
3921 | |
4047 | |
3922 | if (expect_false (ev_is_active (w))) |
4048 | if (ecb_expect_false (ev_is_active (w))) |
3923 | return; |
4049 | return; |
3924 | |
4050 | |
3925 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
4051 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3926 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
4052 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3927 | |
4053 | |
… | |
… | |
3941 | w->events &= ~EV__IOFDSET; |
4067 | w->events &= ~EV__IOFDSET; |
3942 | |
4068 | |
3943 | EV_FREQUENT_CHECK; |
4069 | EV_FREQUENT_CHECK; |
3944 | } |
4070 | } |
3945 | |
4071 | |
3946 | noinline |
4072 | ecb_noinline |
3947 | void |
4073 | void |
3948 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
4074 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3949 | { |
4075 | { |
3950 | clear_pending (EV_A_ (W)w); |
4076 | clear_pending (EV_A_ (W)w); |
3951 | if (expect_false (!ev_is_active (w))) |
4077 | if (ecb_expect_false (!ev_is_active (w))) |
3952 | return; |
4078 | return; |
3953 | |
4079 | |
3954 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
4080 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3955 | |
4081 | |
3956 | #if EV_VERIFY >= 2 |
4082 | #if EV_VERIFY >= 2 |
… | |
… | |
3964 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
4090 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3965 | |
4091 | |
3966 | EV_FREQUENT_CHECK; |
4092 | EV_FREQUENT_CHECK; |
3967 | } |
4093 | } |
3968 | |
4094 | |
3969 | noinline |
4095 | ecb_noinline |
3970 | void |
4096 | void |
3971 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
4097 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3972 | { |
4098 | { |
3973 | if (expect_false (ev_is_active (w))) |
4099 | if (ecb_expect_false (ev_is_active (w))) |
3974 | return; |
4100 | return; |
3975 | |
4101 | |
3976 | ev_at (w) += mn_now; |
4102 | ev_at (w) += mn_now; |
3977 | |
4103 | |
3978 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
4104 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
… | |
… | |
3989 | EV_FREQUENT_CHECK; |
4115 | EV_FREQUENT_CHECK; |
3990 | |
4116 | |
3991 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
4117 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3992 | } |
4118 | } |
3993 | |
4119 | |
3994 | noinline |
4120 | ecb_noinline |
3995 | void |
4121 | void |
3996 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
4122 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3997 | { |
4123 | { |
3998 | clear_pending (EV_A_ (W)w); |
4124 | clear_pending (EV_A_ (W)w); |
3999 | if (expect_false (!ev_is_active (w))) |
4125 | if (ecb_expect_false (!ev_is_active (w))) |
4000 | return; |
4126 | return; |
4001 | |
4127 | |
4002 | EV_FREQUENT_CHECK; |
4128 | EV_FREQUENT_CHECK; |
4003 | |
4129 | |
4004 | { |
4130 | { |
… | |
… | |
4006 | |
4132 | |
4007 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
4133 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
4008 | |
4134 | |
4009 | --timercnt; |
4135 | --timercnt; |
4010 | |
4136 | |
4011 | if (expect_true (active < timercnt + HEAP0)) |
4137 | if (ecb_expect_true (active < timercnt + HEAP0)) |
4012 | { |
4138 | { |
4013 | timers [active] = timers [timercnt + HEAP0]; |
4139 | timers [active] = timers [timercnt + HEAP0]; |
4014 | adjustheap (timers, timercnt, active); |
4140 | adjustheap (timers, timercnt, active); |
4015 | } |
4141 | } |
4016 | } |
4142 | } |
… | |
… | |
4020 | ev_stop (EV_A_ (W)w); |
4146 | ev_stop (EV_A_ (W)w); |
4021 | |
4147 | |
4022 | EV_FREQUENT_CHECK; |
4148 | EV_FREQUENT_CHECK; |
4023 | } |
4149 | } |
4024 | |
4150 | |
4025 | noinline |
4151 | ecb_noinline |
4026 | void |
4152 | void |
4027 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
4153 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
4028 | { |
4154 | { |
4029 | EV_FREQUENT_CHECK; |
4155 | EV_FREQUENT_CHECK; |
4030 | |
4156 | |
… | |
… | |
4051 | } |
4177 | } |
4052 | |
4178 | |
4053 | ev_tstamp |
4179 | ev_tstamp |
4054 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
4180 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
4055 | { |
4181 | { |
4056 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4182 | return ev_at (w) - (ev_is_active (w) ? mn_now : EV_TS_CONST (0.)); |
4057 | } |
4183 | } |
4058 | |
4184 | |
4059 | #if EV_PERIODIC_ENABLE |
4185 | #if EV_PERIODIC_ENABLE |
4060 | noinline |
4186 | ecb_noinline |
4061 | void |
4187 | void |
4062 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4188 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4063 | { |
4189 | { |
4064 | if (expect_false (ev_is_active (w))) |
4190 | if (ecb_expect_false (ev_is_active (w))) |
4065 | return; |
4191 | return; |
4066 | |
4192 | |
4067 | if (w->reschedule_cb) |
4193 | if (w->reschedule_cb) |
4068 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
4194 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
4069 | else if (w->interval) |
4195 | else if (w->interval) |
… | |
… | |
4086 | EV_FREQUENT_CHECK; |
4212 | EV_FREQUENT_CHECK; |
4087 | |
4213 | |
4088 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4214 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4089 | } |
4215 | } |
4090 | |
4216 | |
4091 | noinline |
4217 | ecb_noinline |
4092 | void |
4218 | void |
4093 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4219 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4094 | { |
4220 | { |
4095 | clear_pending (EV_A_ (W)w); |
4221 | clear_pending (EV_A_ (W)w); |
4096 | if (expect_false (!ev_is_active (w))) |
4222 | if (ecb_expect_false (!ev_is_active (w))) |
4097 | return; |
4223 | return; |
4098 | |
4224 | |
4099 | EV_FREQUENT_CHECK; |
4225 | EV_FREQUENT_CHECK; |
4100 | |
4226 | |
4101 | { |
4227 | { |
… | |
… | |
4103 | |
4229 | |
4104 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4230 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4105 | |
4231 | |
4106 | --periodiccnt; |
4232 | --periodiccnt; |
4107 | |
4233 | |
4108 | if (expect_true (active < periodiccnt + HEAP0)) |
4234 | if (ecb_expect_true (active < periodiccnt + HEAP0)) |
4109 | { |
4235 | { |
4110 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4236 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4111 | adjustheap (periodics, periodiccnt, active); |
4237 | adjustheap (periodics, periodiccnt, active); |
4112 | } |
4238 | } |
4113 | } |
4239 | } |
… | |
… | |
4115 | ev_stop (EV_A_ (W)w); |
4241 | ev_stop (EV_A_ (W)w); |
4116 | |
4242 | |
4117 | EV_FREQUENT_CHECK; |
4243 | EV_FREQUENT_CHECK; |
4118 | } |
4244 | } |
4119 | |
4245 | |
4120 | noinline |
4246 | ecb_noinline |
4121 | void |
4247 | void |
4122 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4248 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4123 | { |
4249 | { |
4124 | /* TODO: use adjustheap and recalculation */ |
4250 | /* TODO: use adjustheap and recalculation */ |
4125 | ev_periodic_stop (EV_A_ w); |
4251 | ev_periodic_stop (EV_A_ w); |
… | |
… | |
4131 | # define SA_RESTART 0 |
4257 | # define SA_RESTART 0 |
4132 | #endif |
4258 | #endif |
4133 | |
4259 | |
4134 | #if EV_SIGNAL_ENABLE |
4260 | #if EV_SIGNAL_ENABLE |
4135 | |
4261 | |
4136 | noinline |
4262 | ecb_noinline |
4137 | void |
4263 | void |
4138 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4264 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4139 | { |
4265 | { |
4140 | if (expect_false (ev_is_active (w))) |
4266 | if (ecb_expect_false (ev_is_active (w))) |
4141 | return; |
4267 | return; |
4142 | |
4268 | |
4143 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4269 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4144 | |
4270 | |
4145 | #if EV_MULTIPLICITY |
4271 | #if EV_MULTIPLICITY |
… | |
… | |
4214 | } |
4340 | } |
4215 | |
4341 | |
4216 | EV_FREQUENT_CHECK; |
4342 | EV_FREQUENT_CHECK; |
4217 | } |
4343 | } |
4218 | |
4344 | |
4219 | noinline |
4345 | ecb_noinline |
4220 | void |
4346 | void |
4221 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4347 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4222 | { |
4348 | { |
4223 | clear_pending (EV_A_ (W)w); |
4349 | clear_pending (EV_A_ (W)w); |
4224 | if (expect_false (!ev_is_active (w))) |
4350 | if (ecb_expect_false (!ev_is_active (w))) |
4225 | return; |
4351 | return; |
4226 | |
4352 | |
4227 | EV_FREQUENT_CHECK; |
4353 | EV_FREQUENT_CHECK; |
4228 | |
4354 | |
4229 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
4355 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
… | |
… | |
4262 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4388 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4263 | { |
4389 | { |
4264 | #if EV_MULTIPLICITY |
4390 | #if EV_MULTIPLICITY |
4265 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4391 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4266 | #endif |
4392 | #endif |
4267 | if (expect_false (ev_is_active (w))) |
4393 | if (ecb_expect_false (ev_is_active (w))) |
4268 | return; |
4394 | return; |
4269 | |
4395 | |
4270 | EV_FREQUENT_CHECK; |
4396 | EV_FREQUENT_CHECK; |
4271 | |
4397 | |
4272 | ev_start (EV_A_ (W)w, 1); |
4398 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
4277 | |
4403 | |
4278 | void |
4404 | void |
4279 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4405 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4280 | { |
4406 | { |
4281 | clear_pending (EV_A_ (W)w); |
4407 | clear_pending (EV_A_ (W)w); |
4282 | if (expect_false (!ev_is_active (w))) |
4408 | if (ecb_expect_false (!ev_is_active (w))) |
4283 | return; |
4409 | return; |
4284 | |
4410 | |
4285 | EV_FREQUENT_CHECK; |
4411 | EV_FREQUENT_CHECK; |
4286 | |
4412 | |
4287 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
4413 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
… | |
… | |
4301 | |
4427 | |
4302 | #define DEF_STAT_INTERVAL 5.0074891 |
4428 | #define DEF_STAT_INTERVAL 5.0074891 |
4303 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4429 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4304 | #define MIN_STAT_INTERVAL 0.1074891 |
4430 | #define MIN_STAT_INTERVAL 0.1074891 |
4305 | |
4431 | |
4306 | noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4432 | ecb_noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4307 | |
4433 | |
4308 | #if EV_USE_INOTIFY |
4434 | #if EV_USE_INOTIFY |
4309 | |
4435 | |
4310 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4436 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4311 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4437 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4312 | |
4438 | |
4313 | noinline |
4439 | ecb_noinline |
4314 | static void |
4440 | static void |
4315 | infy_add (EV_P_ ev_stat *w) |
4441 | infy_add (EV_P_ ev_stat *w) |
4316 | { |
4442 | { |
4317 | w->wd = inotify_add_watch (fs_fd, w->path, |
4443 | w->wd = inotify_add_watch (fs_fd, w->path, |
4318 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4444 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
… | |
… | |
4383 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4509 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4384 | ev_timer_again (EV_A_ &w->timer); |
4510 | ev_timer_again (EV_A_ &w->timer); |
4385 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4511 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4386 | } |
4512 | } |
4387 | |
4513 | |
4388 | noinline |
4514 | ecb_noinline |
4389 | static void |
4515 | static void |
4390 | infy_del (EV_P_ ev_stat *w) |
4516 | infy_del (EV_P_ ev_stat *w) |
4391 | { |
4517 | { |
4392 | int slot; |
4518 | int slot; |
4393 | int wd = w->wd; |
4519 | int wd = w->wd; |
… | |
… | |
4401 | |
4527 | |
4402 | /* remove this watcher, if others are watching it, they will rearm */ |
4528 | /* remove this watcher, if others are watching it, they will rearm */ |
4403 | inotify_rm_watch (fs_fd, wd); |
4529 | inotify_rm_watch (fs_fd, wd); |
4404 | } |
4530 | } |
4405 | |
4531 | |
4406 | noinline |
4532 | ecb_noinline |
4407 | static void |
4533 | static void |
4408 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4534 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4409 | { |
4535 | { |
4410 | if (slot < 0) |
4536 | if (slot < 0) |
4411 | /* overflow, need to check for all hash slots */ |
4537 | /* overflow, need to check for all hash slots */ |
… | |
… | |
4557 | w->attr.st_nlink = 0; |
4683 | w->attr.st_nlink = 0; |
4558 | else if (!w->attr.st_nlink) |
4684 | else if (!w->attr.st_nlink) |
4559 | w->attr.st_nlink = 1; |
4685 | w->attr.st_nlink = 1; |
4560 | } |
4686 | } |
4561 | |
4687 | |
4562 | noinline |
4688 | ecb_noinline |
4563 | static void |
4689 | static void |
4564 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4690 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4565 | { |
4691 | { |
4566 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4692 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4567 | |
4693 | |
… | |
… | |
4601 | } |
4727 | } |
4602 | |
4728 | |
4603 | void |
4729 | void |
4604 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4730 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4605 | { |
4731 | { |
4606 | if (expect_false (ev_is_active (w))) |
4732 | if (ecb_expect_false (ev_is_active (w))) |
4607 | return; |
4733 | return; |
4608 | |
4734 | |
4609 | ev_stat_stat (EV_A_ w); |
4735 | ev_stat_stat (EV_A_ w); |
4610 | |
4736 | |
4611 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
4737 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
… | |
… | |
4633 | |
4759 | |
4634 | void |
4760 | void |
4635 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4761 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4636 | { |
4762 | { |
4637 | clear_pending (EV_A_ (W)w); |
4763 | clear_pending (EV_A_ (W)w); |
4638 | if (expect_false (!ev_is_active (w))) |
4764 | if (ecb_expect_false (!ev_is_active (w))) |
4639 | return; |
4765 | return; |
4640 | |
4766 | |
4641 | EV_FREQUENT_CHECK; |
4767 | EV_FREQUENT_CHECK; |
4642 | |
4768 | |
4643 | #if EV_USE_INOTIFY |
4769 | #if EV_USE_INOTIFY |
… | |
… | |
4658 | |
4784 | |
4659 | #if EV_IDLE_ENABLE |
4785 | #if EV_IDLE_ENABLE |
4660 | void |
4786 | void |
4661 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4787 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4662 | { |
4788 | { |
4663 | if (expect_false (ev_is_active (w))) |
4789 | if (ecb_expect_false (ev_is_active (w))) |
4664 | return; |
4790 | return; |
4665 | |
4791 | |
4666 | pri_adjust (EV_A_ (W)w); |
4792 | pri_adjust (EV_A_ (W)w); |
4667 | |
4793 | |
4668 | EV_FREQUENT_CHECK; |
4794 | EV_FREQUENT_CHECK; |
… | |
… | |
4682 | |
4808 | |
4683 | void |
4809 | void |
4684 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4810 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4685 | { |
4811 | { |
4686 | clear_pending (EV_A_ (W)w); |
4812 | clear_pending (EV_A_ (W)w); |
4687 | if (expect_false (!ev_is_active (w))) |
4813 | if (ecb_expect_false (!ev_is_active (w))) |
4688 | return; |
4814 | return; |
4689 | |
4815 | |
4690 | EV_FREQUENT_CHECK; |
4816 | EV_FREQUENT_CHECK; |
4691 | |
4817 | |
4692 | { |
4818 | { |
… | |
… | |
4705 | |
4831 | |
4706 | #if EV_PREPARE_ENABLE |
4832 | #if EV_PREPARE_ENABLE |
4707 | void |
4833 | void |
4708 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4834 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4709 | { |
4835 | { |
4710 | if (expect_false (ev_is_active (w))) |
4836 | if (ecb_expect_false (ev_is_active (w))) |
4711 | return; |
4837 | return; |
4712 | |
4838 | |
4713 | EV_FREQUENT_CHECK; |
4839 | EV_FREQUENT_CHECK; |
4714 | |
4840 | |
4715 | ev_start (EV_A_ (W)w, ++preparecnt); |
4841 | ev_start (EV_A_ (W)w, ++preparecnt); |
… | |
… | |
4721 | |
4847 | |
4722 | void |
4848 | void |
4723 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4849 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4724 | { |
4850 | { |
4725 | clear_pending (EV_A_ (W)w); |
4851 | clear_pending (EV_A_ (W)w); |
4726 | if (expect_false (!ev_is_active (w))) |
4852 | if (ecb_expect_false (!ev_is_active (w))) |
4727 | return; |
4853 | return; |
4728 | |
4854 | |
4729 | EV_FREQUENT_CHECK; |
4855 | EV_FREQUENT_CHECK; |
4730 | |
4856 | |
4731 | { |
4857 | { |
… | |
… | |
4743 | |
4869 | |
4744 | #if EV_CHECK_ENABLE |
4870 | #if EV_CHECK_ENABLE |
4745 | void |
4871 | void |
4746 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4872 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4747 | { |
4873 | { |
4748 | if (expect_false (ev_is_active (w))) |
4874 | if (ecb_expect_false (ev_is_active (w))) |
4749 | return; |
4875 | return; |
4750 | |
4876 | |
4751 | EV_FREQUENT_CHECK; |
4877 | EV_FREQUENT_CHECK; |
4752 | |
4878 | |
4753 | ev_start (EV_A_ (W)w, ++checkcnt); |
4879 | ev_start (EV_A_ (W)w, ++checkcnt); |
… | |
… | |
4759 | |
4885 | |
4760 | void |
4886 | void |
4761 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4887 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4762 | { |
4888 | { |
4763 | clear_pending (EV_A_ (W)w); |
4889 | clear_pending (EV_A_ (W)w); |
4764 | if (expect_false (!ev_is_active (w))) |
4890 | if (ecb_expect_false (!ev_is_active (w))) |
4765 | return; |
4891 | return; |
4766 | |
4892 | |
4767 | EV_FREQUENT_CHECK; |
4893 | EV_FREQUENT_CHECK; |
4768 | |
4894 | |
4769 | { |
4895 | { |
… | |
… | |
4778 | EV_FREQUENT_CHECK; |
4904 | EV_FREQUENT_CHECK; |
4779 | } |
4905 | } |
4780 | #endif |
4906 | #endif |
4781 | |
4907 | |
4782 | #if EV_EMBED_ENABLE |
4908 | #if EV_EMBED_ENABLE |
4783 | noinline |
4909 | ecb_noinline |
4784 | void |
4910 | void |
4785 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4911 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4786 | { |
4912 | { |
4787 | ev_run (w->other, EVRUN_NOWAIT); |
4913 | ev_run (w->other, EVRUN_NOWAIT); |
4788 | } |
4914 | } |
… | |
… | |
4840 | #endif |
4966 | #endif |
4841 | |
4967 | |
4842 | void |
4968 | void |
4843 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4969 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4844 | { |
4970 | { |
4845 | if (expect_false (ev_is_active (w))) |
4971 | if (ecb_expect_false (ev_is_active (w))) |
4846 | return; |
4972 | return; |
4847 | |
4973 | |
4848 | { |
4974 | { |
4849 | EV_P = w->other; |
4975 | EV_P = w->other; |
4850 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
4976 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
… | |
… | |
4872 | |
4998 | |
4873 | void |
4999 | void |
4874 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
5000 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4875 | { |
5001 | { |
4876 | clear_pending (EV_A_ (W)w); |
5002 | clear_pending (EV_A_ (W)w); |
4877 | if (expect_false (!ev_is_active (w))) |
5003 | if (ecb_expect_false (!ev_is_active (w))) |
4878 | return; |
5004 | return; |
4879 | |
5005 | |
4880 | EV_FREQUENT_CHECK; |
5006 | EV_FREQUENT_CHECK; |
4881 | |
5007 | |
4882 | ev_io_stop (EV_A_ &w->io); |
5008 | ev_io_stop (EV_A_ &w->io); |
… | |
… | |
4891 | |
5017 | |
4892 | #if EV_FORK_ENABLE |
5018 | #if EV_FORK_ENABLE |
4893 | void |
5019 | void |
4894 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
5020 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4895 | { |
5021 | { |
4896 | if (expect_false (ev_is_active (w))) |
5022 | if (ecb_expect_false (ev_is_active (w))) |
4897 | return; |
5023 | return; |
4898 | |
5024 | |
4899 | EV_FREQUENT_CHECK; |
5025 | EV_FREQUENT_CHECK; |
4900 | |
5026 | |
4901 | ev_start (EV_A_ (W)w, ++forkcnt); |
5027 | ev_start (EV_A_ (W)w, ++forkcnt); |
… | |
… | |
4907 | |
5033 | |
4908 | void |
5034 | void |
4909 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
5035 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4910 | { |
5036 | { |
4911 | clear_pending (EV_A_ (W)w); |
5037 | clear_pending (EV_A_ (W)w); |
4912 | if (expect_false (!ev_is_active (w))) |
5038 | if (ecb_expect_false (!ev_is_active (w))) |
4913 | return; |
5039 | return; |
4914 | |
5040 | |
4915 | EV_FREQUENT_CHECK; |
5041 | EV_FREQUENT_CHECK; |
4916 | |
5042 | |
4917 | { |
5043 | { |
… | |
… | |
4929 | |
5055 | |
4930 | #if EV_CLEANUP_ENABLE |
5056 | #if EV_CLEANUP_ENABLE |
4931 | void |
5057 | void |
4932 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
5058 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4933 | { |
5059 | { |
4934 | if (expect_false (ev_is_active (w))) |
5060 | if (ecb_expect_false (ev_is_active (w))) |
4935 | return; |
5061 | return; |
4936 | |
5062 | |
4937 | EV_FREQUENT_CHECK; |
5063 | EV_FREQUENT_CHECK; |
4938 | |
5064 | |
4939 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
5065 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
… | |
… | |
4947 | |
5073 | |
4948 | void |
5074 | void |
4949 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
5075 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4950 | { |
5076 | { |
4951 | clear_pending (EV_A_ (W)w); |
5077 | clear_pending (EV_A_ (W)w); |
4952 | if (expect_false (!ev_is_active (w))) |
5078 | if (ecb_expect_false (!ev_is_active (w))) |
4953 | return; |
5079 | return; |
4954 | |
5080 | |
4955 | EV_FREQUENT_CHECK; |
5081 | EV_FREQUENT_CHECK; |
4956 | ev_ref (EV_A); |
5082 | ev_ref (EV_A); |
4957 | |
5083 | |
… | |
… | |
4970 | |
5096 | |
4971 | #if EV_ASYNC_ENABLE |
5097 | #if EV_ASYNC_ENABLE |
4972 | void |
5098 | void |
4973 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
5099 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4974 | { |
5100 | { |
4975 | if (expect_false (ev_is_active (w))) |
5101 | if (ecb_expect_false (ev_is_active (w))) |
4976 | return; |
5102 | return; |
4977 | |
5103 | |
4978 | w->sent = 0; |
5104 | w->sent = 0; |
4979 | |
5105 | |
4980 | evpipe_init (EV_A); |
5106 | evpipe_init (EV_A); |
… | |
… | |
4990 | |
5116 | |
4991 | void |
5117 | void |
4992 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
5118 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4993 | { |
5119 | { |
4994 | clear_pending (EV_A_ (W)w); |
5120 | clear_pending (EV_A_ (W)w); |
4995 | if (expect_false (!ev_is_active (w))) |
5121 | if (ecb_expect_false (!ev_is_active (w))) |
4996 | return; |
5122 | return; |
4997 | |
5123 | |
4998 | EV_FREQUENT_CHECK; |
5124 | EV_FREQUENT_CHECK; |
4999 | |
5125 | |
5000 | { |
5126 | { |