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

Comparing libev/ev.c (file contents):
Revision 1.487 by root, Mon Oct 29 00:00:21 2018 UTC vs.
Revision 1.495 by root, Mon Jun 24 21:27:57 2019 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007-2018 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
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
315 324
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
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
333# define EV_USE_LINUXAIO 0
334# endif
335#endif
336
320#ifndef EV_USE_INOTIFY 337#ifndef EV_USE_INOTIFY
321# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 338# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
322# define EV_USE_INOTIFY EV_FEATURE_OS 339# define EV_USE_INOTIFY EV_FEATURE_OS
323# else 340# else
324# define EV_USE_INOTIFY 0 341# define EV_USE_INOTIFY 0
416 433
417#if !EV_USE_NANOSLEEP 434#if !EV_USE_NANOSLEEP
418/* 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 */
419# if !defined _WIN32 && !defined __hpux 436# if !defined _WIN32 && !defined __hpux
420# 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
421# endif 446# endif
422#endif 447#endif
423 448
424#if EV_USE_INOTIFY 449#if EV_USE_INOTIFY
425# include <sys/statfs.h> 450# include <sys/statfs.h>
609 #define ECB_CLANG_EXTENSION(x) 0 634 #define ECB_CLANG_EXTENSION(x) 0
610#endif 635#endif
611 636
612#define ECB_CPP (__cplusplus+0) 637#define ECB_CPP (__cplusplus+0)
613#define ECB_CPP11 (__cplusplus >= 201103L) 638#define ECB_CPP11 (__cplusplus >= 201103L)
639#define ECB_CPP14 (__cplusplus >= 201402L)
640#define ECB_CPP17 (__cplusplus >= 201703L)
614 641
615#if ECB_CPP 642#if ECB_CPP
616 #define ECB_C 0 643 #define ECB_C 0
617 #define ECB_STDC_VERSION 0 644 #define ECB_STDC_VERSION 0
618#else 645#else
620 #define ECB_STDC_VERSION __STDC_VERSION__ 647 #define ECB_STDC_VERSION __STDC_VERSION__
621#endif 648#endif
622 649
623#define ECB_C99 (ECB_STDC_VERSION >= 199901L) 650#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
624#define ECB_C11 (ECB_STDC_VERSION >= 201112L) 651#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
652#define ECB_C17 (ECB_STDC_VERSION >= 201710L)
625 653
626#if ECB_CPP 654#if ECB_CPP
627 #define ECB_EXTERN_C extern "C" 655 #define ECB_EXTERN_C extern "C"
628 #define ECB_EXTERN_C_BEG ECB_EXTERN_C { 656 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
629 #define ECB_EXTERN_C_END } 657 #define ECB_EXTERN_C_END }
658#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
659 #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
660 #if __i386 || __i386__ 688 #if __i386 || __i386__
661 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 689 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
662 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 690 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
663 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 691 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
664 #elif ECB_GCC_AMD64 692 #elif ECB_GCC_AMD64
665 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 693 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
666 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 694 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
667 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 695 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
668 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 696 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
669 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 697 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
670 #elif defined __ARM_ARCH_2__ \ 698 #elif defined __ARM_ARCH_2__ \
671 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ 699 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
672 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ 700 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
1540# define ABSPRI(w) (((W)w), 0) 1568# define ABSPRI(w) (((W)w), 0)
1541#else 1569#else
1542# define ABSPRI(w) (((W)w)->priority - EV_MINPRI) 1570# define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
1543#endif 1571#endif
1544 1572
1545#define EMPTY /* required for microsofts broken pseudo-c compiler */ 1573#define EMPTY /* required for microsofts broken pseudo-c compiler */
1546#define EMPTY2(a,b) /* used to suppress some warnings */
1547 1574
1548typedef ev_watcher *W; 1575typedef ev_watcher *W;
1549typedef ev_watcher_list *WL; 1576typedef ev_watcher_list *WL;
1550typedef ev_watcher_time *WT; 1577typedef ev_watcher_time *WT;
1551 1578
1575#ifdef _WIN32 1602#ifdef _WIN32
1576# include "ev_win32.c" 1603# include "ev_win32.c"
1577#endif 1604#endif
1578 1605
1579/*****************************************************************************/ 1606/*****************************************************************************/
1607
1608#if EV_USE_LINUXAIO
1609# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1610#endif
1580 1611
1581/* define a suitable floor function (only used by periodics atm) */ 1612/* define a suitable floor function (only used by periodics atm) */
1582 1613
1583#if EV_USE_FLOOR 1614#if EV_USE_FLOOR
1584# include <math.h> 1615# include <math.h>
1767typedef struct 1798typedef struct
1768{ 1799{
1769 WL head; 1800 WL head;
1770 unsigned char events; /* the events watched for */ 1801 unsigned char events; /* the events watched for */
1771 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ 1802 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
1772 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 1803 unsigned char emask; /* some backends store the actual kernel mask in here */
1773 unsigned char unused; 1804 unsigned char unused;
1774#if EV_USE_EPOLL 1805#if EV_USE_EPOLL
1775 unsigned int egen; /* generation counter to counter epoll bugs */ 1806 unsigned int egen; /* generation counter to counter epoll bugs */
1776#endif 1807#endif
1777#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 1808#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
1958{ 1989{
1959 *cur = array_nextsize (elem, *cur, cnt); 1990 *cur = array_nextsize (elem, *cur, cnt);
1960 return ev_realloc (base, elem * *cur); 1991 return ev_realloc (base, elem * *cur);
1961} 1992}
1962 1993
1994#define array_needsize_noinit(base,offset,count)
1995
1963#define array_init_zero(base,count) \ 1996#define array_needsize_zerofill(base,offset,count) \
1964 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1997 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1965 1998
1966#define array_needsize(type,base,cur,cnt,init) \ 1999#define array_needsize(type,base,cur,cnt,init) \
1967 if (expect_false ((cnt) > (cur))) \ 2000 if (expect_false ((cnt) > (cur))) \
1968 { \ 2001 { \
1969 ecb_unused int ocur_ = (cur); \ 2002 ecb_unused int ocur_ = (cur); \
1970 (base) = (type *)array_realloc \ 2003 (base) = (type *)array_realloc \
1971 (sizeof (type), (base), &(cur), (cnt)); \ 2004 (sizeof (type), (base), &(cur), (cnt)); \
1972 init ((base) + (ocur_), (cur) - ocur_); \ 2005 init ((base), ocur_, ((cur) - ocur_)); \
1973 } 2006 }
1974 2007
1975#if 0 2008#if 0
1976#define array_slim(type,stem) \ 2009#define array_slim(type,stem) \
1977 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2010 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
2004 if (expect_false (w_->pending)) 2037 if (expect_false (w_->pending))
2005 pendings [pri][w_->pending - 1].events |= revents; 2038 pendings [pri][w_->pending - 1].events |= revents;
2006 else 2039 else
2007 { 2040 {
2008 w_->pending = ++pendingcnt [pri]; 2041 w_->pending = ++pendingcnt [pri];
2009 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 2042 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
2010 pendings [pri][w_->pending - 1].w = w_; 2043 pendings [pri][w_->pending - 1].w = w_;
2011 pendings [pri][w_->pending - 1].events = revents; 2044 pendings [pri][w_->pending - 1].events = revents;
2012 } 2045 }
2013 2046
2014 pendingpri = NUMPRI - 1; 2047 pendingpri = NUMPRI - 1;
2015} 2048}
2016 2049
2017inline_speed void 2050inline_speed void
2018feed_reverse (EV_P_ W w) 2051feed_reverse (EV_P_ W w)
2019{ 2052{
2020 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); 2053 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit);
2021 rfeeds [rfeedcnt++] = w; 2054 rfeeds [rfeedcnt++] = w;
2022} 2055}
2023 2056
2024inline_size void 2057inline_size void
2025feed_reverse_done (EV_P_ int revents) 2058feed_reverse_done (EV_P_ int revents)
2143 anfds [fd].reify |= flags; 2176 anfds [fd].reify |= flags;
2144 2177
2145 if (expect_true (!reify)) 2178 if (expect_true (!reify))
2146 { 2179 {
2147 ++fdchangecnt; 2180 ++fdchangecnt;
2148 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 2181 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2149 fdchanges [fdchangecnt - 1] = fd; 2182 fdchanges [fdchangecnt - 1] = fd;
2150 } 2183 }
2151} 2184}
2152 2185
2153/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 2186/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
2703# include "ev_kqueue.c" 2736# include "ev_kqueue.c"
2704#endif 2737#endif
2705#if EV_USE_EPOLL 2738#if EV_USE_EPOLL
2706# include "ev_epoll.c" 2739# include "ev_epoll.c"
2707#endif 2740#endif
2741#if EV_USE_LINUXAIO
2742# include "ev_linuxaio.c"
2743#endif
2708#if EV_USE_POLL 2744#if EV_USE_POLL
2709# include "ev_poll.c" 2745# include "ev_poll.c"
2710#endif 2746#endif
2711#if EV_USE_SELECT 2747#if EV_USE_SELECT
2712# include "ev_select.c" 2748# include "ev_select.c"
2740unsigned int 2776unsigned int
2741ev_supported_backends (void) EV_NOEXCEPT 2777ev_supported_backends (void) EV_NOEXCEPT
2742{ 2778{
2743 unsigned int flags = 0; 2779 unsigned int flags = 0;
2744 2780
2745 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2781 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2746 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2782 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2747 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 2783 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2784 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO;
2748 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 2785 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2749 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 2786 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2750 2787
2751 return flags; 2788 return flags;
2752} 2789}
2753 2790
2754ecb_cold 2791ecb_cold
2767 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ 2804 flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */
2768 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ 2805 flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */
2769#endif 2806#endif
2770#ifdef __FreeBSD__ 2807#ifdef __FreeBSD__
2771 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ 2808 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
2809#endif
2810
2811 /* TODO: linuxaio is very experimental */
2812#if !EV_RECOMMEND_LINUXAIO
2813 flags &= ~EVBACKEND_LINUXAIO;
2772#endif 2814#endif
2773 2815
2774 return flags; 2816 return flags;
2775} 2817}
2776 2818
2913 2955
2914 if (!(flags & EVBACKEND_MASK)) 2956 if (!(flags & EVBACKEND_MASK))
2915 flags |= ev_recommended_backends (); 2957 flags |= ev_recommended_backends ();
2916 2958
2917#if EV_USE_IOCP 2959#if EV_USE_IOCP
2918 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 2960 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
2919#endif 2961#endif
2920#if EV_USE_PORT 2962#if EV_USE_PORT
2921 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 2963 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
2922#endif 2964#endif
2923#if EV_USE_KQUEUE 2965#if EV_USE_KQUEUE
2924 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 2966 if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags);
2967#endif
2968#if EV_USE_LINUXAIO
2969 if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags);
2925#endif 2970#endif
2926#if EV_USE_EPOLL 2971#if EV_USE_EPOLL
2927 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); 2972 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
2928#endif 2973#endif
2929#if EV_USE_POLL 2974#if EV_USE_POLL
2930 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); 2975 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
2931#endif 2976#endif
2932#if EV_USE_SELECT 2977#if EV_USE_SELECT
2933 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 2978 if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags);
2934#endif 2979#endif
2935 2980
2936 ev_prepare_init (&pending_w, pendingcb); 2981 ev_prepare_init (&pending_w, pendingcb);
2937 2982
2938#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2983#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2993 3038
2994 if (backend_fd >= 0) 3039 if (backend_fd >= 0)
2995 close (backend_fd); 3040 close (backend_fd);
2996 3041
2997#if EV_USE_IOCP 3042#if EV_USE_IOCP
2998 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); 3043 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
2999#endif 3044#endif
3000#if EV_USE_PORT 3045#if EV_USE_PORT
3001 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 3046 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
3002#endif 3047#endif
3003#if EV_USE_KQUEUE 3048#if EV_USE_KQUEUE
3004 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 3049 if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A);
3050#endif
3051#if EV_USE_LINUXAIO
3052 if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A);
3005#endif 3053#endif
3006#if EV_USE_EPOLL 3054#if EV_USE_EPOLL
3007 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 3055 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
3008#endif 3056#endif
3009#if EV_USE_POLL 3057#if EV_USE_POLL
3010 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); 3058 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
3011#endif 3059#endif
3012#if EV_USE_SELECT 3060#if EV_USE_SELECT
3013 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 3061 if (backend == EVBACKEND_SELECT ) select_destroy (EV_A);
3014#endif 3062#endif
3015 3063
3016 for (i = NUMPRI; i--; ) 3064 for (i = NUMPRI; i--; )
3017 { 3065 {
3018 array_free (pending, [i]); 3066 array_free (pending, [i]);
3060 3108
3061inline_size void 3109inline_size void
3062loop_fork (EV_P) 3110loop_fork (EV_P)
3063{ 3111{
3064#if EV_USE_PORT 3112#if EV_USE_PORT
3065 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 3113 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
3066#endif 3114#endif
3067#if EV_USE_KQUEUE 3115#if EV_USE_KQUEUE
3068 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 3116 if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A);
3117#endif
3118#if EV_USE_LINUXAIO
3119 if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A);
3069#endif 3120#endif
3070#if EV_USE_EPOLL 3121#if EV_USE_EPOLL
3071 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 3122 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
3072#endif 3123#endif
3073#if EV_USE_INOTIFY 3124#if EV_USE_INOTIFY
3074 infy_fork (EV_A); 3125 infy_fork (EV_A);
3075#endif 3126#endif
3076 3127
3873 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3924 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3874 3925
3875 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3876 3927
3877 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3878 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3879 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3880 3931
3881 /* common bug, apparently */ 3932 /* common bug, apparently */
3882 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3933 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3883 3934
3920 3971
3921 EV_FREQUENT_CHECK; 3972 EV_FREQUENT_CHECK;
3922 3973
3923 ++timercnt; 3974 ++timercnt;
3924 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3975 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3925 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3976 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3926 ANHE_w (timers [ev_active (w)]) = (WT)w; 3977 ANHE_w (timers [ev_active (w)]) = (WT)w;
3927 ANHE_at_cache (timers [ev_active (w)]); 3978 ANHE_at_cache (timers [ev_active (w)]);
3928 upheap (timers, ev_active (w)); 3979 upheap (timers, ev_active (w));
3929 3980
3930 EV_FREQUENT_CHECK; 3981 EV_FREQUENT_CHECK;
4017 4068
4018 EV_FREQUENT_CHECK; 4069 EV_FREQUENT_CHECK;
4019 4070
4020 ++periodiccnt; 4071 ++periodiccnt;
4021 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4072 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
4022 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4073 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
4023 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4074 ANHE_w (periodics [ev_active (w)]) = (WT)w;
4024 ANHE_at_cache (periodics [ev_active (w)]); 4075 ANHE_at_cache (periodics [ev_active (w)]);
4025 upheap (periodics, ev_active (w)); 4076 upheap (periodics, ev_active (w));
4026 4077
4027 EV_FREQUENT_CHECK; 4078 EV_FREQUENT_CHECK;
4612 int active = ++idlecnt [ABSPRI (w)]; 4663 int active = ++idlecnt [ABSPRI (w)];
4613 4664
4614 ++idleall; 4665 ++idleall;
4615 ev_start (EV_A_ (W)w, active); 4666 ev_start (EV_A_ (W)w, active);
4616 4667
4617 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4668 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4618 idles [ABSPRI (w)][active - 1] = w; 4669 idles [ABSPRI (w)][active - 1] = w;
4619 } 4670 }
4620 4671
4621 EV_FREQUENT_CHECK; 4672 EV_FREQUENT_CHECK;
4622} 4673}
4652 return; 4703 return;
4653 4704
4654 EV_FREQUENT_CHECK; 4705 EV_FREQUENT_CHECK;
4655 4706
4656 ev_start (EV_A_ (W)w, ++preparecnt); 4707 ev_start (EV_A_ (W)w, ++preparecnt);
4657 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4708 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4658 prepares [preparecnt - 1] = w; 4709 prepares [preparecnt - 1] = w;
4659 4710
4660 EV_FREQUENT_CHECK; 4711 EV_FREQUENT_CHECK;
4661} 4712}
4662 4713
4690 return; 4741 return;
4691 4742
4692 EV_FREQUENT_CHECK; 4743 EV_FREQUENT_CHECK;
4693 4744
4694 ev_start (EV_A_ (W)w, ++checkcnt); 4745 ev_start (EV_A_ (W)w, ++checkcnt);
4695 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4746 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4696 checks [checkcnt - 1] = w; 4747 checks [checkcnt - 1] = w;
4697 4748
4698 EV_FREQUENT_CHECK; 4749 EV_FREQUENT_CHECK;
4699} 4750}
4700 4751
4838 return; 4889 return;
4839 4890
4840 EV_FREQUENT_CHECK; 4891 EV_FREQUENT_CHECK;
4841 4892
4842 ev_start (EV_A_ (W)w, ++forkcnt); 4893 ev_start (EV_A_ (W)w, ++forkcnt);
4843 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4894 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4844 forks [forkcnt - 1] = w; 4895 forks [forkcnt - 1] = w;
4845 4896
4846 EV_FREQUENT_CHECK; 4897 EV_FREQUENT_CHECK;
4847} 4898}
4848 4899
4876 return; 4927 return;
4877 4928
4878 EV_FREQUENT_CHECK; 4929 EV_FREQUENT_CHECK;
4879 4930
4880 ev_start (EV_A_ (W)w, ++cleanupcnt); 4931 ev_start (EV_A_ (W)w, ++cleanupcnt);
4881 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4932 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4882 cleanups [cleanupcnt - 1] = w; 4933 cleanups [cleanupcnt - 1] = w;
4883 4934
4884 /* cleanup watchers should never keep a refcount on the loop */ 4935 /* cleanup watchers should never keep a refcount on the loop */
4885 ev_unref (EV_A); 4936 ev_unref (EV_A);
4886 EV_FREQUENT_CHECK; 4937 EV_FREQUENT_CHECK;
4921 evpipe_init (EV_A); 4972 evpipe_init (EV_A);
4922 4973
4923 EV_FREQUENT_CHECK; 4974 EV_FREQUENT_CHECK;
4924 4975
4925 ev_start (EV_A_ (W)w, ++asynccnt); 4976 ev_start (EV_A_ (W)w, ++asynccnt);
4926 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4977 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4927 asyncs [asynccnt - 1] = w; 4978 asyncs [asynccnt - 1] = w;
4928 4979
4929 EV_FREQUENT_CHECK; 4980 EV_FREQUENT_CHECK;
4930} 4981}
4931 4982
4999 5050
5000void 5051void
5001ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT 5052ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
5002{ 5053{
5003 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5054 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
5004
5005 if (expect_false (!once))
5006 {
5007 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
5008 return;
5009 }
5010 5055
5011 once->cb = cb; 5056 once->cb = cb;
5012 once->arg = arg; 5057 once->arg = arg;
5013 5058
5014 ev_init (&once->io, once_cb_io); 5059 ev_init (&once->io, once_cb_io);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines