… | |
… | |
447 | # endif |
447 | # endif |
448 | #endif |
448 | #endif |
449 | |
449 | |
450 | #if EV_USE_LINUXAIO |
450 | #if EV_USE_LINUXAIO |
451 | # include <sys/syscall.h> |
451 | # include <sys/syscall.h> |
452 | # 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 |
453 | # undef EV_USE_LINUXAIO |
455 | # undef EV_USE_LINUXAIO |
454 | # define EV_USE_LINUXAIO 0 |
456 | # define EV_USE_LINUXAIO 0 |
455 | # else |
|
|
456 | # define EV_NEED_SYSCALL 1 |
|
|
457 | # endif |
457 | # endif |
458 | #endif |
458 | #endif |
459 | |
459 | |
460 | #if EV_USE_IOURING |
460 | #if EV_USE_IOURING |
461 | # include <sys/syscall.h> |
461 | # include <sys/syscall.h> |
462 | # if !__alpha && !SYS_io_uring_setup |
462 | # if !SYS_io_uring_setup && __linux && !__alpha |
463 | # define SYS_io_uring_setup 425 |
463 | # define SYS_io_uring_setup 425 |
464 | # define SYS_io_uring_enter 426 |
464 | # define SYS_io_uring_enter 426 |
465 | # define SYS_io_uring_wregister 427 |
465 | # define SYS_io_uring_wregister 427 |
466 | # endif |
466 | # endif |
467 | # if SYS_io_uring_setup |
467 | # if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */ |
468 | # define EV_NEED_SYSCALL 1 |
468 | # define EV_NEED_SYSCALL 1 |
469 | # else |
469 | # else |
470 | # undef EV_USE_IOURING |
470 | # undef EV_USE_IOURING |
471 | # define EV_USE_IOURING 0 |
471 | # define EV_USE_IOURING 0 |
472 | # endif |
472 | # endif |
… | |
… | |
520 | }; |
520 | }; |
521 | #endif |
521 | #endif |
522 | |
522 | |
523 | /*****************************************************************************/ |
523 | /*****************************************************************************/ |
524 | |
524 | |
525 | #if EV_NEED_SYSCALL |
|
|
526 | |
|
|
527 | #include <sys/syscall.h> |
|
|
528 | |
|
|
529 | /* |
|
|
530 | * define some syscall wrappers for common architectures |
|
|
531 | * this is mostly for nice looks during debugging, not performance. |
|
|
532 | * our syscalls return < 0, not == -1, on error. which is good |
|
|
533 | * enough for linux aio. |
|
|
534 | * TODO: arm is also common nowadays, maybe even mips and x86 |
|
|
535 | * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove... |
|
|
536 | */ |
|
|
537 | #if __GNUC__ && __linux && ECB_AMD64 && !defined __OPTIMIZE_SIZE__ |
|
|
538 | /* the costly errno access probably kills this for size optimisation */ |
|
|
539 | |
|
|
540 | #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5) \ |
|
|
541 | ({ \ |
|
|
542 | long res; \ |
|
|
543 | register unsigned long r5 __asm__ ("r8" ); \ |
|
|
544 | register unsigned long r4 __asm__ ("r10"); \ |
|
|
545 | register unsigned long r3 __asm__ ("rdx"); \ |
|
|
546 | register unsigned long r2 __asm__ ("rsi"); \ |
|
|
547 | register unsigned long r1 __asm__ ("rdi"); \ |
|
|
548 | if (narg >= 5) r5 = (unsigned long)(arg5); \ |
|
|
549 | if (narg >= 4) r4 = (unsigned long)(arg4); \ |
|
|
550 | if (narg >= 3) r3 = (unsigned long)(arg3); \ |
|
|
551 | if (narg >= 2) r2 = (unsigned long)(arg2); \ |
|
|
552 | if (narg >= 1) r1 = (unsigned long)(arg1); \ |
|
|
553 | __asm__ __volatile__ ( \ |
|
|
554 | "syscall\n\t" \ |
|
|
555 | : "=a" (res) \ |
|
|
556 | : "0" (nr), "r" (r1), "r" (r2), "r" (r3), "r" (r4), "r" (r5) \ |
|
|
557 | : "cc", "r11", "cx", "memory"); \ |
|
|
558 | errno = -res; \ |
|
|
559 | res; \ |
|
|
560 | }) |
|
|
561 | |
|
|
562 | #endif |
|
|
563 | |
|
|
564 | #ifdef ev_syscall |
|
|
565 | #define ev_syscall0(nr) ev_syscall (nr, 0, 0, 0, 0, 0, 0 |
|
|
566 | #define ev_syscall1(nr,arg1) ev_syscall (nr, 1, arg1, 0, 0, 0, 0) |
|
|
567 | #define ev_syscall2(nr,arg1,arg2) ev_syscall (nr, 2, arg1, arg2, 0, 0, 0) |
|
|
568 | #define ev_syscall3(nr,arg1,arg2,arg3) ev_syscall (nr, 3, arg1, arg2, arg3, 0, 0) |
|
|
569 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) ev_syscall (nr, 3, arg1, arg2, arg3, arg4, 0) |
|
|
570 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) ev_syscall (nr, 5, arg1, arg2, arg3, arg4, arg5) |
|
|
571 | #else |
|
|
572 | #define ev_syscall0(nr) syscall (nr) |
|
|
573 | #define ev_syscall1(nr,arg1) syscall (nr, arg1) |
|
|
574 | #define ev_syscall2(nr,arg1,arg2) syscall (nr, arg1, arg2) |
|
|
575 | #define ev_syscall3(nr,arg1,arg2,arg3) syscall (nr, arg1, arg2, arg3) |
|
|
576 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) syscall (nr, arg1, arg2, arg3, arg4) |
|
|
577 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) syscall (nr, arg1, arg2, arg3, arg4, arg5) |
|
|
578 | #endif |
|
|
579 | |
|
|
580 | #endif |
|
|
581 | |
|
|
582 | /*****************************************************************************/ |
|
|
583 | |
|
|
584 | #if EV_VERIFY >= 3 |
525 | #if EV_VERIFY >= 3 |
585 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
526 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
586 | #else |
527 | #else |
587 | # define EV_FREQUENT_CHECK do { } while (0) |
528 | # define EV_FREQUENT_CHECK do { } while (0) |
588 | #endif |
529 | #endif |
… | |
… | |
592 | * This value is good at least till the year 4000. |
533 | * This value is good at least till the year 4000. |
593 | */ |
534 | */ |
594 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
535 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
595 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
536 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
596 | |
537 | |
597 | #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) */ |
598 | #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.) \ |
599 | |
548 | |
600 | #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) |
601 | #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) |
602 | |
553 | |
603 | /* 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 */ |
604 | /* ECB.H BEGIN */ |
555 | /* ECB.H BEGIN */ |
605 | /* |
556 | /* |
606 | * libecb - http://software.schmorp.de/pkg/libecb |
557 | * libecb - http://software.schmorp.de/pkg/libecb |
… | |
… | |
1643 | # define inline_speed ecb_inline |
1594 | # define inline_speed ecb_inline |
1644 | #else |
1595 | #else |
1645 | # define inline_speed ecb_noinline static |
1596 | # define inline_speed ecb_noinline static |
1646 | #endif |
1597 | #endif |
1647 | |
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 | /*****************************************************************************/ |
|
|
1664 | |
1648 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1665 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1649 | |
1666 | |
1650 | #if EV_MINPRI == EV_MAXPRI |
1667 | #if EV_MINPRI == EV_MAXPRI |
1651 | # define ABSPRI(w) (((W)w), 0) |
1668 | # define ABSPRI(w) (((W)w), 0) |
1652 | #else |
1669 | #else |
… | |
… | |
1711 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1728 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1712 | #else |
1729 | #else |
1713 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1730 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1714 | #endif |
1731 | #endif |
1715 | |
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 | |
1716 | /* argument too large for an unsigned long? */ |
1741 | /* argument too large for an unsigned long? then reduce it */ |
1717 | if (ecb_expect_false (v >= shift)) |
1742 | if (ecb_expect_false (v >= shift)) |
1718 | { |
1743 | { |
1719 | ev_tstamp f; |
1744 | ev_tstamp f; |
1720 | |
1745 | |
1721 | if (v == v - 1.) |
1746 | if (v == v - 1.) |
1722 | return v; /* very large number */ |
1747 | return v; /* very large numbers are assumed to be integer */ |
1723 | |
1748 | |
1724 | f = shift * ev_floor (v * (1. / shift)); |
1749 | f = shift * ev_floor (v * (1. / shift)); |
1725 | return f + ev_floor (v - f); |
1750 | return f + ev_floor (v - f); |
1726 | } |
|
|
1727 | |
|
|
1728 | /* special treatment for negative args? */ |
|
|
1729 | if (ecb_expect_false (v < 0.)) |
|
|
1730 | { |
|
|
1731 | ev_tstamp f = -ev_floor (-v); |
|
|
1732 | |
|
|
1733 | return f - (f == v ? 0 : 1); |
|
|
1734 | } |
1751 | } |
1735 | |
1752 | |
1736 | /* fits into an unsigned long */ |
1753 | /* fits into an unsigned long */ |
1737 | return (unsigned long)v; |
1754 | return (unsigned long)v; |
1738 | } |
1755 | } |
… | |
… | |
1882 | { |
1899 | { |
1883 | WL head; |
1900 | WL head; |
1884 | unsigned char events; /* the events watched for */ |
1901 | unsigned char events; /* the events watched for */ |
1885 | 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) */ |
1886 | 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 */ |
1887 | unsigned char unused; |
1904 | unsigned char eflags; /* flags field for use by backends */ |
1888 | #if EV_USE_EPOLL |
1905 | #if EV_USE_EPOLL |
1889 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1906 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1890 | #endif |
1907 | #endif |
1891 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1908 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1892 | SOCKET handle; |
1909 | SOCKET handle; |
… | |
… | |
1978 | #if EV_USE_REALTIME |
1995 | #if EV_USE_REALTIME |
1979 | if (ecb_expect_true (have_realtime)) |
1996 | if (ecb_expect_true (have_realtime)) |
1980 | { |
1997 | { |
1981 | struct timespec ts; |
1998 | struct timespec ts; |
1982 | clock_gettime (CLOCK_REALTIME, &ts); |
1999 | clock_gettime (CLOCK_REALTIME, &ts); |
1983 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2000 | return EV_TS_GET (ts); |
1984 | } |
2001 | } |
1985 | #endif |
2002 | #endif |
1986 | |
2003 | |
1987 | struct timeval tv; |
2004 | struct timeval tv; |
1988 | gettimeofday (&tv, 0); |
2005 | gettimeofday (&tv, 0); |
1989 | return tv.tv_sec + tv.tv_usec * 1e-6; |
2006 | return EV_TV_GET (tv); |
1990 | } |
2007 | } |
1991 | #endif |
2008 | #endif |
1992 | |
2009 | |
1993 | inline_size ev_tstamp |
2010 | inline_size ev_tstamp |
1994 | get_clock (void) |
2011 | get_clock (void) |
… | |
… | |
1996 | #if EV_USE_MONOTONIC |
2013 | #if EV_USE_MONOTONIC |
1997 | if (ecb_expect_true (have_monotonic)) |
2014 | if (ecb_expect_true (have_monotonic)) |
1998 | { |
2015 | { |
1999 | struct timespec ts; |
2016 | struct timespec ts; |
2000 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2017 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2001 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2018 | return EV_TS_GET (ts); |
2002 | } |
2019 | } |
2003 | #endif |
2020 | #endif |
2004 | |
2021 | |
2005 | return ev_time (); |
2022 | return ev_time (); |
2006 | } |
2023 | } |
… | |
… | |
2914 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2931 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2915 | |
2932 | |
2916 | /* 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 */ |
2917 | 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 */ |
2918 | flags &= ~EVBACKEND_EPOLL; |
2935 | flags &= ~EVBACKEND_EPOLL; |
|
|
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 | */ |
2919 | |
2943 | |
2920 | return flags; |
2944 | return flags; |
2921 | } |
2945 | } |
2922 | |
2946 | |
2923 | unsigned int |
2947 | unsigned int |