… | |
… | |
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) */ |
|
|
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.) \ |
514 | |
548 | |
515 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
549 | #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) |
550 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
|
|
551 | #define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e6) |
|
|
552 | #define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e9) |
517 | |
553 | |
518 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
554 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
519 | /* ECB.H BEGIN */ |
555 | /* ECB.H BEGIN */ |
520 | /* |
556 | /* |
521 | * libecb - http://software.schmorp.de/pkg/libecb |
557 | * libecb - http://software.schmorp.de/pkg/libecb |
… | |
… | |
1536 | /* ECB.H END */ |
1572 | /* ECB.H END */ |
1537 | |
1573 | |
1538 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1574 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1539 | /* if your architecture doesn't need memory fences, e.g. because it is |
1575 | /* 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 |
1576 | * 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 |
1577 | * from multiple threads, then you can define ECB_NO_THREADS when compiling |
1542 | * libev, in which cases the memory fences become nops. |
1578 | * libev, in which cases the memory fences become nops. |
1543 | * alternatively, you can remove this #error and link against libpthread, |
1579 | * alternatively, you can remove this #error and link against libpthread, |
1544 | * which will then provide the memory fences. |
1580 | * which will then provide the memory fences. |
1545 | */ |
1581 | */ |
1546 | # error "memory fences not defined for your architecture, please report" |
1582 | # error "memory fences not defined for your architecture, please report" |
… | |
… | |
1550 | # define ECB_MEMORY_FENCE do { } while (0) |
1586 | # define ECB_MEMORY_FENCE do { } while (0) |
1551 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1587 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1552 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1588 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1553 | #endif |
1589 | #endif |
1554 | |
1590 | |
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 |
1591 | #define inline_size ecb_inline |
1560 | |
1592 | |
1561 | #if EV_FEATURE_CODE |
1593 | #if EV_FEATURE_CODE |
1562 | # define inline_speed ecb_inline |
1594 | # define inline_speed ecb_inline |
1563 | #else |
1595 | #else |
1564 | # define inline_speed noinline static |
1596 | # define inline_speed ecb_noinline static |
1565 | #endif |
1597 | #endif |
|
|
1598 | |
|
|
1599 | /*****************************************************************************/ |
|
|
1600 | /* raw syscall wrappers */ |
|
|
1601 | |
|
|
1602 | #if EV_NEED_SYSCALL |
|
|
1603 | |
|
|
1604 | #include <sys/syscall.h> |
|
|
1605 | |
|
|
1606 | /* |
|
|
1607 | * define some syscall wrappers for common architectures |
|
|
1608 | * this is mostly for nice looks during debugging, not performance. |
|
|
1609 | * our syscalls return < 0, not == -1, on error. which is good |
|
|
1610 | * enough for linux aio. |
|
|
1611 | * TODO: arm is also common nowadays, maybe even mips and x86 |
|
|
1612 | * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove... |
|
|
1613 | */ |
|
|
1614 | #if __GNUC__ && __linux && ECB_AMD64 && !defined __OPTIMIZE_SIZE__ |
|
|
1615 | /* the costly errno access probably kills this for size optimisation */ |
|
|
1616 | |
|
|
1617 | #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5,arg6) \ |
|
|
1618 | ({ \ |
|
|
1619 | long res; \ |
|
|
1620 | register unsigned long r6 __asm__ ("r9" ); \ |
|
|
1621 | register unsigned long r5 __asm__ ("r8" ); \ |
|
|
1622 | register unsigned long r4 __asm__ ("r10"); \ |
|
|
1623 | register unsigned long r3 __asm__ ("rdx"); \ |
|
|
1624 | register unsigned long r2 __asm__ ("rsi"); \ |
|
|
1625 | register unsigned long r1 __asm__ ("rdi"); \ |
|
|
1626 | if (narg >= 6) r6 = (unsigned long)(arg6); \ |
|
|
1627 | if (narg >= 5) r5 = (unsigned long)(arg5); \ |
|
|
1628 | if (narg >= 4) r4 = (unsigned long)(arg4); \ |
|
|
1629 | if (narg >= 3) r3 = (unsigned long)(arg3); \ |
|
|
1630 | if (narg >= 2) r2 = (unsigned long)(arg2); \ |
|
|
1631 | if (narg >= 1) r1 = (unsigned long)(arg1); \ |
|
|
1632 | __asm__ __volatile__ ( \ |
|
|
1633 | "syscall\n\t" \ |
|
|
1634 | : "=a" (res) \ |
|
|
1635 | : "0" (nr), "r" (r1), "r" (r2), "r" (r3), "r" (r4), "r" (r5) \ |
|
|
1636 | : "cc", "r11", "cx", "memory"); \ |
|
|
1637 | errno = -res; \ |
|
|
1638 | res; \ |
|
|
1639 | }) |
|
|
1640 | |
|
|
1641 | #endif |
|
|
1642 | |
|
|
1643 | #ifdef ev_syscall |
|
|
1644 | #define ev_syscall0(nr) ev_syscall (nr, 0, 0, 0, 0, 0, 0, 0) |
|
|
1645 | #define ev_syscall1(nr,arg1) ev_syscall (nr, 1, arg1, 0, 0, 0, 0, 0) |
|
|
1646 | #define ev_syscall2(nr,arg1,arg2) ev_syscall (nr, 2, arg1, arg2, 0, 0, 0, 0) |
|
|
1647 | #define ev_syscall3(nr,arg1,arg2,arg3) ev_syscall (nr, 3, arg1, arg2, arg3, 0, 0, 0) |
|
|
1648 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) ev_syscall (nr, 3, arg1, arg2, arg3, arg4, 0, 0) |
|
|
1649 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) ev_syscall (nr, 5, arg1, arg2, arg3, arg4, arg5, 0) |
|
|
1650 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) ev_syscall (nr, 6, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1651 | #else |
|
|
1652 | #define ev_syscall0(nr) syscall (nr) |
|
|
1653 | #define ev_syscall1(nr,arg1) syscall (nr, arg1) |
|
|
1654 | #define ev_syscall2(nr,arg1,arg2) syscall (nr, arg1, arg2) |
|
|
1655 | #define ev_syscall3(nr,arg1,arg2,arg3) syscall (nr, arg1, arg2, arg3) |
|
|
1656 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) syscall (nr, arg1, arg2, arg3, arg4) |
|
|
1657 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) syscall (nr, arg1, arg2, arg3, arg4, arg5) |
|
|
1658 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) syscall (nr, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1659 | #endif |
|
|
1660 | |
|
|
1661 | #endif |
|
|
1662 | |
|
|
1663 | /*****************************************************************************/ |
1566 | |
1664 | |
1567 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1665 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1568 | |
1666 | |
1569 | #if EV_MINPRI == EV_MAXPRI |
1667 | #if EV_MINPRI == EV_MAXPRI |
1570 | # define ABSPRI(w) (((W)w), 0) |
1668 | # define ABSPRI(w) (((W)w), 0) |
… | |
… | |
1619 | #else |
1717 | #else |
1620 | |
1718 | |
1621 | #include <float.h> |
1719 | #include <float.h> |
1622 | |
1720 | |
1623 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1721 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1624 | noinline |
1722 | ecb_noinline |
1625 | static ev_tstamp |
1723 | static ev_tstamp |
1626 | ev_floor (ev_tstamp v) |
1724 | ev_floor (ev_tstamp v) |
1627 | { |
1725 | { |
1628 | /* the choice of shift factor is not terribly important */ |
1726 | /* the choice of shift factor is not terribly important */ |
1629 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1727 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1630 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1728 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1631 | #else |
1729 | #else |
1632 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1730 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1633 | #endif |
1731 | #endif |
1634 | |
1732 | |
|
|
1733 | /* special treatment for negative arguments */ |
|
|
1734 | if (ecb_expect_false (v < 0.)) |
|
|
1735 | { |
|
|
1736 | ev_tstamp f = -ev_floor (-v); |
|
|
1737 | |
|
|
1738 | return f - (f == v ? 0 : 1); |
|
|
1739 | } |
|
|
1740 | |
1635 | /* argument too large for an unsigned long? */ |
1741 | /* argument too large for an unsigned long? then reduce it */ |
1636 | if (expect_false (v >= shift)) |
1742 | if (ecb_expect_false (v >= shift)) |
1637 | { |
1743 | { |
1638 | ev_tstamp f; |
1744 | ev_tstamp f; |
1639 | |
1745 | |
1640 | if (v == v - 1.) |
1746 | if (v == v - 1.) |
1641 | return v; /* very large number */ |
1747 | return v; /* very large numbers are assumed to be integer */ |
1642 | |
1748 | |
1643 | f = shift * ev_floor (v * (1. / shift)); |
1749 | f = shift * ev_floor (v * (1. / shift)); |
1644 | return f + ev_floor (v - f); |
1750 | return f + ev_floor (v - f); |
1645 | } |
1751 | } |
1646 | |
1752 | |
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 */ |
1753 | /* fits into an unsigned long */ |
1656 | return (unsigned long)v; |
1754 | return (unsigned long)v; |
1657 | } |
1755 | } |
1658 | |
1756 | |
1659 | #endif |
1757 | #endif |
… | |
… | |
1662 | |
1760 | |
1663 | #ifdef __linux |
1761 | #ifdef __linux |
1664 | # include <sys/utsname.h> |
1762 | # include <sys/utsname.h> |
1665 | #endif |
1763 | #endif |
1666 | |
1764 | |
1667 | noinline ecb_cold |
1765 | ecb_noinline ecb_cold |
1668 | static unsigned int |
1766 | static unsigned int |
1669 | ev_linux_version (void) |
1767 | ev_linux_version (void) |
1670 | { |
1768 | { |
1671 | #ifdef __linux |
1769 | #ifdef __linux |
1672 | unsigned int v = 0; |
1770 | unsigned int v = 0; |
… | |
… | |
1702 | } |
1800 | } |
1703 | |
1801 | |
1704 | /*****************************************************************************/ |
1802 | /*****************************************************************************/ |
1705 | |
1803 | |
1706 | #if EV_AVOID_STDIO |
1804 | #if EV_AVOID_STDIO |
1707 | noinline ecb_cold |
1805 | ecb_noinline ecb_cold |
1708 | static void |
1806 | static void |
1709 | ev_printerr (const char *msg) |
1807 | ev_printerr (const char *msg) |
1710 | { |
1808 | { |
1711 | write (STDERR_FILENO, msg, strlen (msg)); |
1809 | write (STDERR_FILENO, msg, strlen (msg)); |
1712 | } |
1810 | } |
… | |
… | |
1719 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1817 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1720 | { |
1818 | { |
1721 | syserr_cb = cb; |
1819 | syserr_cb = cb; |
1722 | } |
1820 | } |
1723 | |
1821 | |
1724 | noinline ecb_cold |
1822 | ecb_noinline ecb_cold |
1725 | static void |
1823 | static void |
1726 | ev_syserr (const char *msg) |
1824 | ev_syserr (const char *msg) |
1727 | { |
1825 | { |
1728 | if (!msg) |
1826 | if (!msg) |
1729 | msg = "(libev) system error"; |
1827 | msg = "(libev) system error"; |
… | |
… | |
1801 | { |
1899 | { |
1802 | WL head; |
1900 | WL head; |
1803 | unsigned char events; /* the events watched for */ |
1901 | unsigned char events; /* the events watched for */ |
1804 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1902 | 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 */ |
1903 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1806 | unsigned char unused; |
1904 | unsigned char eflags; /* flags field for use by backends */ |
1807 | #if EV_USE_EPOLL |
1905 | #if EV_USE_EPOLL |
1808 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1906 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1809 | #endif |
1907 | #endif |
1810 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1908 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1811 | SOCKET handle; |
1909 | SOCKET handle; |
… | |
… | |
1875 | static int ev_default_loop_ptr; |
1973 | static int ev_default_loop_ptr; |
1876 | |
1974 | |
1877 | #endif |
1975 | #endif |
1878 | |
1976 | |
1879 | #if EV_FEATURE_API |
1977 | #if EV_FEATURE_API |
1880 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
1978 | # 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) |
1979 | # define EV_ACQUIRE_CB if (ecb_expect_false (acquire_cb)) acquire_cb (EV_A) |
1882 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
1980 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
1883 | #else |
1981 | #else |
1884 | # define EV_RELEASE_CB (void)0 |
1982 | # define EV_RELEASE_CB (void)0 |
1885 | # define EV_ACQUIRE_CB (void)0 |
1983 | # define EV_ACQUIRE_CB (void)0 |
1886 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
1984 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
… | |
… | |
1893 | #ifndef EV_HAVE_EV_TIME |
1991 | #ifndef EV_HAVE_EV_TIME |
1894 | ev_tstamp |
1992 | ev_tstamp |
1895 | ev_time (void) EV_NOEXCEPT |
1993 | ev_time (void) EV_NOEXCEPT |
1896 | { |
1994 | { |
1897 | #if EV_USE_REALTIME |
1995 | #if EV_USE_REALTIME |
1898 | if (expect_true (have_realtime)) |
1996 | if (ecb_expect_true (have_realtime)) |
1899 | { |
1997 | { |
1900 | struct timespec ts; |
1998 | struct timespec ts; |
1901 | clock_gettime (CLOCK_REALTIME, &ts); |
1999 | clock_gettime (CLOCK_REALTIME, &ts); |
1902 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2000 | return EV_TS_GET (ts); |
1903 | } |
2001 | } |
1904 | #endif |
2002 | #endif |
1905 | |
2003 | |
1906 | struct timeval tv; |
2004 | struct timeval tv; |
1907 | gettimeofday (&tv, 0); |
2005 | gettimeofday (&tv, 0); |
1908 | return tv.tv_sec + tv.tv_usec * 1e-6; |
2006 | return EV_TV_GET (tv); |
1909 | } |
2007 | } |
1910 | #endif |
2008 | #endif |
1911 | |
2009 | |
1912 | inline_size ev_tstamp |
2010 | inline_size ev_tstamp |
1913 | get_clock (void) |
2011 | get_clock (void) |
1914 | { |
2012 | { |
1915 | #if EV_USE_MONOTONIC |
2013 | #if EV_USE_MONOTONIC |
1916 | if (expect_true (have_monotonic)) |
2014 | if (ecb_expect_true (have_monotonic)) |
1917 | { |
2015 | { |
1918 | struct timespec ts; |
2016 | struct timespec ts; |
1919 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2017 | clock_gettime (CLOCK_MONOTONIC, &ts); |
1920 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2018 | return EV_TS_GET (ts); |
1921 | } |
2019 | } |
1922 | #endif |
2020 | #endif |
1923 | |
2021 | |
1924 | return ev_time (); |
2022 | return ev_time (); |
1925 | } |
2023 | } |
… | |
… | |
1983 | } |
2081 | } |
1984 | |
2082 | |
1985 | return ncur; |
2083 | return ncur; |
1986 | } |
2084 | } |
1987 | |
2085 | |
1988 | noinline ecb_cold |
2086 | ecb_noinline ecb_cold |
1989 | static void * |
2087 | static void * |
1990 | array_realloc (int elem, void *base, int *cur, int cnt) |
2088 | array_realloc (int elem, void *base, int *cur, int cnt) |
1991 | { |
2089 | { |
1992 | *cur = array_nextsize (elem, *cur, cnt); |
2090 | *cur = array_nextsize (elem, *cur, cnt); |
1993 | return ev_realloc (base, elem * *cur); |
2091 | return ev_realloc (base, elem * *cur); |
… | |
… | |
1997 | |
2095 | |
1998 | #define array_needsize_zerofill(base,offset,count) \ |
2096 | #define array_needsize_zerofill(base,offset,count) \ |
1999 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
2097 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
2000 | |
2098 | |
2001 | #define array_needsize(type,base,cur,cnt,init) \ |
2099 | #define array_needsize(type,base,cur,cnt,init) \ |
2002 | if (expect_false ((cnt) > (cur))) \ |
2100 | if (ecb_expect_false ((cnt) > (cur))) \ |
2003 | { \ |
2101 | { \ |
2004 | ecb_unused int ocur_ = (cur); \ |
2102 | ecb_unused int ocur_ = (cur); \ |
2005 | (base) = (type *)array_realloc \ |
2103 | (base) = (type *)array_realloc \ |
2006 | (sizeof (type), (base), &(cur), (cnt)); \ |
2104 | (sizeof (type), (base), &(cur), (cnt)); \ |
2007 | init ((base), ocur_, ((cur) - ocur_)); \ |
2105 | init ((base), ocur_, ((cur) - ocur_)); \ |
… | |
… | |
2021 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2119 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2022 | |
2120 | |
2023 | /*****************************************************************************/ |
2121 | /*****************************************************************************/ |
2024 | |
2122 | |
2025 | /* dummy callback for pending events */ |
2123 | /* dummy callback for pending events */ |
2026 | noinline |
2124 | ecb_noinline |
2027 | static void |
2125 | static void |
2028 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2126 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2029 | { |
2127 | { |
2030 | } |
2128 | } |
2031 | |
2129 | |
2032 | noinline |
2130 | ecb_noinline |
2033 | void |
2131 | void |
2034 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2132 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2035 | { |
2133 | { |
2036 | W w_ = (W)w; |
2134 | W w_ = (W)w; |
2037 | int pri = ABSPRI (w_); |
2135 | int pri = ABSPRI (w_); |
2038 | |
2136 | |
2039 | if (expect_false (w_->pending)) |
2137 | if (ecb_expect_false (w_->pending)) |
2040 | pendings [pri][w_->pending - 1].events |= revents; |
2138 | pendings [pri][w_->pending - 1].events |= revents; |
2041 | else |
2139 | else |
2042 | { |
2140 | { |
2043 | w_->pending = ++pendingcnt [pri]; |
2141 | w_->pending = ++pendingcnt [pri]; |
2044 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2142 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
… | |
… | |
2095 | inline_speed void |
2193 | inline_speed void |
2096 | fd_event (EV_P_ int fd, int revents) |
2194 | fd_event (EV_P_ int fd, int revents) |
2097 | { |
2195 | { |
2098 | ANFD *anfd = anfds + fd; |
2196 | ANFD *anfd = anfds + fd; |
2099 | |
2197 | |
2100 | if (expect_true (!anfd->reify)) |
2198 | if (ecb_expect_true (!anfd->reify)) |
2101 | fd_event_nocheck (EV_A_ fd, revents); |
2199 | fd_event_nocheck (EV_A_ fd, revents); |
2102 | } |
2200 | } |
2103 | |
2201 | |
2104 | void |
2202 | void |
2105 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2203 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
… | |
… | |
2149 | unsigned char o_events = anfd->events; |
2247 | unsigned char o_events = anfd->events; |
2150 | unsigned char o_reify = anfd->reify; |
2248 | unsigned char o_reify = anfd->reify; |
2151 | |
2249 | |
2152 | anfd->reify = 0; |
2250 | anfd->reify = 0; |
2153 | |
2251 | |
2154 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2252 | /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2155 | { |
2253 | { |
2156 | anfd->events = 0; |
2254 | anfd->events = 0; |
2157 | |
2255 | |
2158 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2256 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2159 | anfd->events |= (unsigned char)w->events; |
2257 | anfd->events |= (unsigned char)w->events; |
… | |
… | |
2175 | fd_change (EV_P_ int fd, int flags) |
2273 | fd_change (EV_P_ int fd, int flags) |
2176 | { |
2274 | { |
2177 | unsigned char reify = anfds [fd].reify; |
2275 | unsigned char reify = anfds [fd].reify; |
2178 | anfds [fd].reify |= flags; |
2276 | anfds [fd].reify |= flags; |
2179 | |
2277 | |
2180 | if (expect_true (!reify)) |
2278 | if (ecb_expect_true (!reify)) |
2181 | { |
2279 | { |
2182 | ++fdchangecnt; |
2280 | ++fdchangecnt; |
2183 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2281 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2184 | fdchanges [fdchangecnt - 1] = fd; |
2282 | fdchanges [fdchangecnt - 1] = fd; |
2185 | } |
2283 | } |
… | |
… | |
2208 | return fcntl (fd, F_GETFD) != -1; |
2306 | return fcntl (fd, F_GETFD) != -1; |
2209 | #endif |
2307 | #endif |
2210 | } |
2308 | } |
2211 | |
2309 | |
2212 | /* called on EBADF to verify fds */ |
2310 | /* called on EBADF to verify fds */ |
2213 | noinline ecb_cold |
2311 | ecb_noinline ecb_cold |
2214 | static void |
2312 | static void |
2215 | fd_ebadf (EV_P) |
2313 | fd_ebadf (EV_P) |
2216 | { |
2314 | { |
2217 | int fd; |
2315 | int fd; |
2218 | |
2316 | |
… | |
… | |
2221 | if (!fd_valid (fd) && errno == EBADF) |
2319 | if (!fd_valid (fd) && errno == EBADF) |
2222 | fd_kill (EV_A_ fd); |
2320 | fd_kill (EV_A_ fd); |
2223 | } |
2321 | } |
2224 | |
2322 | |
2225 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2323 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2226 | noinline ecb_cold |
2324 | ecb_noinline ecb_cold |
2227 | static void |
2325 | static void |
2228 | fd_enomem (EV_P) |
2326 | fd_enomem (EV_P) |
2229 | { |
2327 | { |
2230 | int fd; |
2328 | int fd; |
2231 | |
2329 | |
… | |
… | |
2236 | break; |
2334 | break; |
2237 | } |
2335 | } |
2238 | } |
2336 | } |
2239 | |
2337 | |
2240 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2338 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2241 | noinline |
2339 | ecb_noinline |
2242 | static void |
2340 | static void |
2243 | fd_rearm_all (EV_P) |
2341 | fd_rearm_all (EV_P) |
2244 | { |
2342 | { |
2245 | int fd; |
2343 | int fd; |
2246 | |
2344 | |
… | |
… | |
2300 | ev_tstamp minat; |
2398 | ev_tstamp minat; |
2301 | ANHE *minpos; |
2399 | ANHE *minpos; |
2302 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2400 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2303 | |
2401 | |
2304 | /* find minimum child */ |
2402 | /* find minimum child */ |
2305 | if (expect_true (pos + DHEAP - 1 < E)) |
2403 | if (ecb_expect_true (pos + DHEAP - 1 < E)) |
2306 | { |
2404 | { |
2307 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2405 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2308 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2406 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2309 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2407 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2310 | if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2408 | if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
… | |
… | |
2428 | |
2526 | |
2429 | /*****************************************************************************/ |
2527 | /*****************************************************************************/ |
2430 | |
2528 | |
2431 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2529 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2432 | |
2530 | |
2433 | noinline ecb_cold |
2531 | ecb_noinline ecb_cold |
2434 | static void |
2532 | static void |
2435 | evpipe_init (EV_P) |
2533 | evpipe_init (EV_P) |
2436 | { |
2534 | { |
2437 | if (!ev_is_active (&pipe_w)) |
2535 | if (!ev_is_active (&pipe_w)) |
2438 | { |
2536 | { |
… | |
… | |
2479 | inline_speed void |
2577 | inline_speed void |
2480 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2578 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2481 | { |
2579 | { |
2482 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2580 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2483 | |
2581 | |
2484 | if (expect_true (*flag)) |
2582 | if (ecb_expect_true (*flag)) |
2485 | return; |
2583 | return; |
2486 | |
2584 | |
2487 | *flag = 1; |
2585 | *flag = 1; |
2488 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2586 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2489 | |
2587 | |
… | |
… | |
2566 | sig_pending = 0; |
2664 | sig_pending = 0; |
2567 | |
2665 | |
2568 | ECB_MEMORY_FENCE; |
2666 | ECB_MEMORY_FENCE; |
2569 | |
2667 | |
2570 | for (i = EV_NSIG - 1; i--; ) |
2668 | for (i = EV_NSIG - 1; i--; ) |
2571 | if (expect_false (signals [i].pending)) |
2669 | if (ecb_expect_false (signals [i].pending)) |
2572 | ev_feed_signal_event (EV_A_ i + 1); |
2670 | ev_feed_signal_event (EV_A_ i + 1); |
2573 | } |
2671 | } |
2574 | #endif |
2672 | #endif |
2575 | |
2673 | |
2576 | #if EV_ASYNC_ENABLE |
2674 | #if EV_ASYNC_ENABLE |
… | |
… | |
2617 | #endif |
2715 | #endif |
2618 | |
2716 | |
2619 | ev_feed_signal (signum); |
2717 | ev_feed_signal (signum); |
2620 | } |
2718 | } |
2621 | |
2719 | |
2622 | noinline |
2720 | ecb_noinline |
2623 | void |
2721 | void |
2624 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2722 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2625 | { |
2723 | { |
2626 | WL w; |
2724 | WL w; |
2627 | |
2725 | |
2628 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2726 | if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG)) |
2629 | return; |
2727 | return; |
2630 | |
2728 | |
2631 | --signum; |
2729 | --signum; |
2632 | |
2730 | |
2633 | #if EV_MULTIPLICITY |
2731 | #if EV_MULTIPLICITY |
2634 | /* it is permissible to try to feed a signal to the wrong loop */ |
2732 | /* 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 */ |
2733 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
2636 | |
2734 | |
2637 | if (expect_false (signals [signum].loop != EV_A)) |
2735 | if (ecb_expect_false (signals [signum].loop != EV_A)) |
2638 | return; |
2736 | return; |
2639 | #endif |
2737 | #endif |
2640 | |
2738 | |
2641 | signals [signum].pending = 0; |
2739 | signals [signum].pending = 0; |
2642 | ECB_MEMORY_FENCE_RELEASE; |
2740 | ECB_MEMORY_FENCE_RELEASE; |
… | |
… | |
2741 | # include "ev_epoll.c" |
2839 | # include "ev_epoll.c" |
2742 | #endif |
2840 | #endif |
2743 | #if EV_USE_LINUXAIO |
2841 | #if EV_USE_LINUXAIO |
2744 | # include "ev_linuxaio.c" |
2842 | # include "ev_linuxaio.c" |
2745 | #endif |
2843 | #endif |
|
|
2844 | #if EV_USE_IOURING |
|
|
2845 | # include "ev_iouring.c" |
|
|
2846 | #endif |
2746 | #if EV_USE_POLL |
2847 | #if EV_USE_POLL |
2747 | # include "ev_poll.c" |
2848 | # include "ev_poll.c" |
2748 | #endif |
2849 | #endif |
2749 | #if EV_USE_SELECT |
2850 | #if EV_USE_SELECT |
2750 | # include "ev_select.c" |
2851 | # include "ev_select.c" |
… | |
… | |
2782 | |
2883 | |
2783 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2884 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2784 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2885 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2785 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2886 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2786 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2887 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
|
|
2888 | if (EV_USE_IOURING ) flags |= EVBACKEND_IOURING; |
2787 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2889 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2788 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2890 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2789 | |
2891 | |
2790 | return flags; |
2892 | return flags; |
2791 | } |
2893 | } |
… | |
… | |
2812 | |
2914 | |
2813 | /* TODO: linuxaio is very experimental */ |
2915 | /* TODO: linuxaio is very experimental */ |
2814 | #if !EV_RECOMMEND_LINUXAIO |
2916 | #if !EV_RECOMMEND_LINUXAIO |
2815 | flags &= ~EVBACKEND_LINUXAIO; |
2917 | flags &= ~EVBACKEND_LINUXAIO; |
2816 | #endif |
2918 | #endif |
|
|
2919 | /* TODO: linuxaio is super experimental */ |
|
|
2920 | #if !EV_RECOMMEND_IOURING |
|
|
2921 | flags &= ~EVBACKEND_IOURING; |
|
|
2922 | #endif |
2817 | |
2923 | |
2818 | return flags; |
2924 | return flags; |
2819 | } |
2925 | } |
2820 | |
2926 | |
2821 | ecb_cold |
2927 | ecb_cold |
… | |
… | |
2826 | |
2932 | |
2827 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2933 | /* 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 */ |
2934 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2829 | flags &= ~EVBACKEND_EPOLL; |
2935 | flags &= ~EVBACKEND_EPOLL; |
2830 | |
2936 | |
|
|
2937 | /* EVBACKEND_LINUXAIO is theoretically embeddable, but suffers from a performance overhead */ |
|
|
2938 | |
|
|
2939 | /* EVBACKEND_IOURING is practically embeddable, but the current implementation is not |
|
|
2940 | * because our backend_fd is the epoll fd we need as fallback. |
|
|
2941 | * if the kernel ever is fixed, this might change... |
|
|
2942 | */ |
|
|
2943 | |
2831 | return flags; |
2944 | return flags; |
2832 | } |
2945 | } |
2833 | |
2946 | |
2834 | unsigned int |
2947 | unsigned int |
2835 | ev_backend (EV_P) EV_NOEXCEPT |
2948 | ev_backend (EV_P) EV_NOEXCEPT |
… | |
… | |
2887 | acquire_cb = acquire; |
3000 | acquire_cb = acquire; |
2888 | } |
3001 | } |
2889 | #endif |
3002 | #endif |
2890 | |
3003 | |
2891 | /* initialise a loop structure, must be zero-initialised */ |
3004 | /* initialise a loop structure, must be zero-initialised */ |
2892 | noinline ecb_cold |
3005 | ecb_noinline ecb_cold |
2893 | static void |
3006 | static void |
2894 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
3007 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2895 | { |
3008 | { |
2896 | if (!backend) |
3009 | if (!backend) |
2897 | { |
3010 | { |
… | |
… | |
2965 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
3078 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2966 | #endif |
3079 | #endif |
2967 | #if EV_USE_KQUEUE |
3080 | #if EV_USE_KQUEUE |
2968 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
3081 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
2969 | #endif |
3082 | #endif |
|
|
3083 | #if EV_USE_IOURING |
|
|
3084 | if (!backend && (flags & EVBACKEND_IOURING )) backend = iouring_init (EV_A_ flags); |
|
|
3085 | #endif |
2970 | #if EV_USE_LINUXAIO |
3086 | #if EV_USE_LINUXAIO |
2971 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
3087 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2972 | #endif |
3088 | #endif |
2973 | #if EV_USE_EPOLL |
3089 | #if EV_USE_EPOLL |
2974 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
3090 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
… | |
… | |
3002 | return; |
3118 | return; |
3003 | #endif |
3119 | #endif |
3004 | |
3120 | |
3005 | #if EV_CLEANUP_ENABLE |
3121 | #if EV_CLEANUP_ENABLE |
3006 | /* queue cleanup watchers (and execute them) */ |
3122 | /* queue cleanup watchers (and execute them) */ |
3007 | if (expect_false (cleanupcnt)) |
3123 | if (ecb_expect_false (cleanupcnt)) |
3008 | { |
3124 | { |
3009 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
3125 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
3010 | EV_INVOKE_PENDING; |
3126 | EV_INVOKE_PENDING; |
3011 | } |
3127 | } |
3012 | #endif |
3128 | #endif |
… | |
… | |
3047 | #if EV_USE_PORT |
3163 | #if EV_USE_PORT |
3048 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3164 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3049 | #endif |
3165 | #endif |
3050 | #if EV_USE_KQUEUE |
3166 | #if EV_USE_KQUEUE |
3051 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
3167 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3168 | #endif |
|
|
3169 | #if EV_USE_IOURING |
|
|
3170 | if (backend == EVBACKEND_IOURING ) iouring_destroy (EV_A); |
3052 | #endif |
3171 | #endif |
3053 | #if EV_USE_LINUXAIO |
3172 | #if EV_USE_LINUXAIO |
3054 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3173 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3055 | #endif |
3174 | #endif |
3056 | #if EV_USE_EPOLL |
3175 | #if EV_USE_EPOLL |
… | |
… | |
3115 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3234 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3116 | #endif |
3235 | #endif |
3117 | #if EV_USE_KQUEUE |
3236 | #if EV_USE_KQUEUE |
3118 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
3237 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
3119 | #endif |
3238 | #endif |
|
|
3239 | #if EV_USE_IOURING |
|
|
3240 | if (backend == EVBACKEND_IOURING ) iouring_fork (EV_A); |
|
|
3241 | #endif |
3120 | #if EV_USE_LINUXAIO |
3242 | #if EV_USE_LINUXAIO |
3121 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3243 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3122 | #endif |
3244 | #endif |
3123 | #if EV_USE_EPOLL |
3245 | #if EV_USE_EPOLL |
3124 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3246 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
… | |
… | |
3166 | } |
3288 | } |
3167 | |
3289 | |
3168 | #endif /* multiplicity */ |
3290 | #endif /* multiplicity */ |
3169 | |
3291 | |
3170 | #if EV_VERIFY |
3292 | #if EV_VERIFY |
3171 | noinline ecb_cold |
3293 | ecb_noinline ecb_cold |
3172 | static void |
3294 | static void |
3173 | verify_watcher (EV_P_ W w) |
3295 | verify_watcher (EV_P_ W w) |
3174 | { |
3296 | { |
3175 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3297 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3176 | |
3298 | |
3177 | if (w->pending) |
3299 | if (w->pending) |
3178 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3300 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3179 | } |
3301 | } |
3180 | |
3302 | |
3181 | noinline ecb_cold |
3303 | ecb_noinline ecb_cold |
3182 | static void |
3304 | static void |
3183 | verify_heap (EV_P_ ANHE *heap, int N) |
3305 | verify_heap (EV_P_ ANHE *heap, int N) |
3184 | { |
3306 | { |
3185 | int i; |
3307 | int i; |
3186 | |
3308 | |
… | |
… | |
3192 | |
3314 | |
3193 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3315 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3194 | } |
3316 | } |
3195 | } |
3317 | } |
3196 | |
3318 | |
3197 | noinline ecb_cold |
3319 | ecb_noinline ecb_cold |
3198 | static void |
3320 | static void |
3199 | array_verify (EV_P_ W *ws, int cnt) |
3321 | array_verify (EV_P_ W *ws, int cnt) |
3200 | { |
3322 | { |
3201 | while (cnt--) |
3323 | while (cnt--) |
3202 | { |
3324 | { |
… | |
… | |
3351 | count += pendingcnt [pri]; |
3473 | count += pendingcnt [pri]; |
3352 | |
3474 | |
3353 | return count; |
3475 | return count; |
3354 | } |
3476 | } |
3355 | |
3477 | |
3356 | noinline |
3478 | ecb_noinline |
3357 | void |
3479 | void |
3358 | ev_invoke_pending (EV_P) |
3480 | ev_invoke_pending (EV_P) |
3359 | { |
3481 | { |
3360 | pendingpri = NUMPRI; |
3482 | pendingpri = NUMPRI; |
3361 | |
3483 | |
… | |
… | |
3380 | /* make idle watchers pending. this handles the "call-idle */ |
3502 | /* make idle watchers pending. this handles the "call-idle */ |
3381 | /* only when higher priorities are idle" logic */ |
3503 | /* only when higher priorities are idle" logic */ |
3382 | inline_size void |
3504 | inline_size void |
3383 | idle_reify (EV_P) |
3505 | idle_reify (EV_P) |
3384 | { |
3506 | { |
3385 | if (expect_false (idleall)) |
3507 | if (ecb_expect_false (idleall)) |
3386 | { |
3508 | { |
3387 | int pri; |
3509 | int pri; |
3388 | |
3510 | |
3389 | for (pri = NUMPRI; pri--; ) |
3511 | for (pri = NUMPRI; pri--; ) |
3390 | { |
3512 | { |
… | |
… | |
3439 | } |
3561 | } |
3440 | } |
3562 | } |
3441 | |
3563 | |
3442 | #if EV_PERIODIC_ENABLE |
3564 | #if EV_PERIODIC_ENABLE |
3443 | |
3565 | |
3444 | noinline |
3566 | ecb_noinline |
3445 | static void |
3567 | static void |
3446 | periodic_recalc (EV_P_ ev_periodic *w) |
3568 | periodic_recalc (EV_P_ ev_periodic *w) |
3447 | { |
3569 | { |
3448 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3570 | 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); |
3571 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
… | |
… | |
3452 | while (at <= ev_rt_now) |
3574 | while (at <= ev_rt_now) |
3453 | { |
3575 | { |
3454 | ev_tstamp nat = at + w->interval; |
3576 | ev_tstamp nat = at + w->interval; |
3455 | |
3577 | |
3456 | /* when resolution fails us, we use ev_rt_now */ |
3578 | /* when resolution fails us, we use ev_rt_now */ |
3457 | if (expect_false (nat == at)) |
3579 | if (ecb_expect_false (nat == at)) |
3458 | { |
3580 | { |
3459 | at = ev_rt_now; |
3581 | at = ev_rt_now; |
3460 | break; |
3582 | break; |
3461 | } |
3583 | } |
3462 | |
3584 | |
… | |
… | |
3508 | } |
3630 | } |
3509 | } |
3631 | } |
3510 | |
3632 | |
3511 | /* simply recalculate all periodics */ |
3633 | /* simply recalculate all periodics */ |
3512 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3634 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3513 | noinline ecb_cold |
3635 | ecb_noinline ecb_cold |
3514 | static void |
3636 | static void |
3515 | periodics_reschedule (EV_P) |
3637 | periodics_reschedule (EV_P) |
3516 | { |
3638 | { |
3517 | int i; |
3639 | int i; |
3518 | |
3640 | |
… | |
… | |
3532 | reheap (periodics, periodiccnt); |
3654 | reheap (periodics, periodiccnt); |
3533 | } |
3655 | } |
3534 | #endif |
3656 | #endif |
3535 | |
3657 | |
3536 | /* adjust all timers by a given offset */ |
3658 | /* adjust all timers by a given offset */ |
3537 | noinline ecb_cold |
3659 | ecb_noinline ecb_cold |
3538 | static void |
3660 | static void |
3539 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3661 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3540 | { |
3662 | { |
3541 | int i; |
3663 | int i; |
3542 | |
3664 | |
… | |
… | |
3552 | /* also detect if there was a timejump, and act accordingly */ |
3674 | /* also detect if there was a timejump, and act accordingly */ |
3553 | inline_speed void |
3675 | inline_speed void |
3554 | time_update (EV_P_ ev_tstamp max_block) |
3676 | time_update (EV_P_ ev_tstamp max_block) |
3555 | { |
3677 | { |
3556 | #if EV_USE_MONOTONIC |
3678 | #if EV_USE_MONOTONIC |
3557 | if (expect_true (have_monotonic)) |
3679 | if (ecb_expect_true (have_monotonic)) |
3558 | { |
3680 | { |
3559 | int i; |
3681 | int i; |
3560 | ev_tstamp odiff = rtmn_diff; |
3682 | ev_tstamp odiff = rtmn_diff; |
3561 | |
3683 | |
3562 | mn_now = get_clock (); |
3684 | mn_now = get_clock (); |
3563 | |
3685 | |
3564 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3686 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3565 | /* interpolate in the meantime */ |
3687 | /* interpolate in the meantime */ |
3566 | if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) |
3688 | if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) |
3567 | { |
3689 | { |
3568 | ev_rt_now = rtmn_diff + mn_now; |
3690 | ev_rt_now = rtmn_diff + mn_now; |
3569 | return; |
3691 | return; |
3570 | } |
3692 | } |
3571 | |
3693 | |
… | |
… | |
3585 | ev_tstamp diff; |
3707 | ev_tstamp diff; |
3586 | rtmn_diff = ev_rt_now - mn_now; |
3708 | rtmn_diff = ev_rt_now - mn_now; |
3587 | |
3709 | |
3588 | diff = odiff - rtmn_diff; |
3710 | diff = odiff - rtmn_diff; |
3589 | |
3711 | |
3590 | if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) |
3712 | if (ecb_expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) |
3591 | return; /* all is well */ |
3713 | return; /* all is well */ |
3592 | |
3714 | |
3593 | ev_rt_now = ev_time (); |
3715 | ev_rt_now = ev_time (); |
3594 | mn_now = get_clock (); |
3716 | mn_now = get_clock (); |
3595 | now_floor = mn_now; |
3717 | now_floor = mn_now; |
… | |
… | |
3604 | else |
3726 | else |
3605 | #endif |
3727 | #endif |
3606 | { |
3728 | { |
3607 | ev_rt_now = ev_time (); |
3729 | ev_rt_now = ev_time (); |
3608 | |
3730 | |
3609 | if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) |
3731 | if (ecb_expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) |
3610 | { |
3732 | { |
3611 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
3733 | /* 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); |
3734 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3613 | #if EV_PERIODIC_ENABLE |
3735 | #if EV_PERIODIC_ENABLE |
3614 | periodics_reschedule (EV_A); |
3736 | periodics_reschedule (EV_A); |
… | |
… | |
3637 | #if EV_VERIFY >= 2 |
3759 | #if EV_VERIFY >= 2 |
3638 | ev_verify (EV_A); |
3760 | ev_verify (EV_A); |
3639 | #endif |
3761 | #endif |
3640 | |
3762 | |
3641 | #ifndef _WIN32 |
3763 | #ifndef _WIN32 |
3642 | if (expect_false (curpid)) /* penalise the forking check even more */ |
3764 | if (ecb_expect_false (curpid)) /* penalise the forking check even more */ |
3643 | if (expect_false (getpid () != curpid)) |
3765 | if (ecb_expect_false (getpid () != curpid)) |
3644 | { |
3766 | { |
3645 | curpid = getpid (); |
3767 | curpid = getpid (); |
3646 | postfork = 1; |
3768 | postfork = 1; |
3647 | } |
3769 | } |
3648 | #endif |
3770 | #endif |
3649 | |
3771 | |
3650 | #if EV_FORK_ENABLE |
3772 | #if EV_FORK_ENABLE |
3651 | /* we might have forked, so queue fork handlers */ |
3773 | /* we might have forked, so queue fork handlers */ |
3652 | if (expect_false (postfork)) |
3774 | if (ecb_expect_false (postfork)) |
3653 | if (forkcnt) |
3775 | if (forkcnt) |
3654 | { |
3776 | { |
3655 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3777 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3656 | EV_INVOKE_PENDING; |
3778 | EV_INVOKE_PENDING; |
3657 | } |
3779 | } |
3658 | #endif |
3780 | #endif |
3659 | |
3781 | |
3660 | #if EV_PREPARE_ENABLE |
3782 | #if EV_PREPARE_ENABLE |
3661 | /* queue prepare watchers (and execute them) */ |
3783 | /* queue prepare watchers (and execute them) */ |
3662 | if (expect_false (preparecnt)) |
3784 | if (ecb_expect_false (preparecnt)) |
3663 | { |
3785 | { |
3664 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3786 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3665 | EV_INVOKE_PENDING; |
3787 | EV_INVOKE_PENDING; |
3666 | } |
3788 | } |
3667 | #endif |
3789 | #endif |
3668 | |
3790 | |
3669 | if (expect_false (loop_done)) |
3791 | if (ecb_expect_false (loop_done)) |
3670 | break; |
3792 | break; |
3671 | |
3793 | |
3672 | /* we might have forked, so reify kernel state if necessary */ |
3794 | /* we might have forked, so reify kernel state if necessary */ |
3673 | if (expect_false (postfork)) |
3795 | if (ecb_expect_false (postfork)) |
3674 | loop_fork (EV_A); |
3796 | loop_fork (EV_A); |
3675 | |
3797 | |
3676 | /* update fd-related kernel structures */ |
3798 | /* update fd-related kernel structures */ |
3677 | fd_reify (EV_A); |
3799 | fd_reify (EV_A); |
3678 | |
3800 | |
… | |
… | |
3690 | /* from now on, we want a pipe-wake-up */ |
3812 | /* from now on, we want a pipe-wake-up */ |
3691 | pipe_write_wanted = 1; |
3813 | pipe_write_wanted = 1; |
3692 | |
3814 | |
3693 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3815 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3694 | |
3816 | |
3695 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3817 | if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3696 | { |
3818 | { |
3697 | waittime = MAX_BLOCKTIME; |
3819 | waittime = MAX_BLOCKTIME; |
3698 | |
3820 | |
3699 | if (timercnt) |
3821 | if (timercnt) |
3700 | { |
3822 | { |
… | |
… | |
3709 | if (waittime > to) waittime = to; |
3831 | if (waittime > to) waittime = to; |
3710 | } |
3832 | } |
3711 | #endif |
3833 | #endif |
3712 | |
3834 | |
3713 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3835 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3714 | if (expect_false (waittime < timeout_blocktime)) |
3836 | if (ecb_expect_false (waittime < timeout_blocktime)) |
3715 | waittime = timeout_blocktime; |
3837 | waittime = timeout_blocktime; |
3716 | |
3838 | |
3717 | /* at this point, we NEED to wait, so we have to ensure */ |
3839 | /* at this point, we NEED to wait, so we have to ensure */ |
3718 | /* to pass a minimum nonzero value to the backend */ |
3840 | /* to pass a minimum nonzero value to the backend */ |
3719 | if (expect_false (waittime < backend_mintime)) |
3841 | if (ecb_expect_false (waittime < backend_mintime)) |
3720 | waittime = backend_mintime; |
3842 | waittime = backend_mintime; |
3721 | |
3843 | |
3722 | /* extra check because io_blocktime is commonly 0 */ |
3844 | /* extra check because io_blocktime is commonly 0 */ |
3723 | if (expect_false (io_blocktime)) |
3845 | if (ecb_expect_false (io_blocktime)) |
3724 | { |
3846 | { |
3725 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3847 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3726 | |
3848 | |
3727 | if (sleeptime > waittime - backend_mintime) |
3849 | if (sleeptime > waittime - backend_mintime) |
3728 | sleeptime = waittime - backend_mintime; |
3850 | sleeptime = waittime - backend_mintime; |
3729 | |
3851 | |
3730 | if (expect_true (sleeptime > 0.)) |
3852 | if (ecb_expect_true (sleeptime > 0.)) |
3731 | { |
3853 | { |
3732 | ev_sleep (sleeptime); |
3854 | ev_sleep (sleeptime); |
3733 | waittime -= sleeptime; |
3855 | waittime -= sleeptime; |
3734 | } |
3856 | } |
3735 | } |
3857 | } |
… | |
… | |
3749 | { |
3871 | { |
3750 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3872 | 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); |
3873 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3752 | } |
3874 | } |
3753 | |
3875 | |
3754 | |
|
|
3755 | /* update ev_rt_now, do magic */ |
3876 | /* update ev_rt_now, do magic */ |
3756 | time_update (EV_A_ waittime + sleeptime); |
3877 | time_update (EV_A_ waittime + sleeptime); |
3757 | } |
3878 | } |
3758 | |
3879 | |
3759 | /* queue pending timers and reschedule them */ |
3880 | /* queue pending timers and reschedule them */ |
… | |
… | |
3767 | idle_reify (EV_A); |
3888 | idle_reify (EV_A); |
3768 | #endif |
3889 | #endif |
3769 | |
3890 | |
3770 | #if EV_CHECK_ENABLE |
3891 | #if EV_CHECK_ENABLE |
3771 | /* queue check watchers, to be executed first */ |
3892 | /* queue check watchers, to be executed first */ |
3772 | if (expect_false (checkcnt)) |
3893 | if (ecb_expect_false (checkcnt)) |
3773 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3894 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3774 | #endif |
3895 | #endif |
3775 | |
3896 | |
3776 | EV_INVOKE_PENDING; |
3897 | EV_INVOKE_PENDING; |
3777 | } |
3898 | } |
3778 | while (expect_true ( |
3899 | while (ecb_expect_true ( |
3779 | activecnt |
3900 | activecnt |
3780 | && !loop_done |
3901 | && !loop_done |
3781 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3902 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3782 | )); |
3903 | )); |
3783 | |
3904 | |
… | |
… | |
3847 | inline_size void |
3968 | inline_size void |
3848 | wlist_del (WL *head, WL elem) |
3969 | wlist_del (WL *head, WL elem) |
3849 | { |
3970 | { |
3850 | while (*head) |
3971 | while (*head) |
3851 | { |
3972 | { |
3852 | if (expect_true (*head == elem)) |
3973 | if (ecb_expect_true (*head == elem)) |
3853 | { |
3974 | { |
3854 | *head = elem->next; |
3975 | *head = elem->next; |
3855 | break; |
3976 | break; |
3856 | } |
3977 | } |
3857 | |
3978 | |
… | |
… | |
3874 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3995 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3875 | { |
3996 | { |
3876 | W w_ = (W)w; |
3997 | W w_ = (W)w; |
3877 | int pending = w_->pending; |
3998 | int pending = w_->pending; |
3878 | |
3999 | |
3879 | if (expect_true (pending)) |
4000 | if (ecb_expect_true (pending)) |
3880 | { |
4001 | { |
3881 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
4002 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
3882 | p->w = (W)&pending_w; |
4003 | p->w = (W)&pending_w; |
3883 | w_->pending = 0; |
4004 | w_->pending = 0; |
3884 | return p->events; |
4005 | return p->events; |
… | |
… | |
3911 | w->active = 0; |
4032 | w->active = 0; |
3912 | } |
4033 | } |
3913 | |
4034 | |
3914 | /*****************************************************************************/ |
4035 | /*****************************************************************************/ |
3915 | |
4036 | |
3916 | noinline |
4037 | ecb_noinline |
3917 | void |
4038 | void |
3918 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
4039 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3919 | { |
4040 | { |
3920 | int fd = w->fd; |
4041 | int fd = w->fd; |
3921 | |
4042 | |
3922 | if (expect_false (ev_is_active (w))) |
4043 | if (ecb_expect_false (ev_is_active (w))) |
3923 | return; |
4044 | return; |
3924 | |
4045 | |
3925 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
4046 | 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)))); |
4047 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3927 | |
4048 | |
… | |
… | |
3941 | w->events &= ~EV__IOFDSET; |
4062 | w->events &= ~EV__IOFDSET; |
3942 | |
4063 | |
3943 | EV_FREQUENT_CHECK; |
4064 | EV_FREQUENT_CHECK; |
3944 | } |
4065 | } |
3945 | |
4066 | |
3946 | noinline |
4067 | ecb_noinline |
3947 | void |
4068 | void |
3948 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
4069 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3949 | { |
4070 | { |
3950 | clear_pending (EV_A_ (W)w); |
4071 | clear_pending (EV_A_ (W)w); |
3951 | if (expect_false (!ev_is_active (w))) |
4072 | if (ecb_expect_false (!ev_is_active (w))) |
3952 | return; |
4073 | return; |
3953 | |
4074 | |
3954 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
4075 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3955 | |
4076 | |
3956 | #if EV_VERIFY >= 2 |
4077 | #if EV_VERIFY >= 2 |
… | |
… | |
3964 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
4085 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3965 | |
4086 | |
3966 | EV_FREQUENT_CHECK; |
4087 | EV_FREQUENT_CHECK; |
3967 | } |
4088 | } |
3968 | |
4089 | |
3969 | noinline |
4090 | ecb_noinline |
3970 | void |
4091 | void |
3971 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
4092 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3972 | { |
4093 | { |
3973 | if (expect_false (ev_is_active (w))) |
4094 | if (ecb_expect_false (ev_is_active (w))) |
3974 | return; |
4095 | return; |
3975 | |
4096 | |
3976 | ev_at (w) += mn_now; |
4097 | ev_at (w) += mn_now; |
3977 | |
4098 | |
3978 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
4099 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
… | |
… | |
3989 | EV_FREQUENT_CHECK; |
4110 | EV_FREQUENT_CHECK; |
3990 | |
4111 | |
3991 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
4112 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3992 | } |
4113 | } |
3993 | |
4114 | |
3994 | noinline |
4115 | ecb_noinline |
3995 | void |
4116 | void |
3996 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
4117 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3997 | { |
4118 | { |
3998 | clear_pending (EV_A_ (W)w); |
4119 | clear_pending (EV_A_ (W)w); |
3999 | if (expect_false (!ev_is_active (w))) |
4120 | if (ecb_expect_false (!ev_is_active (w))) |
4000 | return; |
4121 | return; |
4001 | |
4122 | |
4002 | EV_FREQUENT_CHECK; |
4123 | EV_FREQUENT_CHECK; |
4003 | |
4124 | |
4004 | { |
4125 | { |
… | |
… | |
4006 | |
4127 | |
4007 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
4128 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
4008 | |
4129 | |
4009 | --timercnt; |
4130 | --timercnt; |
4010 | |
4131 | |
4011 | if (expect_true (active < timercnt + HEAP0)) |
4132 | if (ecb_expect_true (active < timercnt + HEAP0)) |
4012 | { |
4133 | { |
4013 | timers [active] = timers [timercnt + HEAP0]; |
4134 | timers [active] = timers [timercnt + HEAP0]; |
4014 | adjustheap (timers, timercnt, active); |
4135 | adjustheap (timers, timercnt, active); |
4015 | } |
4136 | } |
4016 | } |
4137 | } |
… | |
… | |
4020 | ev_stop (EV_A_ (W)w); |
4141 | ev_stop (EV_A_ (W)w); |
4021 | |
4142 | |
4022 | EV_FREQUENT_CHECK; |
4143 | EV_FREQUENT_CHECK; |
4023 | } |
4144 | } |
4024 | |
4145 | |
4025 | noinline |
4146 | ecb_noinline |
4026 | void |
4147 | void |
4027 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
4148 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
4028 | { |
4149 | { |
4029 | EV_FREQUENT_CHECK; |
4150 | EV_FREQUENT_CHECK; |
4030 | |
4151 | |
… | |
… | |
4055 | { |
4176 | { |
4056 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4177 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4057 | } |
4178 | } |
4058 | |
4179 | |
4059 | #if EV_PERIODIC_ENABLE |
4180 | #if EV_PERIODIC_ENABLE |
4060 | noinline |
4181 | ecb_noinline |
4061 | void |
4182 | void |
4062 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4183 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4063 | { |
4184 | { |
4064 | if (expect_false (ev_is_active (w))) |
4185 | if (ecb_expect_false (ev_is_active (w))) |
4065 | return; |
4186 | return; |
4066 | |
4187 | |
4067 | if (w->reschedule_cb) |
4188 | if (w->reschedule_cb) |
4068 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
4189 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
4069 | else if (w->interval) |
4190 | else if (w->interval) |
… | |
… | |
4086 | EV_FREQUENT_CHECK; |
4207 | EV_FREQUENT_CHECK; |
4087 | |
4208 | |
4088 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4209 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4089 | } |
4210 | } |
4090 | |
4211 | |
4091 | noinline |
4212 | ecb_noinline |
4092 | void |
4213 | void |
4093 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4214 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4094 | { |
4215 | { |
4095 | clear_pending (EV_A_ (W)w); |
4216 | clear_pending (EV_A_ (W)w); |
4096 | if (expect_false (!ev_is_active (w))) |
4217 | if (ecb_expect_false (!ev_is_active (w))) |
4097 | return; |
4218 | return; |
4098 | |
4219 | |
4099 | EV_FREQUENT_CHECK; |
4220 | EV_FREQUENT_CHECK; |
4100 | |
4221 | |
4101 | { |
4222 | { |
… | |
… | |
4103 | |
4224 | |
4104 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4225 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4105 | |
4226 | |
4106 | --periodiccnt; |
4227 | --periodiccnt; |
4107 | |
4228 | |
4108 | if (expect_true (active < periodiccnt + HEAP0)) |
4229 | if (ecb_expect_true (active < periodiccnt + HEAP0)) |
4109 | { |
4230 | { |
4110 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4231 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4111 | adjustheap (periodics, periodiccnt, active); |
4232 | adjustheap (periodics, periodiccnt, active); |
4112 | } |
4233 | } |
4113 | } |
4234 | } |
… | |
… | |
4115 | ev_stop (EV_A_ (W)w); |
4236 | ev_stop (EV_A_ (W)w); |
4116 | |
4237 | |
4117 | EV_FREQUENT_CHECK; |
4238 | EV_FREQUENT_CHECK; |
4118 | } |
4239 | } |
4119 | |
4240 | |
4120 | noinline |
4241 | ecb_noinline |
4121 | void |
4242 | void |
4122 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4243 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4123 | { |
4244 | { |
4124 | /* TODO: use adjustheap and recalculation */ |
4245 | /* TODO: use adjustheap and recalculation */ |
4125 | ev_periodic_stop (EV_A_ w); |
4246 | ev_periodic_stop (EV_A_ w); |
… | |
… | |
4131 | # define SA_RESTART 0 |
4252 | # define SA_RESTART 0 |
4132 | #endif |
4253 | #endif |
4133 | |
4254 | |
4134 | #if EV_SIGNAL_ENABLE |
4255 | #if EV_SIGNAL_ENABLE |
4135 | |
4256 | |
4136 | noinline |
4257 | ecb_noinline |
4137 | void |
4258 | void |
4138 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4259 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4139 | { |
4260 | { |
4140 | if (expect_false (ev_is_active (w))) |
4261 | if (ecb_expect_false (ev_is_active (w))) |
4141 | return; |
4262 | return; |
4142 | |
4263 | |
4143 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4264 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4144 | |
4265 | |
4145 | #if EV_MULTIPLICITY |
4266 | #if EV_MULTIPLICITY |
… | |
… | |
4214 | } |
4335 | } |
4215 | |
4336 | |
4216 | EV_FREQUENT_CHECK; |
4337 | EV_FREQUENT_CHECK; |
4217 | } |
4338 | } |
4218 | |
4339 | |
4219 | noinline |
4340 | ecb_noinline |
4220 | void |
4341 | void |
4221 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4342 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4222 | { |
4343 | { |
4223 | clear_pending (EV_A_ (W)w); |
4344 | clear_pending (EV_A_ (W)w); |
4224 | if (expect_false (!ev_is_active (w))) |
4345 | if (ecb_expect_false (!ev_is_active (w))) |
4225 | return; |
4346 | return; |
4226 | |
4347 | |
4227 | EV_FREQUENT_CHECK; |
4348 | EV_FREQUENT_CHECK; |
4228 | |
4349 | |
4229 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
4350 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
… | |
… | |
4262 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4383 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4263 | { |
4384 | { |
4264 | #if EV_MULTIPLICITY |
4385 | #if EV_MULTIPLICITY |
4265 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4386 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4266 | #endif |
4387 | #endif |
4267 | if (expect_false (ev_is_active (w))) |
4388 | if (ecb_expect_false (ev_is_active (w))) |
4268 | return; |
4389 | return; |
4269 | |
4390 | |
4270 | EV_FREQUENT_CHECK; |
4391 | EV_FREQUENT_CHECK; |
4271 | |
4392 | |
4272 | ev_start (EV_A_ (W)w, 1); |
4393 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
4277 | |
4398 | |
4278 | void |
4399 | void |
4279 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4400 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4280 | { |
4401 | { |
4281 | clear_pending (EV_A_ (W)w); |
4402 | clear_pending (EV_A_ (W)w); |
4282 | if (expect_false (!ev_is_active (w))) |
4403 | if (ecb_expect_false (!ev_is_active (w))) |
4283 | return; |
4404 | return; |
4284 | |
4405 | |
4285 | EV_FREQUENT_CHECK; |
4406 | EV_FREQUENT_CHECK; |
4286 | |
4407 | |
4287 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
4408 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
… | |
… | |
4301 | |
4422 | |
4302 | #define DEF_STAT_INTERVAL 5.0074891 |
4423 | #define DEF_STAT_INTERVAL 5.0074891 |
4303 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4424 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4304 | #define MIN_STAT_INTERVAL 0.1074891 |
4425 | #define MIN_STAT_INTERVAL 0.1074891 |
4305 | |
4426 | |
4306 | noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4427 | ecb_noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4307 | |
4428 | |
4308 | #if EV_USE_INOTIFY |
4429 | #if EV_USE_INOTIFY |
4309 | |
4430 | |
4310 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4431 | /* 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) |
4432 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4312 | |
4433 | |
4313 | noinline |
4434 | ecb_noinline |
4314 | static void |
4435 | static void |
4315 | infy_add (EV_P_ ev_stat *w) |
4436 | infy_add (EV_P_ ev_stat *w) |
4316 | { |
4437 | { |
4317 | w->wd = inotify_add_watch (fs_fd, w->path, |
4438 | w->wd = inotify_add_watch (fs_fd, w->path, |
4318 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4439 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
… | |
… | |
4383 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4504 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4384 | ev_timer_again (EV_A_ &w->timer); |
4505 | ev_timer_again (EV_A_ &w->timer); |
4385 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4506 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4386 | } |
4507 | } |
4387 | |
4508 | |
4388 | noinline |
4509 | ecb_noinline |
4389 | static void |
4510 | static void |
4390 | infy_del (EV_P_ ev_stat *w) |
4511 | infy_del (EV_P_ ev_stat *w) |
4391 | { |
4512 | { |
4392 | int slot; |
4513 | int slot; |
4393 | int wd = w->wd; |
4514 | int wd = w->wd; |
… | |
… | |
4401 | |
4522 | |
4402 | /* remove this watcher, if others are watching it, they will rearm */ |
4523 | /* remove this watcher, if others are watching it, they will rearm */ |
4403 | inotify_rm_watch (fs_fd, wd); |
4524 | inotify_rm_watch (fs_fd, wd); |
4404 | } |
4525 | } |
4405 | |
4526 | |
4406 | noinline |
4527 | ecb_noinline |
4407 | static void |
4528 | static void |
4408 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4529 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4409 | { |
4530 | { |
4410 | if (slot < 0) |
4531 | if (slot < 0) |
4411 | /* overflow, need to check for all hash slots */ |
4532 | /* overflow, need to check for all hash slots */ |
… | |
… | |
4557 | w->attr.st_nlink = 0; |
4678 | w->attr.st_nlink = 0; |
4558 | else if (!w->attr.st_nlink) |
4679 | else if (!w->attr.st_nlink) |
4559 | w->attr.st_nlink = 1; |
4680 | w->attr.st_nlink = 1; |
4560 | } |
4681 | } |
4561 | |
4682 | |
4562 | noinline |
4683 | ecb_noinline |
4563 | static void |
4684 | static void |
4564 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4685 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4565 | { |
4686 | { |
4566 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4687 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4567 | |
4688 | |
… | |
… | |
4601 | } |
4722 | } |
4602 | |
4723 | |
4603 | void |
4724 | void |
4604 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4725 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4605 | { |
4726 | { |
4606 | if (expect_false (ev_is_active (w))) |
4727 | if (ecb_expect_false (ev_is_active (w))) |
4607 | return; |
4728 | return; |
4608 | |
4729 | |
4609 | ev_stat_stat (EV_A_ w); |
4730 | ev_stat_stat (EV_A_ w); |
4610 | |
4731 | |
4611 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
4732 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
… | |
… | |
4633 | |
4754 | |
4634 | void |
4755 | void |
4635 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4756 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4636 | { |
4757 | { |
4637 | clear_pending (EV_A_ (W)w); |
4758 | clear_pending (EV_A_ (W)w); |
4638 | if (expect_false (!ev_is_active (w))) |
4759 | if (ecb_expect_false (!ev_is_active (w))) |
4639 | return; |
4760 | return; |
4640 | |
4761 | |
4641 | EV_FREQUENT_CHECK; |
4762 | EV_FREQUENT_CHECK; |
4642 | |
4763 | |
4643 | #if EV_USE_INOTIFY |
4764 | #if EV_USE_INOTIFY |
… | |
… | |
4658 | |
4779 | |
4659 | #if EV_IDLE_ENABLE |
4780 | #if EV_IDLE_ENABLE |
4660 | void |
4781 | void |
4661 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4782 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4662 | { |
4783 | { |
4663 | if (expect_false (ev_is_active (w))) |
4784 | if (ecb_expect_false (ev_is_active (w))) |
4664 | return; |
4785 | return; |
4665 | |
4786 | |
4666 | pri_adjust (EV_A_ (W)w); |
4787 | pri_adjust (EV_A_ (W)w); |
4667 | |
4788 | |
4668 | EV_FREQUENT_CHECK; |
4789 | EV_FREQUENT_CHECK; |
… | |
… | |
4682 | |
4803 | |
4683 | void |
4804 | void |
4684 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4805 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4685 | { |
4806 | { |
4686 | clear_pending (EV_A_ (W)w); |
4807 | clear_pending (EV_A_ (W)w); |
4687 | if (expect_false (!ev_is_active (w))) |
4808 | if (ecb_expect_false (!ev_is_active (w))) |
4688 | return; |
4809 | return; |
4689 | |
4810 | |
4690 | EV_FREQUENT_CHECK; |
4811 | EV_FREQUENT_CHECK; |
4691 | |
4812 | |
4692 | { |
4813 | { |
… | |
… | |
4705 | |
4826 | |
4706 | #if EV_PREPARE_ENABLE |
4827 | #if EV_PREPARE_ENABLE |
4707 | void |
4828 | void |
4708 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4829 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4709 | { |
4830 | { |
4710 | if (expect_false (ev_is_active (w))) |
4831 | if (ecb_expect_false (ev_is_active (w))) |
4711 | return; |
4832 | return; |
4712 | |
4833 | |
4713 | EV_FREQUENT_CHECK; |
4834 | EV_FREQUENT_CHECK; |
4714 | |
4835 | |
4715 | ev_start (EV_A_ (W)w, ++preparecnt); |
4836 | ev_start (EV_A_ (W)w, ++preparecnt); |
… | |
… | |
4721 | |
4842 | |
4722 | void |
4843 | void |
4723 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4844 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4724 | { |
4845 | { |
4725 | clear_pending (EV_A_ (W)w); |
4846 | clear_pending (EV_A_ (W)w); |
4726 | if (expect_false (!ev_is_active (w))) |
4847 | if (ecb_expect_false (!ev_is_active (w))) |
4727 | return; |
4848 | return; |
4728 | |
4849 | |
4729 | EV_FREQUENT_CHECK; |
4850 | EV_FREQUENT_CHECK; |
4730 | |
4851 | |
4731 | { |
4852 | { |
… | |
… | |
4743 | |
4864 | |
4744 | #if EV_CHECK_ENABLE |
4865 | #if EV_CHECK_ENABLE |
4745 | void |
4866 | void |
4746 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4867 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4747 | { |
4868 | { |
4748 | if (expect_false (ev_is_active (w))) |
4869 | if (ecb_expect_false (ev_is_active (w))) |
4749 | return; |
4870 | return; |
4750 | |
4871 | |
4751 | EV_FREQUENT_CHECK; |
4872 | EV_FREQUENT_CHECK; |
4752 | |
4873 | |
4753 | ev_start (EV_A_ (W)w, ++checkcnt); |
4874 | ev_start (EV_A_ (W)w, ++checkcnt); |
… | |
… | |
4759 | |
4880 | |
4760 | void |
4881 | void |
4761 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4882 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4762 | { |
4883 | { |
4763 | clear_pending (EV_A_ (W)w); |
4884 | clear_pending (EV_A_ (W)w); |
4764 | if (expect_false (!ev_is_active (w))) |
4885 | if (ecb_expect_false (!ev_is_active (w))) |
4765 | return; |
4886 | return; |
4766 | |
4887 | |
4767 | EV_FREQUENT_CHECK; |
4888 | EV_FREQUENT_CHECK; |
4768 | |
4889 | |
4769 | { |
4890 | { |
… | |
… | |
4778 | EV_FREQUENT_CHECK; |
4899 | EV_FREQUENT_CHECK; |
4779 | } |
4900 | } |
4780 | #endif |
4901 | #endif |
4781 | |
4902 | |
4782 | #if EV_EMBED_ENABLE |
4903 | #if EV_EMBED_ENABLE |
4783 | noinline |
4904 | ecb_noinline |
4784 | void |
4905 | void |
4785 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4906 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4786 | { |
4907 | { |
4787 | ev_run (w->other, EVRUN_NOWAIT); |
4908 | ev_run (w->other, EVRUN_NOWAIT); |
4788 | } |
4909 | } |
… | |
… | |
4840 | #endif |
4961 | #endif |
4841 | |
4962 | |
4842 | void |
4963 | void |
4843 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4964 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4844 | { |
4965 | { |
4845 | if (expect_false (ev_is_active (w))) |
4966 | if (ecb_expect_false (ev_is_active (w))) |
4846 | return; |
4967 | return; |
4847 | |
4968 | |
4848 | { |
4969 | { |
4849 | EV_P = w->other; |
4970 | EV_P = w->other; |
4850 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
4971 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
… | |
… | |
4872 | |
4993 | |
4873 | void |
4994 | void |
4874 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4995 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4875 | { |
4996 | { |
4876 | clear_pending (EV_A_ (W)w); |
4997 | clear_pending (EV_A_ (W)w); |
4877 | if (expect_false (!ev_is_active (w))) |
4998 | if (ecb_expect_false (!ev_is_active (w))) |
4878 | return; |
4999 | return; |
4879 | |
5000 | |
4880 | EV_FREQUENT_CHECK; |
5001 | EV_FREQUENT_CHECK; |
4881 | |
5002 | |
4882 | ev_io_stop (EV_A_ &w->io); |
5003 | ev_io_stop (EV_A_ &w->io); |
… | |
… | |
4891 | |
5012 | |
4892 | #if EV_FORK_ENABLE |
5013 | #if EV_FORK_ENABLE |
4893 | void |
5014 | void |
4894 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
5015 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4895 | { |
5016 | { |
4896 | if (expect_false (ev_is_active (w))) |
5017 | if (ecb_expect_false (ev_is_active (w))) |
4897 | return; |
5018 | return; |
4898 | |
5019 | |
4899 | EV_FREQUENT_CHECK; |
5020 | EV_FREQUENT_CHECK; |
4900 | |
5021 | |
4901 | ev_start (EV_A_ (W)w, ++forkcnt); |
5022 | ev_start (EV_A_ (W)w, ++forkcnt); |
… | |
… | |
4907 | |
5028 | |
4908 | void |
5029 | void |
4909 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
5030 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4910 | { |
5031 | { |
4911 | clear_pending (EV_A_ (W)w); |
5032 | clear_pending (EV_A_ (W)w); |
4912 | if (expect_false (!ev_is_active (w))) |
5033 | if (ecb_expect_false (!ev_is_active (w))) |
4913 | return; |
5034 | return; |
4914 | |
5035 | |
4915 | EV_FREQUENT_CHECK; |
5036 | EV_FREQUENT_CHECK; |
4916 | |
5037 | |
4917 | { |
5038 | { |
… | |
… | |
4929 | |
5050 | |
4930 | #if EV_CLEANUP_ENABLE |
5051 | #if EV_CLEANUP_ENABLE |
4931 | void |
5052 | void |
4932 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
5053 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4933 | { |
5054 | { |
4934 | if (expect_false (ev_is_active (w))) |
5055 | if (ecb_expect_false (ev_is_active (w))) |
4935 | return; |
5056 | return; |
4936 | |
5057 | |
4937 | EV_FREQUENT_CHECK; |
5058 | EV_FREQUENT_CHECK; |
4938 | |
5059 | |
4939 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
5060 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
… | |
… | |
4947 | |
5068 | |
4948 | void |
5069 | void |
4949 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
5070 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4950 | { |
5071 | { |
4951 | clear_pending (EV_A_ (W)w); |
5072 | clear_pending (EV_A_ (W)w); |
4952 | if (expect_false (!ev_is_active (w))) |
5073 | if (ecb_expect_false (!ev_is_active (w))) |
4953 | return; |
5074 | return; |
4954 | |
5075 | |
4955 | EV_FREQUENT_CHECK; |
5076 | EV_FREQUENT_CHECK; |
4956 | ev_ref (EV_A); |
5077 | ev_ref (EV_A); |
4957 | |
5078 | |
… | |
… | |
4970 | |
5091 | |
4971 | #if EV_ASYNC_ENABLE |
5092 | #if EV_ASYNC_ENABLE |
4972 | void |
5093 | void |
4973 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
5094 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4974 | { |
5095 | { |
4975 | if (expect_false (ev_is_active (w))) |
5096 | if (ecb_expect_false (ev_is_active (w))) |
4976 | return; |
5097 | return; |
4977 | |
5098 | |
4978 | w->sent = 0; |
5099 | w->sent = 0; |
4979 | |
5100 | |
4980 | evpipe_init (EV_A); |
5101 | evpipe_init (EV_A); |
… | |
… | |
4990 | |
5111 | |
4991 | void |
5112 | void |
4992 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
5113 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4993 | { |
5114 | { |
4994 | clear_pending (EV_A_ (W)w); |
5115 | clear_pending (EV_A_ (W)w); |
4995 | if (expect_false (!ev_is_active (w))) |
5116 | if (ecb_expect_false (!ev_is_active (w))) |
4996 | return; |
5117 | return; |
4997 | |
5118 | |
4998 | EV_FREQUENT_CHECK; |
5119 | EV_FREQUENT_CHECK; |
4999 | |
5120 | |
5000 | { |
5121 | { |