… | |
… | |
115 | # else |
115 | # else |
116 | # undef EV_USE_EPOLL |
116 | # undef EV_USE_EPOLL |
117 | # define EV_USE_EPOLL 0 |
117 | # define EV_USE_EPOLL 0 |
118 | # endif |
118 | # endif |
119 | |
119 | |
|
|
120 | # if HAVE_LINUX_AIO_ABI_H |
|
|
121 | # ifndef EV_USE_LINUXAIO |
|
|
122 | # define EV_USE_LINUXAIO EV_FEATURE_BACKENDS |
|
|
123 | # endif |
|
|
124 | # else |
|
|
125 | # undef EV_USE_LINUXAIO |
|
|
126 | # define EV_USE_LINUXAIO 0 |
|
|
127 | # endif |
|
|
128 | |
120 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
129 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
121 | # ifndef EV_USE_KQUEUE |
130 | # ifndef EV_USE_KQUEUE |
122 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
131 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
123 | # endif |
132 | # endif |
124 | # else |
133 | # else |
… | |
… | |
316 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
317 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
318 | #endif |
327 | #endif |
319 | |
328 | |
320 | #ifndef EV_USE_LINUXAIO |
329 | #ifndef EV_USE_LINUXAIO |
|
|
330 | # if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ |
|
|
331 | # define EV_USE_LINUXAIO 1 |
|
|
332 | # else |
321 | # define EV_USE_LINUXAIO 0 |
333 | # define EV_USE_LINUXAIO 0 |
|
|
334 | # endif |
322 | #endif |
335 | #endif |
323 | |
336 | |
324 | #ifndef EV_USE_INOTIFY |
337 | #ifndef EV_USE_INOTIFY |
325 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
326 | # define EV_USE_INOTIFY EV_FEATURE_OS |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
… | |
… | |
383 | /* aix's poll.h seems to cause lots of trouble */ |
396 | /* aix's poll.h seems to cause lots of trouble */ |
384 | #ifdef _AIX |
397 | #ifdef _AIX |
385 | /* AIX has a completely broken poll.h header */ |
398 | /* AIX has a completely broken poll.h header */ |
386 | # undef EV_USE_POLL |
399 | # undef EV_USE_POLL |
387 | # define EV_USE_POLL 0 |
400 | # define EV_USE_POLL 0 |
388 | #endif |
|
|
389 | |
|
|
390 | #if EV_USE_LINUXAIO |
|
|
391 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
392 | #endif |
401 | #endif |
393 | |
402 | |
394 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
403 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
395 | /* which makes programs even slower. might work on other unices, too. */ |
404 | /* which makes programs even slower. might work on other unices, too. */ |
396 | #if EV_USE_CLOCK_SYSCALL |
405 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
424 | |
433 | |
425 | #if !EV_USE_NANOSLEEP |
434 | #if !EV_USE_NANOSLEEP |
426 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
435 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
427 | # if !defined _WIN32 && !defined __hpux |
436 | # if !defined _WIN32 && !defined __hpux |
428 | # include <sys/select.h> |
437 | # include <sys/select.h> |
|
|
438 | # endif |
|
|
439 | #endif |
|
|
440 | |
|
|
441 | #if EV_USE_LINUXAIO |
|
|
442 | # include <sys/syscall.h> |
|
|
443 | # if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */ |
|
|
444 | # undef EV_USE_LINUXAIO |
|
|
445 | # define EV_USE_LINUXAIO 0 |
429 | # endif |
446 | # endif |
430 | #endif |
447 | #endif |
431 | |
448 | |
432 | #if EV_USE_INOTIFY |
449 | #if EV_USE_INOTIFY |
433 | # include <sys/statfs.h> |
450 | # include <sys/statfs.h> |
… | |
… | |
542 | |
559 | |
543 | #ifndef ECB_H |
560 | #ifndef ECB_H |
544 | #define ECB_H |
561 | #define ECB_H |
545 | |
562 | |
546 | /* 16 bits major, 16 bits minor */ |
563 | /* 16 bits major, 16 bits minor */ |
547 | #define ECB_VERSION 0x00010005 |
564 | #define ECB_VERSION 0x00010006 |
548 | |
565 | |
549 | #ifdef _WIN32 |
566 | #ifdef _WIN32 |
550 | typedef signed char int8_t; |
567 | typedef signed char int8_t; |
551 | typedef unsigned char uint8_t; |
568 | typedef unsigned char uint8_t; |
552 | typedef signed short int16_t; |
569 | typedef signed short int16_t; |
… | |
… | |
666 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
683 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
667 | #endif |
684 | #endif |
668 | |
685 | |
669 | #ifndef ECB_MEMORY_FENCE |
686 | #ifndef ECB_MEMORY_FENCE |
670 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
687 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
688 | #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory") |
671 | #if __i386 || __i386__ |
689 | #if __i386 || __i386__ |
672 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
690 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
673 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
691 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
674 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
692 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
675 | #elif ECB_GCC_AMD64 |
693 | #elif ECB_GCC_AMD64 |
… | |
… | |
725 | #if ECB_GCC_VERSION(4,7) |
743 | #if ECB_GCC_VERSION(4,7) |
726 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
744 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
727 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
745 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
728 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
746 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
729 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
747 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
748 | #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED) |
730 | |
749 | |
731 | #elif ECB_CLANG_EXTENSION(c_atomic) |
750 | #elif ECB_CLANG_EXTENSION(c_atomic) |
732 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
751 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
733 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
752 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
734 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
753 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
735 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
754 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
755 | #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED) |
736 | |
756 | |
737 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
757 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
738 | #define ECB_MEMORY_FENCE __sync_synchronize () |
758 | #define ECB_MEMORY_FENCE __sync_synchronize () |
739 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
759 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
740 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
760 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
… | |
… | |
750 | #elif defined _WIN32 |
770 | #elif defined _WIN32 |
751 | #include <WinNT.h> |
771 | #include <WinNT.h> |
752 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
772 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
753 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
773 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
754 | #include <mbarrier.h> |
774 | #include <mbarrier.h> |
755 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
775 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
756 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
776 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier () |
757 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
777 | #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier () |
|
|
778 | #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier () |
758 | #elif __xlC__ |
779 | #elif __xlC__ |
759 | #define ECB_MEMORY_FENCE __sync () |
780 | #define ECB_MEMORY_FENCE __sync () |
760 | #endif |
781 | #endif |
761 | #endif |
782 | #endif |
762 | |
783 | |
763 | #ifndef ECB_MEMORY_FENCE |
784 | #ifndef ECB_MEMORY_FENCE |
764 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
785 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
765 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
786 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
766 | /* not just C11 atomics and atomic accesses */ |
787 | /* not just C11 atomics and atomic accesses */ |
767 | #include <stdatomic.h> |
788 | #include <stdatomic.h> |
768 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
769 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
770 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
771 | /* for most usages, or gcc and clang have a bug */ |
|
|
772 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
773 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
774 | /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */ |
|
|
775 | /* for all __atomic_thread_fence's except seq_cst */ |
|
|
776 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
789 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
|
|
790 | #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire) |
|
|
791 | #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release) |
777 | #endif |
792 | #endif |
778 | #endif |
793 | #endif |
779 | |
794 | |
780 | #ifndef ECB_MEMORY_FENCE |
795 | #ifndef ECB_MEMORY_FENCE |
781 | #if !ECB_AVOID_PTHREADS |
796 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
799 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
814 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
800 | #endif |
815 | #endif |
801 | |
816 | |
802 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
817 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
803 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
818 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
819 | #endif |
|
|
820 | |
|
|
821 | #if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE |
|
|
822 | #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */ |
804 | #endif |
823 | #endif |
805 | |
824 | |
806 | /*****************************************************************************/ |
825 | /*****************************************************************************/ |
807 | |
826 | |
808 | #if ECB_CPP |
827 | #if ECB_CPP |
… | |
… | |
1586 | # include "ev_win32.c" |
1605 | # include "ev_win32.c" |
1587 | #endif |
1606 | #endif |
1588 | |
1607 | |
1589 | /*****************************************************************************/ |
1608 | /*****************************************************************************/ |
1590 | |
1609 | |
|
|
1610 | #if EV_USE_LINUXAIO |
|
|
1611 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
1612 | #endif |
|
|
1613 | |
1591 | /* define a suitable floor function (only used by periodics atm) */ |
1614 | /* define a suitable floor function (only used by periodics atm) */ |
1592 | |
1615 | |
1593 | #if EV_USE_FLOOR |
1616 | #if EV_USE_FLOOR |
1594 | # include <math.h> |
1617 | # include <math.h> |
1595 | # define ev_floor(v) floor (v) |
1618 | # define ev_floor(v) floor (v) |
… | |
… | |
1968 | { |
1991 | { |
1969 | *cur = array_nextsize (elem, *cur, cnt); |
1992 | *cur = array_nextsize (elem, *cur, cnt); |
1970 | return ev_realloc (base, elem * *cur); |
1993 | return ev_realloc (base, elem * *cur); |
1971 | } |
1994 | } |
1972 | |
1995 | |
1973 | #define array_needsize_noinit(base,count) |
1996 | #define array_needsize_noinit(base,offset,count) |
1974 | |
1997 | |
1975 | #define array_needsize_zerofill(base,count) \ |
1998 | #define array_needsize_zerofill(base,offset,count) \ |
1976 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1999 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
1977 | |
2000 | |
1978 | #define array_needsize(type,base,cur,cnt,init) \ |
2001 | #define array_needsize(type,base,cur,cnt,init) \ |
1979 | if (expect_false ((cnt) > (cur))) \ |
2002 | if (expect_false ((cnt) > (cur))) \ |
1980 | { \ |
2003 | { \ |
1981 | ecb_unused int ocur_ = (cur); \ |
2004 | ecb_unused int ocur_ = (cur); \ |
1982 | (base) = (type *)array_realloc \ |
2005 | (base) = (type *)array_realloc \ |
1983 | (sizeof (type), (base), &(cur), (cnt)); \ |
2006 | (sizeof (type), (base), &(cur), (cnt)); \ |
1984 | init ((base) + (ocur_), (cur) - ocur_); \ |
2007 | init ((base), ocur_, ((cur) - ocur_)); \ |
1985 | } |
2008 | } |
1986 | |
2009 | |
1987 | #if 0 |
2010 | #if 0 |
1988 | #define array_slim(type,stem) \ |
2011 | #define array_slim(type,stem) \ |
1989 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
2012 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
… | |
… | |
2124 | ev_io *w; |
2147 | ev_io *w; |
2125 | |
2148 | |
2126 | unsigned char o_events = anfd->events; |
2149 | unsigned char o_events = anfd->events; |
2127 | unsigned char o_reify = anfd->reify; |
2150 | unsigned char o_reify = anfd->reify; |
2128 | |
2151 | |
2129 | anfd->reify = 0; |
2152 | anfd->reify = 0; |
2130 | |
2153 | |
2131 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2154 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2132 | { |
2155 | { |
2133 | anfd->events = 0; |
2156 | anfd->events = 0; |
2134 | |
2157 | |
… | |
… | |
2712 | # include "ev_port.c" |
2735 | # include "ev_port.c" |
2713 | #endif |
2736 | #endif |
2714 | #if EV_USE_KQUEUE |
2737 | #if EV_USE_KQUEUE |
2715 | # include "ev_kqueue.c" |
2738 | # include "ev_kqueue.c" |
2716 | #endif |
2739 | #endif |
|
|
2740 | #if EV_USE_EPOLL |
|
|
2741 | # include "ev_epoll.c" |
|
|
2742 | #endif |
2717 | #if EV_USE_LINUXAIO |
2743 | #if EV_USE_LINUXAIO |
2718 | # include "ev_linuxaio.c" |
2744 | # include "ev_linuxaio.c" |
2719 | #endif |
|
|
2720 | #if EV_USE_EPOLL |
|
|
2721 | # include "ev_epoll.c" |
|
|
2722 | #endif |
2745 | #endif |
2723 | #if EV_USE_POLL |
2746 | #if EV_USE_POLL |
2724 | # include "ev_poll.c" |
2747 | # include "ev_poll.c" |
2725 | #endif |
2748 | #endif |
2726 | #if EV_USE_SELECT |
2749 | #if EV_USE_SELECT |
… | |
… | |
2783 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
2806 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
2784 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
2807 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
2785 | #endif |
2808 | #endif |
2786 | #ifdef __FreeBSD__ |
2809 | #ifdef __FreeBSD__ |
2787 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2810 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
|
|
2811 | #endif |
|
|
2812 | |
|
|
2813 | /* TODO: linuxaio is very experimental */ |
|
|
2814 | #if !EV_RECOMMEND_LINUXAIO |
|
|
2815 | flags &= ~EVBACKEND_LINUXAIO; |
2788 | #endif |
2816 | #endif |
2789 | |
2817 | |
2790 | return flags; |
2818 | return flags; |
2791 | } |
2819 | } |
2792 | |
2820 | |