… | |
… | |
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 |
… | |
… | |
1558 | # define inline_speed ecb_inline |
1599 | # define inline_speed ecb_inline |
1559 | #else |
1600 | #else |
1560 | # define inline_speed ecb_noinline static |
1601 | # define inline_speed ecb_noinline static |
1561 | #endif |
1602 | #endif |
1562 | |
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 | /*****************************************************************************/ |
|
|
1669 | |
1563 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1670 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1564 | |
1671 | |
1565 | #if EV_MINPRI == EV_MAXPRI |
1672 | #if EV_MINPRI == EV_MAXPRI |
1566 | # define ABSPRI(w) (((W)w), 0) |
1673 | # define ABSPRI(w) (((W)w), 0) |
1567 | #else |
1674 | #else |
… | |
… | |
1626 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1733 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1627 | #else |
1734 | #else |
1628 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1735 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1629 | #endif |
1736 | #endif |
1630 | |
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 | |
1631 | /* argument too large for an unsigned long? */ |
1746 | /* argument too large for an unsigned long? then reduce it */ |
1632 | if (ecb_expect_false (v >= shift)) |
1747 | if (ecb_expect_false (v >= shift)) |
1633 | { |
1748 | { |
1634 | ev_tstamp f; |
1749 | ev_tstamp f; |
1635 | |
1750 | |
1636 | if (v == v - 1.) |
1751 | if (v == v - 1.) |
1637 | return v; /* very large number */ |
1752 | return v; /* very large numbers are assumed to be integer */ |
1638 | |
1753 | |
1639 | f = shift * ev_floor (v * (1. / shift)); |
1754 | f = shift * ev_floor (v * (1. / shift)); |
1640 | return f + ev_floor (v - f); |
1755 | return f + ev_floor (v - f); |
1641 | } |
|
|
1642 | |
|
|
1643 | /* special treatment for negative args? */ |
|
|
1644 | if (ecb_expect_false (v < 0.)) |
|
|
1645 | { |
|
|
1646 | ev_tstamp f = -ev_floor (-v); |
|
|
1647 | |
|
|
1648 | return f - (f == v ? 0 : 1); |
|
|
1649 | } |
1756 | } |
1650 | |
1757 | |
1651 | /* fits into an unsigned long */ |
1758 | /* fits into an unsigned long */ |
1652 | return (unsigned long)v; |
1759 | return (unsigned long)v; |
1653 | } |
1760 | } |
… | |
… | |
1797 | { |
1904 | { |
1798 | WL head; |
1905 | WL head; |
1799 | unsigned char events; /* the events watched for */ |
1906 | unsigned char events; /* the events watched for */ |
1800 | 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) */ |
1801 | 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 */ |
1802 | unsigned char unused; |
1909 | unsigned char eflags; /* flags field for use by backends */ |
1803 | #if EV_USE_EPOLL |
1910 | #if EV_USE_EPOLL |
1804 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1911 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1805 | #endif |
1912 | #endif |
1806 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1913 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1807 | SOCKET handle; |
1914 | SOCKET handle; |
… | |
… | |
1861 | static struct ev_loop default_loop_struct; |
1968 | static struct ev_loop default_loop_struct; |
1862 | 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 */ |
1863 | |
1970 | |
1864 | #else |
1971 | #else |
1865 | |
1972 | |
1866 | 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 */ |
1867 | #define VAR(name,decl) static decl; |
1974 | #define VAR(name,decl) static decl; |
1868 | #include "ev_vars.h" |
1975 | #include "ev_vars.h" |
1869 | #undef VAR |
1976 | #undef VAR |
1870 | |
1977 | |
1871 | static int ev_default_loop_ptr; |
1978 | static int ev_default_loop_ptr; |
… | |
… | |
1893 | #if EV_USE_REALTIME |
2000 | #if EV_USE_REALTIME |
1894 | if (ecb_expect_true (have_realtime)) |
2001 | if (ecb_expect_true (have_realtime)) |
1895 | { |
2002 | { |
1896 | struct timespec ts; |
2003 | struct timespec ts; |
1897 | clock_gettime (CLOCK_REALTIME, &ts); |
2004 | clock_gettime (CLOCK_REALTIME, &ts); |
1898 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2005 | return EV_TS_GET (ts); |
1899 | } |
2006 | } |
1900 | #endif |
2007 | #endif |
1901 | |
2008 | |
1902 | struct timeval tv; |
2009 | struct timeval tv; |
1903 | gettimeofday (&tv, 0); |
2010 | gettimeofday (&tv, 0); |
1904 | return tv.tv_sec + tv.tv_usec * 1e-6; |
2011 | return EV_TV_GET (tv); |
1905 | } |
2012 | } |
1906 | #endif |
2013 | #endif |
1907 | |
2014 | |
1908 | inline_size ev_tstamp |
2015 | inline_size ev_tstamp |
1909 | get_clock (void) |
2016 | get_clock (void) |
… | |
… | |
1911 | #if EV_USE_MONOTONIC |
2018 | #if EV_USE_MONOTONIC |
1912 | if (ecb_expect_true (have_monotonic)) |
2019 | if (ecb_expect_true (have_monotonic)) |
1913 | { |
2020 | { |
1914 | struct timespec ts; |
2021 | struct timespec ts; |
1915 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2022 | clock_gettime (CLOCK_MONOTONIC, &ts); |
1916 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2023 | return EV_TS_GET (ts); |
1917 | } |
2024 | } |
1918 | #endif |
2025 | #endif |
1919 | |
2026 | |
1920 | return ev_time (); |
2027 | return ev_time (); |
1921 | } |
2028 | } |
… | |
… | |
1929 | #endif |
2036 | #endif |
1930 | |
2037 | |
1931 | void |
2038 | void |
1932 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
2039 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1933 | { |
2040 | { |
1934 | if (delay > 0.) |
2041 | if (delay > EV_TS_CONST (0.)) |
1935 | { |
2042 | { |
1936 | #if EV_USE_NANOSLEEP |
2043 | #if EV_USE_NANOSLEEP |
1937 | struct timespec ts; |
2044 | struct timespec ts; |
1938 | |
2045 | |
1939 | EV_TS_SET (ts, delay); |
2046 | EV_TS_SET (ts, delay); |
1940 | nanosleep (&ts, 0); |
2047 | nanosleep (&ts, 0); |
1941 | #elif defined _WIN32 |
2048 | #elif defined _WIN32 |
1942 | /* maybe this should round up, as ms is very low resolution */ |
2049 | /* maybe this should round up, as ms is very low resolution */ |
1943 | /* compared to select (µs) or nanosleep (ns) */ |
2050 | /* compared to select (µs) or nanosleep (ns) */ |
1944 | Sleep ((unsigned long)(delay * 1e3)); |
2051 | Sleep ((unsigned long)(EV_TS_TO_MSEC (delay))); |
1945 | #else |
2052 | #else |
1946 | struct timeval tv; |
2053 | struct timeval tv; |
1947 | |
2054 | |
1948 | /* 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 */ |
1949 | /* something not guaranteed by newer posix versions, but guaranteed */ |
2056 | /* something not guaranteed by newer posix versions, but guaranteed */ |
… | |
… | |
2299 | |
2406 | |
2300 | /* find minimum child */ |
2407 | /* find minimum child */ |
2301 | if (ecb_expect_true (pos + DHEAP - 1 < E)) |
2408 | if (ecb_expect_true (pos + DHEAP - 1 < E)) |
2302 | { |
2409 | { |
2303 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2410 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2304 | 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)); |
2305 | 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)); |
2306 | 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)); |
2307 | } |
2414 | } |
2308 | else if (pos < E) |
2415 | else if (pos < E) |
2309 | { |
2416 | { |
2310 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2417 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2311 | 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)); |
2312 | 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)); |
2313 | 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)); |
2314 | } |
2421 | } |
2315 | else |
2422 | else |
2316 | break; |
2423 | break; |
2317 | |
2424 | |
2318 | if (ANHE_at (he) <= minat) |
2425 | if (ANHE_at (he) <= minat) |
… | |
… | |
2326 | |
2433 | |
2327 | heap [k] = he; |
2434 | heap [k] = he; |
2328 | ev_active (ANHE_w (he)) = k; |
2435 | ev_active (ANHE_w (he)) = k; |
2329 | } |
2436 | } |
2330 | |
2437 | |
2331 | #else /* 4HEAP */ |
2438 | #else /* not 4HEAP */ |
2332 | |
2439 | |
2333 | #define HEAP0 1 |
2440 | #define HEAP0 1 |
2334 | #define HPARENT(k) ((k) >> 1) |
2441 | #define HPARENT(k) ((k) >> 1) |
2335 | #define UPHEAP_DONE(p,k) (!(p)) |
2442 | #define UPHEAP_DONE(p,k) (!(p)) |
2336 | |
2443 | |
… | |
… | |
2737 | # include "ev_epoll.c" |
2844 | # include "ev_epoll.c" |
2738 | #endif |
2845 | #endif |
2739 | #if EV_USE_LINUXAIO |
2846 | #if EV_USE_LINUXAIO |
2740 | # include "ev_linuxaio.c" |
2847 | # include "ev_linuxaio.c" |
2741 | #endif |
2848 | #endif |
|
|
2849 | #if EV_USE_IOURING |
|
|
2850 | # include "ev_iouring.c" |
|
|
2851 | #endif |
2742 | #if EV_USE_POLL |
2852 | #if EV_USE_POLL |
2743 | # include "ev_poll.c" |
2853 | # include "ev_poll.c" |
2744 | #endif |
2854 | #endif |
2745 | #if EV_USE_SELECT |
2855 | #if EV_USE_SELECT |
2746 | # include "ev_select.c" |
2856 | # include "ev_select.c" |
… | |
… | |
2778 | |
2888 | |
2779 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2889 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2780 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2890 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2781 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2891 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2782 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2892 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
|
|
2893 | if (EV_USE_IOURING ) flags |= EVBACKEND_IOURING; |
2783 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2894 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2784 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2895 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2785 | |
2896 | |
2786 | return flags; |
2897 | return flags; |
2787 | } |
2898 | } |
… | |
… | |
2808 | |
2919 | |
2809 | /* TODO: linuxaio is very experimental */ |
2920 | /* TODO: linuxaio is very experimental */ |
2810 | #if !EV_RECOMMEND_LINUXAIO |
2921 | #if !EV_RECOMMEND_LINUXAIO |
2811 | flags &= ~EVBACKEND_LINUXAIO; |
2922 | flags &= ~EVBACKEND_LINUXAIO; |
2812 | #endif |
2923 | #endif |
|
|
2924 | /* TODO: linuxaio is super experimental */ |
|
|
2925 | #if !EV_RECOMMEND_IOURING |
|
|
2926 | flags &= ~EVBACKEND_IOURING; |
|
|
2927 | #endif |
2813 | |
2928 | |
2814 | return flags; |
2929 | return flags; |
2815 | } |
2930 | } |
2816 | |
2931 | |
2817 | ecb_cold |
2932 | ecb_cold |
… | |
… | |
2821 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2936 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2822 | |
2937 | |
2823 | /* 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 */ |
2824 | 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 */ |
2825 | flags &= ~EVBACKEND_EPOLL; |
2940 | flags &= ~EVBACKEND_EPOLL; |
|
|
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 | */ |
2826 | |
2948 | |
2827 | return flags; |
2949 | return flags; |
2828 | } |
2950 | } |
2829 | |
2951 | |
2830 | unsigned int |
2952 | unsigned int |
… | |
… | |
2961 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
3083 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2962 | #endif |
3084 | #endif |
2963 | #if EV_USE_KQUEUE |
3085 | #if EV_USE_KQUEUE |
2964 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
3086 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
2965 | #endif |
3087 | #endif |
|
|
3088 | #if EV_USE_IOURING |
|
|
3089 | if (!backend && (flags & EVBACKEND_IOURING )) backend = iouring_init (EV_A_ flags); |
|
|
3090 | #endif |
2966 | #if EV_USE_LINUXAIO |
3091 | #if EV_USE_LINUXAIO |
2967 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
3092 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2968 | #endif |
3093 | #endif |
2969 | #if EV_USE_EPOLL |
3094 | #if EV_USE_EPOLL |
2970 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
3095 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
… | |
… | |
3043 | #if EV_USE_PORT |
3168 | #if EV_USE_PORT |
3044 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3169 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3045 | #endif |
3170 | #endif |
3046 | #if EV_USE_KQUEUE |
3171 | #if EV_USE_KQUEUE |
3047 | 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); |
3048 | #endif |
3176 | #endif |
3049 | #if EV_USE_LINUXAIO |
3177 | #if EV_USE_LINUXAIO |
3050 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3178 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3051 | #endif |
3179 | #endif |
3052 | #if EV_USE_EPOLL |
3180 | #if EV_USE_EPOLL |
… | |
… | |
3110 | #if EV_USE_PORT |
3238 | #if EV_USE_PORT |
3111 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3239 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3112 | #endif |
3240 | #endif |
3113 | #if EV_USE_KQUEUE |
3241 | #if EV_USE_KQUEUE |
3114 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
3242 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3243 | #endif |
|
|
3244 | #if EV_USE_IOURING |
|
|
3245 | if (backend == EVBACKEND_IOURING ) iouring_fork (EV_A); |
3115 | #endif |
3246 | #endif |
3116 | #if EV_USE_LINUXAIO |
3247 | #if EV_USE_LINUXAIO |
3117 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3248 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3118 | #endif |
3249 | #endif |
3119 | #if EV_USE_EPOLL |
3250 | #if EV_USE_EPOLL |
… | |
… | |
3416 | { |
3547 | { |
3417 | ev_at (w) += w->repeat; |
3548 | ev_at (w) += w->repeat; |
3418 | if (ev_at (w) < mn_now) |
3549 | if (ev_at (w) < mn_now) |
3419 | ev_at (w) = mn_now; |
3550 | ev_at (w) = mn_now; |
3420 | |
3551 | |
3421 | 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.))); |
3422 | |
3553 | |
3423 | ANHE_at_cache (timers [HEAP0]); |
3554 | ANHE_at_cache (timers [HEAP0]); |
3424 | downheap (timers, timercnt, HEAP0); |
3555 | downheap (timers, timercnt, HEAP0); |
3425 | } |
3556 | } |
3426 | else |
3557 | else |
… | |
… | |
3557 | |
3688 | |
3558 | mn_now = get_clock (); |
3689 | mn_now = get_clock (); |
3559 | |
3690 | |
3560 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3691 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3561 | /* interpolate in the meantime */ |
3692 | /* interpolate in the meantime */ |
3562 | if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) |
3693 | if (ecb_expect_true (mn_now - now_floor < EV_TS_CONST (MIN_TIMEJUMP * .5))) |
3563 | { |
3694 | { |
3564 | ev_rt_now = rtmn_diff + mn_now; |
3695 | ev_rt_now = rtmn_diff + mn_now; |
3565 | return; |
3696 | return; |
3566 | } |
3697 | } |
3567 | |
3698 | |
… | |
… | |
3581 | ev_tstamp diff; |
3712 | ev_tstamp diff; |
3582 | rtmn_diff = ev_rt_now - mn_now; |
3713 | rtmn_diff = ev_rt_now - mn_now; |
3583 | |
3714 | |
3584 | diff = odiff - rtmn_diff; |
3715 | diff = odiff - rtmn_diff; |
3585 | |
3716 | |
3586 | if (ecb_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))) |
3587 | return; /* all is well */ |
3718 | return; /* all is well */ |
3588 | |
3719 | |
3589 | ev_rt_now = ev_time (); |
3720 | ev_rt_now = ev_time (); |
3590 | mn_now = get_clock (); |
3721 | mn_now = get_clock (); |
3591 | now_floor = mn_now; |
3722 | now_floor = mn_now; |
… | |
… | |
3600 | else |
3731 | else |
3601 | #endif |
3732 | #endif |
3602 | { |
3733 | { |
3603 | ev_rt_now = ev_time (); |
3734 | ev_rt_now = ev_time (); |
3604 | |
3735 | |
3605 | if (ecb_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))) |
3606 | { |
3737 | { |
3607 | /* 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 */ |
3608 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3739 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3609 | #if EV_PERIODIC_ENABLE |
3740 | #if EV_PERIODIC_ENABLE |
3610 | periodics_reschedule (EV_A); |
3741 | periodics_reschedule (EV_A); |
… | |
… | |
3679 | |
3810 | |
3680 | /* remember old timestamp for io_blocktime calculation */ |
3811 | /* remember old timestamp for io_blocktime calculation */ |
3681 | ev_tstamp prev_mn_now = mn_now; |
3812 | ev_tstamp prev_mn_now = mn_now; |
3682 | |
3813 | |
3683 | /* update time to cancel out callback processing overhead */ |
3814 | /* update time to cancel out callback processing overhead */ |
3684 | time_update (EV_A_ 1e100); |
3815 | time_update (EV_A_ EV_TS_CONST (EV_TSTAMP_HUGE)); |
3685 | |
3816 | |
3686 | /* from now on, we want a pipe-wake-up */ |
3817 | /* from now on, we want a pipe-wake-up */ |
3687 | pipe_write_wanted = 1; |
3818 | pipe_write_wanted = 1; |
3688 | |
3819 | |
3689 | 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 */ |
3690 | |
3821 | |
3691 | if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3822 | if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3692 | { |
3823 | { |
3693 | waittime = MAX_BLOCKTIME; |
3824 | waittime = EV_TS_CONST (MAX_BLOCKTIME); |
3694 | |
3825 | |
3695 | if (timercnt) |
3826 | if (timercnt) |
3696 | { |
3827 | { |
3697 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3828 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3698 | if (waittime > to) waittime = to; |
3829 | if (waittime > to) waittime = to; |
… | |
… | |
3721 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3852 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3722 | |
3853 | |
3723 | if (sleeptime > waittime - backend_mintime) |
3854 | if (sleeptime > waittime - backend_mintime) |
3724 | sleeptime = waittime - backend_mintime; |
3855 | sleeptime = waittime - backend_mintime; |
3725 | |
3856 | |
3726 | if (ecb_expect_true (sleeptime > 0.)) |
3857 | if (ecb_expect_true (sleeptime > EV_TS_CONST (0.))) |
3727 | { |
3858 | { |
3728 | ev_sleep (sleeptime); |
3859 | ev_sleep (sleeptime); |
3729 | waittime -= sleeptime; |
3860 | waittime -= sleeptime; |
3730 | } |
3861 | } |
3731 | } |
3862 | } |
… | |
… | |
3805 | } |
3936 | } |
3806 | |
3937 | |
3807 | void |
3938 | void |
3808 | ev_now_update (EV_P) EV_NOEXCEPT |
3939 | ev_now_update (EV_P) EV_NOEXCEPT |
3809 | { |
3940 | { |
3810 | time_update (EV_A_ 1e100); |
3941 | time_update (EV_A_ EV_TSTAMP_HUGE); |
3811 | } |
3942 | } |
3812 | |
3943 | |
3813 | void |
3944 | void |
3814 | ev_suspend (EV_P) EV_NOEXCEPT |
3945 | ev_suspend (EV_P) EV_NOEXCEPT |
3815 | { |
3946 | { |
… | |
… | |
4046 | } |
4177 | } |
4047 | |
4178 | |
4048 | ev_tstamp |
4179 | ev_tstamp |
4049 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
4180 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
4050 | { |
4181 | { |
4051 | 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.)); |
4052 | } |
4183 | } |
4053 | |
4184 | |
4054 | #if EV_PERIODIC_ENABLE |
4185 | #if EV_PERIODIC_ENABLE |
4055 | ecb_noinline |
4186 | ecb_noinline |
4056 | void |
4187 | void |