ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.492 by root, Sat Jun 22 16:25:53 2019 UTC vs.
Revision 1.496 by root, Mon Jun 24 22:27:29 2019 UTC

398/* AIX has a completely broken poll.h header */ 398/* AIX has a completely broken poll.h header */
399# undef EV_USE_POLL 399# undef EV_USE_POLL
400# define EV_USE_POLL 0 400# define EV_USE_POLL 0
401#endif 401#endif
402 402
403#if EV_USE_LINUXAIO
404# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
405#endif
406
407/* 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, */
408/* which makes programs even slower. might work on other unices, too. */ 404/* which makes programs even slower. might work on other unices, too. */
409#if EV_USE_CLOCK_SYSCALL 405#if EV_USE_CLOCK_SYSCALL
410# include <sys/syscall.h> 406# include <sys/syscall.h>
411# ifdef SYS_clock_gettime 407# ifdef SYS_clock_gettime
442# endif 438# endif
443#endif 439#endif
444 440
445#if EV_USE_LINUXAIO 441#if EV_USE_LINUXAIO
446# include <sys/syscall.h> 442# include <sys/syscall.h>
447# if !SYS_io_getevents 443# if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */
448# undef EV_USE_LINUXAIO 444# undef EV_USE_LINUXAIO
449# define EV_USE_LINUXAIO 0 445# define EV_USE_LINUXAIO 0
450# endif 446# endif
451#endif 447#endif
452 448
563 559
564#ifndef ECB_H 560#ifndef ECB_H
565#define ECB_H 561#define ECB_H
566 562
567/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
568#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
569 565
570#ifdef _WIN32 566#ifdef _WIN32
571 typedef signed char int8_t; 567 typedef signed char int8_t;
572 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
573 typedef signed short int16_t; 569 typedef signed short int16_t;
687 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
688#endif 684#endif
689 685
690#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
691 #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")
692 #if __i386 || __i386__ 689 #if __i386 || __i386__
693 #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")
694 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
695 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
696 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
746 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
747 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
748 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
749 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
750 #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)
751 749
752 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
753 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
754 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
755 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
756 #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)
757 756
758 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
759 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
760 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
761 /* 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... */
771 #elif defined _WIN32 770 #elif defined _WIN32
772 #include <WinNT.h> 771 #include <WinNT.h>
773 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
774 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
775 #include <mbarrier.h> 774 #include <mbarrier.h>
776 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
777 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
778 #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 ()
779 #elif __xlC__ 779 #elif __xlC__
780 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
781 #endif 781 #endif
782#endif 782#endif
783 783
784#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
786 /* 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, */
787 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
788 #include <stdatomic.h> 788 #include <stdatomic.h>
789 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
790 /* any fence other than seq_cst, which isn't very efficient for us. */
791 /* Why that is, we don't know - either the C11 memory model is quite useless */
792 /* for most usages, or gcc and clang have a bug */
793 /* I *currently* lean towards the latter, and inefficiently implement */
794 /* all three of ecb's fences as a seq_cst fence */
795 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
796 /* for all __atomic_thread_fence's except seq_cst */
797 #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)
798 #endif 792 #endif
799#endif 793#endif
800 794
801#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
802 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
820 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
821#endif 815#endif
822 816
823#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
824 #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 */
825#endif 823#endif
826 824
827/*****************************************************************************/ 825/*****************************************************************************/
828 826
829#if ECB_CPP 827#if ECB_CPP
1607# include "ev_win32.c" 1605# include "ev_win32.c"
1608#endif 1606#endif
1609 1607
1610/*****************************************************************************/ 1608/*****************************************************************************/
1611 1609
1610#if EV_USE_LINUXAIO
1611# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1612#endif
1613
1612/* define a suitable floor function (only used by periodics atm) */ 1614/* define a suitable floor function (only used by periodics atm) */
1613 1615
1614#if EV_USE_FLOOR 1616#if EV_USE_FLOOR
1615# include <math.h> 1617# include <math.h>
1616# define ev_floor(v) floor (v) 1618# define ev_floor(v) floor (v)
1989{ 1991{
1990 *cur = array_nextsize (elem, *cur, cnt); 1992 *cur = array_nextsize (elem, *cur, cnt);
1991 return ev_realloc (base, elem * *cur); 1993 return ev_realloc (base, elem * *cur);
1992} 1994}
1993 1995
1994#define array_needsize_noinit(base,count) 1996#define array_needsize_noinit(base,offset,count)
1995 1997
1996#define array_needsize_zerofill(base,count) \ 1998#define array_needsize_zerofill(base,offset,count) \
1997 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1999 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1998 2000
1999#define array_needsize(type,base,cur,cnt,init) \ 2001#define array_needsize(type,base,cur,cnt,init) \
2000 if (expect_false ((cnt) > (cur))) \ 2002 if (expect_false ((cnt) > (cur))) \
2001 { \ 2003 { \
2002 ecb_unused int ocur_ = (cur); \ 2004 ecb_unused int ocur_ = (cur); \
2003 (base) = (type *)array_realloc \ 2005 (base) = (type *)array_realloc \
2004 (sizeof (type), (base), &(cur), (cnt)); \ 2006 (sizeof (type), (base), &(cur), (cnt)); \
2005 init ((base) + (ocur_), (cur) - ocur_); \ 2007 init ((base), ocur_, ((cur) - ocur_)); \
2006 } 2008 }
2007 2009
2008#if 0 2010#if 0
2009#define array_slim(type,stem) \ 2011#define array_slim(type,stem) \
2010 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2012 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
2733# include "ev_port.c" 2735# include "ev_port.c"
2734#endif 2736#endif
2735#if EV_USE_KQUEUE 2737#if EV_USE_KQUEUE
2736# include "ev_kqueue.c" 2738# include "ev_kqueue.c"
2737#endif 2739#endif
2740#if EV_USE_EPOLL
2741# include "ev_epoll.c"
2742#endif
2738#if EV_USE_LINUXAIO 2743#if EV_USE_LINUXAIO
2739# include "ev_linuxaio.c" 2744# include "ev_linuxaio.c"
2740#endif
2741#if EV_USE_EPOLL
2742# include "ev_epoll.c"
2743#endif 2745#endif
2744#if EV_USE_POLL 2746#if EV_USE_POLL
2745# include "ev_poll.c" 2747# include "ev_poll.c"
2746#endif 2748#endif
2747#if EV_USE_SELECT 2749#if EV_USE_SELECT
2807#ifdef __FreeBSD__ 2809#ifdef __FreeBSD__
2808 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) */
2809#endif 2811#endif
2810 2812
2811 /* TODO: linuxaio is very experimental */ 2813 /* TODO: linuxaio is very experimental */
2814#if !EV_RECOMMEND_LINUXAIO
2812 flags &= ~EVBACKEND_LINUXAIO; 2815 flags &= ~EVBACKEND_LINUXAIO;
2816#endif
2813 2817
2814 return flags; 2818 return flags;
2815} 2819}
2816 2820
2817ecb_cold 2821ecb_cold

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines