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

Comparing libev/ev.c (file contents):
Revision 1.482 by root, Sat Jul 28 04:15:15 2018 UTC vs.
Revision 1.498 by root, Wed Jun 26 00:01:46 2019 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 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
162# define EV_USE_EVENTFD 0 171# define EV_USE_EVENTFD 0
163# endif 172# endif
164 173
165#endif 174#endif
166 175
176/* OS X, in its infinite idiocy, actually HARDCODES
177 * a limit of 1024 into their select. Where people have brains,
178 * OS X engineers apparently have a vacuum. Or maybe they were
179 * ordered to have a vacuum, or they do anything for money.
180 * This might help. Or not.
181 * Note that this must be defined early, as other include files
182 * will rely on this define as well.
183 */
184#define _DARWIN_UNLIMITED_SELECT 1
185
167#include <stdlib.h> 186#include <stdlib.h>
168#include <string.h> 187#include <string.h>
169#include <fcntl.h> 188#include <fcntl.h>
170#include <stddef.h> 189#include <stddef.h>
171 190
208# ifndef EV_SELECT_IS_WINSOCKET 227# ifndef EV_SELECT_IS_WINSOCKET
209# define EV_SELECT_IS_WINSOCKET 1 228# define EV_SELECT_IS_WINSOCKET 1
210# endif 229# endif
211# undef EV_AVOID_STDIO 230# undef EV_AVOID_STDIO
212#endif 231#endif
213
214/* OS X, in its infinite idiocy, actually HARDCODES
215 * a limit of 1024 into their select. Where people have brains,
216 * OS X engineers apparently have a vacuum. Or maybe they were
217 * ordered to have a vacuum, or they do anything for money.
218 * This might help. Or not.
219 */
220#define _DARWIN_UNLIMITED_SELECT 1
221 232
222/* this block tries to deduce configuration from header-defined symbols and defaults */ 233/* this block tries to deduce configuration from header-defined symbols and defaults */
223 234
224/* try to deduce the maximum number of signals on this platform */ 235/* try to deduce the maximum number of signals on this platform */
225#if defined EV_NSIG 236#if defined EV_NSIG
313 324
314#ifndef EV_USE_PORT 325#ifndef EV_USE_PORT
315# define EV_USE_PORT 0 326# define EV_USE_PORT 0
316#endif 327#endif
317 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
318#ifndef EV_USE_INOTIFY 337#ifndef EV_USE_INOTIFY
319# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 338# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
320# define EV_USE_INOTIFY EV_FEATURE_OS 339# define EV_USE_INOTIFY EV_FEATURE_OS
321# else 340# else
322# define EV_USE_INOTIFY 0 341# define EV_USE_INOTIFY 0
414 433
415#if !EV_USE_NANOSLEEP 434#if !EV_USE_NANOSLEEP
416/* 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 */
417# if !defined _WIN32 && !defined __hpux 436# if !defined _WIN32 && !defined __hpux
418# 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
419# endif 446# endif
420#endif 447#endif
421 448
422#if EV_USE_INOTIFY 449#if EV_USE_INOTIFY
423# include <sys/statfs.h> 450# include <sys/statfs.h>
532 559
533#ifndef ECB_H 560#ifndef ECB_H
534#define ECB_H 561#define ECB_H
535 562
536/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
537#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
538 565
539#ifdef _WIN32 566#ifdef _WIN32
540 typedef signed char int8_t; 567 typedef signed char int8_t;
541 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
542 typedef signed short int16_t; 569 typedef signed short int16_t;
607 #define ECB_CLANG_EXTENSION(x) 0 634 #define ECB_CLANG_EXTENSION(x) 0
608#endif 635#endif
609 636
610#define ECB_CPP (__cplusplus+0) 637#define ECB_CPP (__cplusplus+0)
611#define ECB_CPP11 (__cplusplus >= 201103L) 638#define ECB_CPP11 (__cplusplus >= 201103L)
639#define ECB_CPP14 (__cplusplus >= 201402L)
640#define ECB_CPP17 (__cplusplus >= 201703L)
612 641
613#if ECB_CPP 642#if ECB_CPP
614 #define ECB_C 0 643 #define ECB_C 0
615 #define ECB_STDC_VERSION 0 644 #define ECB_STDC_VERSION 0
616#else 645#else
618 #define ECB_STDC_VERSION __STDC_VERSION__ 647 #define ECB_STDC_VERSION __STDC_VERSION__
619#endif 648#endif
620 649
621#define ECB_C99 (ECB_STDC_VERSION >= 199901L) 650#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
622#define ECB_C11 (ECB_STDC_VERSION >= 201112L) 651#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
652#define ECB_C17 (ECB_STDC_VERSION >= 201710L)
623 653
624#if ECB_CPP 654#if ECB_CPP
625 #define ECB_EXTERN_C extern "C" 655 #define ECB_EXTERN_C extern "C"
626 #define ECB_EXTERN_C_BEG ECB_EXTERN_C { 656 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
627 #define ECB_EXTERN_C_END } 657 #define ECB_EXTERN_C_END }
653 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
654#endif 684#endif
655 685
656#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
657 #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")
658 #if __i386 || __i386__ 689 #if __i386 || __i386__
659 #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")
660 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
661 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
662 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
663 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 694 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
664 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 695 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
665 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 696 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
666 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 697 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
667 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 698 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
668 #elif defined __ARM_ARCH_2__ \ 699 #elif defined __ARM_ARCH_2__ \
669 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ 700 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
670 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ 701 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
712 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
713 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
714 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
715 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
716 #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)
717 749
718 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
719 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
720 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
721 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
722 #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)
723 756
724 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
725 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
726 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
727 /* 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... */
737 #elif defined _WIN32 770 #elif defined _WIN32
738 #include <WinNT.h> 771 #include <WinNT.h>
739 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
740 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
741 #include <mbarrier.h> 774 #include <mbarrier.h>
742 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
743 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
744 #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 ()
745 #elif __xlC__ 779 #elif __xlC__
746 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
747 #endif 781 #endif
748#endif 782#endif
749 783
750#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
751 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
752 /* 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, */
753 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
754 #include <stdatomic.h> 788 #include <stdatomic.h>
755 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
756 /* any fence other than seq_cst, which isn't very efficient for us. */
757 /* Why that is, we don't know - either the C11 memory model is quite useless */
758 /* for most usages, or gcc and clang have a bug */
759 /* I *currently* lean towards the latter, and inefficiently implement */
760 /* all three of ecb's fences as a seq_cst fence */
761 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
762 /* for all __atomic_thread_fence's except seq_cst */
763 #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)
764 #endif 792 #endif
765#endif 793#endif
766 794
767#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
768 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
786 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
787#endif 815#endif
788 816
789#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
790 #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 */
791#endif 823#endif
792 824
793/*****************************************************************************/ 825/*****************************************************************************/
794 826
795#if ECB_CPP 827#if ECB_CPP
1538# define ABSPRI(w) (((W)w), 0) 1570# define ABSPRI(w) (((W)w), 0)
1539#else 1571#else
1540# define ABSPRI(w) (((W)w)->priority - EV_MINPRI) 1572# define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
1541#endif 1573#endif
1542 1574
1543#define EMPTY /* required for microsofts broken pseudo-c compiler */ 1575#define EMPTY /* required for microsofts broken pseudo-c compiler */
1544#define EMPTY2(a,b) /* used to suppress some warnings */
1545 1576
1546typedef ev_watcher *W; 1577typedef ev_watcher *W;
1547typedef ev_watcher_list *WL; 1578typedef ev_watcher_list *WL;
1548typedef ev_watcher_time *WT; 1579typedef ev_watcher_time *WT;
1549 1580
1573#ifdef _WIN32 1604#ifdef _WIN32
1574# include "ev_win32.c" 1605# include "ev_win32.c"
1575#endif 1606#endif
1576 1607
1577/*****************************************************************************/ 1608/*****************************************************************************/
1609
1610#if EV_USE_LINUXAIO
1611# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1612#endif
1578 1613
1579/* define a suitable floor function (only used by periodics atm) */ 1614/* define a suitable floor function (only used by periodics atm) */
1580 1615
1581#if EV_USE_FLOOR 1616#if EV_USE_FLOOR
1582# include <math.h> 1617# include <math.h>
1675{ 1710{
1676 write (STDERR_FILENO, msg, strlen (msg)); 1711 write (STDERR_FILENO, msg, strlen (msg));
1677} 1712}
1678#endif 1713#endif
1679 1714
1680static void (*syserr_cb)(const char *msg) EV_THROW; 1715static void (*syserr_cb)(const char *msg) EV_NOEXCEPT;
1681 1716
1682ecb_cold 1717ecb_cold
1683void 1718void
1684ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW 1719ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1685{ 1720{
1686 syserr_cb = cb; 1721 syserr_cb = cb;
1687} 1722}
1688 1723
1689noinline ecb_cold 1724noinline ecb_cold
1708 abort (); 1743 abort ();
1709 } 1744 }
1710} 1745}
1711 1746
1712static void * 1747static void *
1713ev_realloc_emul (void *ptr, long size) EV_THROW 1748ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT
1714{ 1749{
1715 /* some systems, notably openbsd and darwin, fail to properly 1750 /* some systems, notably openbsd and darwin, fail to properly
1716 * implement realloc (x, 0) (as required by both ansi c-89 and 1751 * implement realloc (x, 0) (as required by both ansi c-89 and
1717 * the single unix specification, so work around them here. 1752 * the single unix specification, so work around them here.
1718 * recently, also (at least) fedora and debian started breaking it, 1753 * recently, also (at least) fedora and debian started breaking it,
1724 1759
1725 free (ptr); 1760 free (ptr);
1726 return 0; 1761 return 0;
1727} 1762}
1728 1763
1729static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1764static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul;
1730 1765
1731ecb_cold 1766ecb_cold
1732void 1767void
1733ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW 1768ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT
1734{ 1769{
1735 alloc = cb; 1770 alloc = cb;
1736} 1771}
1737 1772
1738inline_speed void * 1773inline_speed void *
1765typedef struct 1800typedef struct
1766{ 1801{
1767 WL head; 1802 WL head;
1768 unsigned char events; /* the events watched for */ 1803 unsigned char events; /* the events watched for */
1769 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ 1804 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
1770 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 1805 unsigned char emask; /* some backends store the actual kernel mask in here */
1771 unsigned char unused; 1806 unsigned char unused;
1772#if EV_USE_EPOLL 1807#if EV_USE_EPOLL
1773 unsigned int egen; /* generation counter to counter epoll bugs */ 1808 unsigned int egen; /* generation counter to counter epoll bugs */
1774#endif 1809#endif
1775#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 1810#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
1855 1890
1856/*****************************************************************************/ 1891/*****************************************************************************/
1857 1892
1858#ifndef EV_HAVE_EV_TIME 1893#ifndef EV_HAVE_EV_TIME
1859ev_tstamp 1894ev_tstamp
1860ev_time (void) EV_THROW 1895ev_time (void) EV_NOEXCEPT
1861{ 1896{
1862#if EV_USE_REALTIME 1897#if EV_USE_REALTIME
1863 if (expect_true (have_realtime)) 1898 if (expect_true (have_realtime))
1864 { 1899 {
1865 struct timespec ts; 1900 struct timespec ts;
1889 return ev_time (); 1924 return ev_time ();
1890} 1925}
1891 1926
1892#if EV_MULTIPLICITY 1927#if EV_MULTIPLICITY
1893ev_tstamp 1928ev_tstamp
1894ev_now (EV_P) EV_THROW 1929ev_now (EV_P) EV_NOEXCEPT
1895{ 1930{
1896 return ev_rt_now; 1931 return ev_rt_now;
1897} 1932}
1898#endif 1933#endif
1899 1934
1900void 1935void
1901ev_sleep (ev_tstamp delay) EV_THROW 1936ev_sleep (ev_tstamp delay) EV_NOEXCEPT
1902{ 1937{
1903 if (delay > 0.) 1938 if (delay > 0.)
1904 { 1939 {
1905#if EV_USE_NANOSLEEP 1940#if EV_USE_NANOSLEEP
1906 struct timespec ts; 1941 struct timespec ts;
1956{ 1991{
1957 *cur = array_nextsize (elem, *cur, cnt); 1992 *cur = array_nextsize (elem, *cur, cnt);
1958 return ev_realloc (base, elem * *cur); 1993 return ev_realloc (base, elem * *cur);
1959} 1994}
1960 1995
1996#define array_needsize_noinit(base,offset,count)
1997
1961#define array_init_zero(base,count) \ 1998#define array_needsize_zerofill(base,offset,count) \
1962 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1999 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1963 2000
1964#define array_needsize(type,base,cur,cnt,init) \ 2001#define array_needsize(type,base,cur,cnt,init) \
1965 if (expect_false ((cnt) > (cur))) \ 2002 if (expect_false ((cnt) > (cur))) \
1966 { \ 2003 { \
1967 ecb_unused int ocur_ = (cur); \ 2004 ecb_unused int ocur_ = (cur); \
1968 (base) = (type *)array_realloc \ 2005 (base) = (type *)array_realloc \
1969 (sizeof (type), (base), &(cur), (cnt)); \ 2006 (sizeof (type), (base), &(cur), (cnt)); \
1970 init ((base) + (ocur_), (cur) - ocur_); \ 2007 init ((base), ocur_, ((cur) - ocur_)); \
1971 } 2008 }
1972 2009
1973#if 0 2010#if 0
1974#define array_slim(type,stem) \ 2011#define array_slim(type,stem) \
1975 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2012 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
1992{ 2029{
1993} 2030}
1994 2031
1995noinline 2032noinline
1996void 2033void
1997ev_feed_event (EV_P_ void *w, int revents) EV_THROW 2034ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
1998{ 2035{
1999 W w_ = (W)w; 2036 W w_ = (W)w;
2000 int pri = ABSPRI (w_); 2037 int pri = ABSPRI (w_);
2001 2038
2002 if (expect_false (w_->pending)) 2039 if (expect_false (w_->pending))
2003 pendings [pri][w_->pending - 1].events |= revents; 2040 pendings [pri][w_->pending - 1].events |= revents;
2004 else 2041 else
2005 { 2042 {
2006 w_->pending = ++pendingcnt [pri]; 2043 w_->pending = ++pendingcnt [pri];
2007 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 2044 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
2008 pendings [pri][w_->pending - 1].w = w_; 2045 pendings [pri][w_->pending - 1].w = w_;
2009 pendings [pri][w_->pending - 1].events = revents; 2046 pendings [pri][w_->pending - 1].events = revents;
2010 } 2047 }
2011 2048
2012 pendingpri = NUMPRI - 1; 2049 pendingpri = NUMPRI - 1;
2013} 2050}
2014 2051
2015inline_speed void 2052inline_speed void
2016feed_reverse (EV_P_ W w) 2053feed_reverse (EV_P_ W w)
2017{ 2054{
2018 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); 2055 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit);
2019 rfeeds [rfeedcnt++] = w; 2056 rfeeds [rfeedcnt++] = w;
2020} 2057}
2021 2058
2022inline_size void 2059inline_size void
2023feed_reverse_done (EV_P_ int revents) 2060feed_reverse_done (EV_P_ int revents)
2063 if (expect_true (!anfd->reify)) 2100 if (expect_true (!anfd->reify))
2064 fd_event_nocheck (EV_A_ fd, revents); 2101 fd_event_nocheck (EV_A_ fd, revents);
2065} 2102}
2066 2103
2067void 2104void
2068ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW 2105ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2069{ 2106{
2070 if (fd >= 0 && fd < anfdmax) 2107 if (fd >= 0 && fd < anfdmax)
2071 fd_event_nocheck (EV_A_ fd, revents); 2108 fd_event_nocheck (EV_A_ fd, revents);
2072} 2109}
2073 2110
2110 ev_io *w; 2147 ev_io *w;
2111 2148
2112 unsigned char o_events = anfd->events; 2149 unsigned char o_events = anfd->events;
2113 unsigned char o_reify = anfd->reify; 2150 unsigned char o_reify = anfd->reify;
2114 2151
2115 anfd->reify = 0; 2152 anfd->reify = 0;
2116 2153
2117 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2154 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2118 { 2155 {
2119 anfd->events = 0; 2156 anfd->events = 0;
2120 2157
2141 anfds [fd].reify |= flags; 2178 anfds [fd].reify |= flags;
2142 2179
2143 if (expect_true (!reify)) 2180 if (expect_true (!reify))
2144 { 2181 {
2145 ++fdchangecnt; 2182 ++fdchangecnt;
2146 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 2183 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2147 fdchanges [fdchangecnt - 1] = fd; 2184 fdchanges [fdchangecnt - 1] = fd;
2148 } 2185 }
2149} 2186}
2150 2187
2151/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 2188/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
2473#endif 2510#endif
2474 { 2511 {
2475#ifdef _WIN32 2512#ifdef _WIN32
2476 WSABUF buf; 2513 WSABUF buf;
2477 DWORD sent; 2514 DWORD sent;
2478 buf.buf = &buf; 2515 buf.buf = (char *)&buf;
2479 buf.len = 1; 2516 buf.len = 1;
2480 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); 2517 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
2481#else 2518#else
2482 write (evpipe [1], &(evpipe [1]), 1); 2519 write (evpipe [1], &(evpipe [1]), 1);
2483#endif 2520#endif
2555} 2592}
2556 2593
2557/*****************************************************************************/ 2594/*****************************************************************************/
2558 2595
2559void 2596void
2560ev_feed_signal (int signum) EV_THROW 2597ev_feed_signal (int signum) EV_NOEXCEPT
2561{ 2598{
2562#if EV_MULTIPLICITY 2599#if EV_MULTIPLICITY
2563 EV_P; 2600 EV_P;
2564 ECB_MEMORY_FENCE_ACQUIRE; 2601 ECB_MEMORY_FENCE_ACQUIRE;
2565 EV_A = signals [signum - 1].loop; 2602 EV_A = signals [signum - 1].loop;
2582 ev_feed_signal (signum); 2619 ev_feed_signal (signum);
2583} 2620}
2584 2621
2585noinline 2622noinline
2586void 2623void
2587ev_feed_signal_event (EV_P_ int signum) EV_THROW 2624ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2588{ 2625{
2589 WL w; 2626 WL w;
2590 2627
2591 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2628 if (expect_false (signum <= 0 || signum >= EV_NSIG))
2592 return; 2629 return;
2701# include "ev_kqueue.c" 2738# include "ev_kqueue.c"
2702#endif 2739#endif
2703#if EV_USE_EPOLL 2740#if EV_USE_EPOLL
2704# include "ev_epoll.c" 2741# include "ev_epoll.c"
2705#endif 2742#endif
2743#if EV_USE_LINUXAIO
2744# include "ev_linuxaio.c"
2745#endif
2706#if EV_USE_POLL 2746#if EV_USE_POLL
2707# include "ev_poll.c" 2747# include "ev_poll.c"
2708#endif 2748#endif
2709#if EV_USE_SELECT 2749#if EV_USE_SELECT
2710# include "ev_select.c" 2750# include "ev_select.c"
2711#endif 2751#endif
2712 2752
2713ecb_cold int 2753ecb_cold int
2714ev_version_major (void) EV_THROW 2754ev_version_major (void) EV_NOEXCEPT
2715{ 2755{
2716 return EV_VERSION_MAJOR; 2756 return EV_VERSION_MAJOR;
2717} 2757}
2718 2758
2719ecb_cold int 2759ecb_cold int
2720ev_version_minor (void) EV_THROW 2760ev_version_minor (void) EV_NOEXCEPT
2721{ 2761{
2722 return EV_VERSION_MINOR; 2762 return EV_VERSION_MINOR;
2723} 2763}
2724 2764
2725/* return true if we are running with elevated privileges and should ignore env variables */ 2765/* return true if we are running with elevated privileges and should ignore env variables */
2734#endif 2774#endif
2735} 2775}
2736 2776
2737ecb_cold 2777ecb_cold
2738unsigned int 2778unsigned int
2739ev_supported_backends (void) EV_THROW 2779ev_supported_backends (void) EV_NOEXCEPT
2740{ 2780{
2741 unsigned int flags = 0; 2781 unsigned int flags = 0;
2742 2782
2743 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2783 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2744 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2784 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2745 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 2785 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2786 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO;
2746 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 2787 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2747 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 2788 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2748 2789
2749 return flags; 2790 return flags;
2750} 2791}
2751 2792
2752ecb_cold 2793ecb_cold
2753unsigned int 2794unsigned int
2754ev_recommended_backends (void) EV_THROW 2795ev_recommended_backends (void) EV_NOEXCEPT
2755{ 2796{
2756 unsigned int flags = ev_supported_backends (); 2797 unsigned int flags = ev_supported_backends ();
2757 2798
2758#ifndef __NetBSD__ 2799#ifndef __NetBSD__
2759 /* kqueue is borked on everything but netbsd apparently */ 2800 /* kqueue is borked on everything but netbsd apparently */
2767#endif 2808#endif
2768#ifdef __FreeBSD__ 2809#ifdef __FreeBSD__
2769 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) */
2770#endif 2811#endif
2771 2812
2813 /* TODO: linuxaio is very experimental */
2814#if !EV_RECOMMEND_LINUXAIO
2815 flags &= ~EVBACKEND_LINUXAIO;
2816#endif
2817
2772 return flags; 2818 return flags;
2773} 2819}
2774 2820
2775ecb_cold 2821ecb_cold
2776unsigned int 2822unsigned int
2777ev_embeddable_backends (void) EV_THROW 2823ev_embeddable_backends (void) EV_NOEXCEPT
2778{ 2824{
2779 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2825 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2780 2826
2781 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2827 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2782 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2828 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2784 2830
2785 return flags; 2831 return flags;
2786} 2832}
2787 2833
2788unsigned int 2834unsigned int
2789ev_backend (EV_P) EV_THROW 2835ev_backend (EV_P) EV_NOEXCEPT
2790{ 2836{
2791 return backend; 2837 return backend;
2792} 2838}
2793 2839
2794#if EV_FEATURE_API 2840#if EV_FEATURE_API
2795unsigned int 2841unsigned int
2796ev_iteration (EV_P) EV_THROW 2842ev_iteration (EV_P) EV_NOEXCEPT
2797{ 2843{
2798 return loop_count; 2844 return loop_count;
2799} 2845}
2800 2846
2801unsigned int 2847unsigned int
2802ev_depth (EV_P) EV_THROW 2848ev_depth (EV_P) EV_NOEXCEPT
2803{ 2849{
2804 return loop_depth; 2850 return loop_depth;
2805} 2851}
2806 2852
2807void 2853void
2808ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2854ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2809{ 2855{
2810 io_blocktime = interval; 2856 io_blocktime = interval;
2811} 2857}
2812 2858
2813void 2859void
2814ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2860ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2815{ 2861{
2816 timeout_blocktime = interval; 2862 timeout_blocktime = interval;
2817} 2863}
2818 2864
2819void 2865void
2820ev_set_userdata (EV_P_ void *data) EV_THROW 2866ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT
2821{ 2867{
2822 userdata = data; 2868 userdata = data;
2823} 2869}
2824 2870
2825void * 2871void *
2826ev_userdata (EV_P) EV_THROW 2872ev_userdata (EV_P) EV_NOEXCEPT
2827{ 2873{
2828 return userdata; 2874 return userdata;
2829} 2875}
2830 2876
2831void 2877void
2832ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW 2878ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT
2833{ 2879{
2834 invoke_cb = invoke_pending_cb; 2880 invoke_cb = invoke_pending_cb;
2835} 2881}
2836 2882
2837void 2883void
2838ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW 2884ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT
2839{ 2885{
2840 release_cb = release; 2886 release_cb = release;
2841 acquire_cb = acquire; 2887 acquire_cb = acquire;
2842} 2888}
2843#endif 2889#endif
2844 2890
2845/* initialise a loop structure, must be zero-initialised */ 2891/* initialise a loop structure, must be zero-initialised */
2846noinline ecb_cold 2892noinline ecb_cold
2847static void 2893static void
2848loop_init (EV_P_ unsigned int flags) EV_THROW 2894loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2849{ 2895{
2850 if (!backend) 2896 if (!backend)
2851 { 2897 {
2852 origflags = flags; 2898 origflags = flags;
2853 2899
2911 2957
2912 if (!(flags & EVBACKEND_MASK)) 2958 if (!(flags & EVBACKEND_MASK))
2913 flags |= ev_recommended_backends (); 2959 flags |= ev_recommended_backends ();
2914 2960
2915#if EV_USE_IOCP 2961#if EV_USE_IOCP
2916 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 2962 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
2917#endif 2963#endif
2918#if EV_USE_PORT 2964#if EV_USE_PORT
2919 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 2965 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
2920#endif 2966#endif
2921#if EV_USE_KQUEUE 2967#if EV_USE_KQUEUE
2922 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 2968 if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags);
2969#endif
2970#if EV_USE_LINUXAIO
2971 if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags);
2923#endif 2972#endif
2924#if EV_USE_EPOLL 2973#if EV_USE_EPOLL
2925 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); 2974 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
2926#endif 2975#endif
2927#if EV_USE_POLL 2976#if EV_USE_POLL
2928 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); 2977 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
2929#endif 2978#endif
2930#if EV_USE_SELECT 2979#if EV_USE_SELECT
2931 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 2980 if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags);
2932#endif 2981#endif
2933 2982
2934 ev_prepare_init (&pending_w, pendingcb); 2983 ev_prepare_init (&pending_w, pendingcb);
2935 2984
2936#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2985#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2991 3040
2992 if (backend_fd >= 0) 3041 if (backend_fd >= 0)
2993 close (backend_fd); 3042 close (backend_fd);
2994 3043
2995#if EV_USE_IOCP 3044#if EV_USE_IOCP
2996 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); 3045 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
2997#endif 3046#endif
2998#if EV_USE_PORT 3047#if EV_USE_PORT
2999 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 3048 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
3000#endif 3049#endif
3001#if EV_USE_KQUEUE 3050#if EV_USE_KQUEUE
3002 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 3051 if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A);
3052#endif
3053#if EV_USE_LINUXAIO
3054 if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A);
3003#endif 3055#endif
3004#if EV_USE_EPOLL 3056#if EV_USE_EPOLL
3005 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 3057 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
3006#endif 3058#endif
3007#if EV_USE_POLL 3059#if EV_USE_POLL
3008 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); 3060 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
3009#endif 3061#endif
3010#if EV_USE_SELECT 3062#if EV_USE_SELECT
3011 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 3063 if (backend == EVBACKEND_SELECT ) select_destroy (EV_A);
3012#endif 3064#endif
3013 3065
3014 for (i = NUMPRI; i--; ) 3066 for (i = NUMPRI; i--; )
3015 { 3067 {
3016 array_free (pending, [i]); 3068 array_free (pending, [i]);
3058 3110
3059inline_size void 3111inline_size void
3060loop_fork (EV_P) 3112loop_fork (EV_P)
3061{ 3113{
3062#if EV_USE_PORT 3114#if EV_USE_PORT
3063 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 3115 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
3064#endif 3116#endif
3065#if EV_USE_KQUEUE 3117#if EV_USE_KQUEUE
3066 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 3118 if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A);
3119#endif
3120#if EV_USE_LINUXAIO
3121 if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A);
3067#endif 3122#endif
3068#if EV_USE_EPOLL 3123#if EV_USE_EPOLL
3069 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 3124 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
3070#endif 3125#endif
3071#if EV_USE_INOTIFY 3126#if EV_USE_INOTIFY
3072 infy_fork (EV_A); 3127 infy_fork (EV_A);
3073#endif 3128#endif
3074 3129
3094 3149
3095#if EV_MULTIPLICITY 3150#if EV_MULTIPLICITY
3096 3151
3097ecb_cold 3152ecb_cold
3098struct ev_loop * 3153struct ev_loop *
3099ev_loop_new (unsigned int flags) EV_THROW 3154ev_loop_new (unsigned int flags) EV_NOEXCEPT
3100{ 3155{
3101 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 3156 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
3102 3157
3103 memset (EV_A, 0, sizeof (struct ev_loop)); 3158 memset (EV_A, 0, sizeof (struct ev_loop));
3104 loop_init (EV_A_ flags); 3159 loop_init (EV_A_ flags);
3151} 3206}
3152#endif 3207#endif
3153 3208
3154#if EV_FEATURE_API 3209#if EV_FEATURE_API
3155void ecb_cold 3210void ecb_cold
3156ev_verify (EV_P) EV_THROW 3211ev_verify (EV_P) EV_NOEXCEPT
3157{ 3212{
3158#if EV_VERIFY 3213#if EV_VERIFY
3159 int i; 3214 int i;
3160 WL w, w2; 3215 WL w, w2;
3161 3216
3242ecb_cold 3297ecb_cold
3243struct ev_loop * 3298struct ev_loop *
3244#else 3299#else
3245int 3300int
3246#endif 3301#endif
3247ev_default_loop (unsigned int flags) EV_THROW 3302ev_default_loop (unsigned int flags) EV_NOEXCEPT
3248{ 3303{
3249 if (!ev_default_loop_ptr) 3304 if (!ev_default_loop_ptr)
3250 { 3305 {
3251#if EV_MULTIPLICITY 3306#if EV_MULTIPLICITY
3252 EV_P = ev_default_loop_ptr = &default_loop_struct; 3307 EV_P = ev_default_loop_ptr = &default_loop_struct;
3271 3326
3272 return ev_default_loop_ptr; 3327 return ev_default_loop_ptr;
3273} 3328}
3274 3329
3275void 3330void
3276ev_loop_fork (EV_P) EV_THROW 3331ev_loop_fork (EV_P) EV_NOEXCEPT
3277{ 3332{
3278 postfork = 1; 3333 postfork = 1;
3279} 3334}
3280 3335
3281/*****************************************************************************/ 3336/*****************************************************************************/
3285{ 3340{
3286 EV_CB_INVOKE ((W)w, revents); 3341 EV_CB_INVOKE ((W)w, revents);
3287} 3342}
3288 3343
3289unsigned int 3344unsigned int
3290ev_pending_count (EV_P) EV_THROW 3345ev_pending_count (EV_P) EV_NOEXCEPT
3291{ 3346{
3292 int pri; 3347 int pri;
3293 unsigned int count = 0; 3348 unsigned int count = 0;
3294 3349
3295 for (pri = NUMPRI; pri--; ) 3350 for (pri = NUMPRI; pri--; )
3302void 3357void
3303ev_invoke_pending (EV_P) 3358ev_invoke_pending (EV_P)
3304{ 3359{
3305 pendingpri = NUMPRI; 3360 pendingpri = NUMPRI;
3306 3361
3307 while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ 3362 do
3308 { 3363 {
3309 --pendingpri; 3364 --pendingpri;
3310 3365
3366 /* pendingpri possibly gets modified in the inner loop */
3311 while (pendingcnt [pendingpri]) 3367 while (pendingcnt [pendingpri])
3312 { 3368 {
3313 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; 3369 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
3314 3370
3315 p->w->pending = 0; 3371 p->w->pending = 0;
3316 EV_CB_INVOKE (p->w, p->events); 3372 EV_CB_INVOKE (p->w, p->events);
3317 EV_FREQUENT_CHECK; 3373 EV_FREQUENT_CHECK;
3318 } 3374 }
3319 } 3375 }
3376 while (pendingpri);
3320} 3377}
3321 3378
3322#if EV_IDLE_ENABLE 3379#if EV_IDLE_ENABLE
3323/* make idle watchers pending. this handles the "call-idle */ 3380/* make idle watchers pending. this handles the "call-idle */
3324/* only when higher priorities are idle" logic */ 3381/* only when higher priorities are idle" logic */
3733 3790
3734 return activecnt; 3791 return activecnt;
3735} 3792}
3736 3793
3737void 3794void
3738ev_break (EV_P_ int how) EV_THROW 3795ev_break (EV_P_ int how) EV_NOEXCEPT
3739{ 3796{
3740 loop_done = how; 3797 loop_done = how;
3741} 3798}
3742 3799
3743void 3800void
3744ev_ref (EV_P) EV_THROW 3801ev_ref (EV_P) EV_NOEXCEPT
3745{ 3802{
3746 ++activecnt; 3803 ++activecnt;
3747} 3804}
3748 3805
3749void 3806void
3750ev_unref (EV_P) EV_THROW 3807ev_unref (EV_P) EV_NOEXCEPT
3751{ 3808{
3752 --activecnt; 3809 --activecnt;
3753} 3810}
3754 3811
3755void 3812void
3756ev_now_update (EV_P) EV_THROW 3813ev_now_update (EV_P) EV_NOEXCEPT
3757{ 3814{
3758 time_update (EV_A_ 1e100); 3815 time_update (EV_A_ 1e100);
3759} 3816}
3760 3817
3761void 3818void
3762ev_suspend (EV_P) EV_THROW 3819ev_suspend (EV_P) EV_NOEXCEPT
3763{ 3820{
3764 ev_now_update (EV_A); 3821 ev_now_update (EV_A);
3765} 3822}
3766 3823
3767void 3824void
3768ev_resume (EV_P) EV_THROW 3825ev_resume (EV_P) EV_NOEXCEPT
3769{ 3826{
3770 ev_tstamp mn_prev = mn_now; 3827 ev_tstamp mn_prev = mn_now;
3771 3828
3772 ev_now_update (EV_A); 3829 ev_now_update (EV_A);
3773 timers_reschedule (EV_A_ mn_now - mn_prev); 3830 timers_reschedule (EV_A_ mn_now - mn_prev);
3812 w->pending = 0; 3869 w->pending = 0;
3813 } 3870 }
3814} 3871}
3815 3872
3816int 3873int
3817ev_clear_pending (EV_P_ void *w) EV_THROW 3874ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3818{ 3875{
3819 W w_ = (W)w; 3876 W w_ = (W)w;
3820 int pending = w_->pending; 3877 int pending = w_->pending;
3821 3878
3822 if (expect_true (pending)) 3879 if (expect_true (pending))
3856 3913
3857/*****************************************************************************/ 3914/*****************************************************************************/
3858 3915
3859noinline 3916noinline
3860void 3917void
3861ev_io_start (EV_P_ ev_io *w) EV_THROW 3918ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3862{ 3919{
3863 int fd = w->fd; 3920 int fd = w->fd;
3864 3921
3865 if (expect_false (ev_is_active (w))) 3922 if (expect_false (ev_is_active (w)))
3866 return; 3923 return;
3867 3924
3868 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3925 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3869 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3926 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3870 3927
3928#if EV_VERIFY >= 2
3929 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3930#endif
3871 EV_FREQUENT_CHECK; 3931 EV_FREQUENT_CHECK;
3872 3932
3873 ev_start (EV_A_ (W)w, 1); 3933 ev_start (EV_A_ (W)w, 1);
3874 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3934 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3875 wlist_add (&anfds[fd].head, (WL)w); 3935 wlist_add (&anfds[fd].head, (WL)w);
3876 3936
3877 /* common bug, apparently */ 3937 /* common bug, apparently */
3878 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3938 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3879 3939
3883 EV_FREQUENT_CHECK; 3943 EV_FREQUENT_CHECK;
3884} 3944}
3885 3945
3886noinline 3946noinline
3887void 3947void
3888ev_io_stop (EV_P_ ev_io *w) EV_THROW 3948ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3889{ 3949{
3890 clear_pending (EV_A_ (W)w); 3950 clear_pending (EV_A_ (W)w);
3891 if (expect_false (!ev_is_active (w))) 3951 if (expect_false (!ev_is_active (w)))
3892 return; 3952 return;
3893 3953
3894 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 3954 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
3895 3955
3956#if EV_VERIFY >= 2
3957 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3958#endif
3896 EV_FREQUENT_CHECK; 3959 EV_FREQUENT_CHECK;
3897 3960
3898 wlist_del (&anfds[w->fd].head, (WL)w); 3961 wlist_del (&anfds[w->fd].head, (WL)w);
3899 ev_stop (EV_A_ (W)w); 3962 ev_stop (EV_A_ (W)w);
3900 3963
3903 EV_FREQUENT_CHECK; 3966 EV_FREQUENT_CHECK;
3904} 3967}
3905 3968
3906noinline 3969noinline
3907void 3970void
3908ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3971ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3909{ 3972{
3910 if (expect_false (ev_is_active (w))) 3973 if (expect_false (ev_is_active (w)))
3911 return; 3974 return;
3912 3975
3913 ev_at (w) += mn_now; 3976 ev_at (w) += mn_now;
3916 3979
3917 EV_FREQUENT_CHECK; 3980 EV_FREQUENT_CHECK;
3918 3981
3919 ++timercnt; 3982 ++timercnt;
3920 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3983 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3921 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3984 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3922 ANHE_w (timers [ev_active (w)]) = (WT)w; 3985 ANHE_w (timers [ev_active (w)]) = (WT)w;
3923 ANHE_at_cache (timers [ev_active (w)]); 3986 ANHE_at_cache (timers [ev_active (w)]);
3924 upheap (timers, ev_active (w)); 3987 upheap (timers, ev_active (w));
3925 3988
3926 EV_FREQUENT_CHECK; 3989 EV_FREQUENT_CHECK;
3928 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3991 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3929} 3992}
3930 3993
3931noinline 3994noinline
3932void 3995void
3933ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3996ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3934{ 3997{
3935 clear_pending (EV_A_ (W)w); 3998 clear_pending (EV_A_ (W)w);
3936 if (expect_false (!ev_is_active (w))) 3999 if (expect_false (!ev_is_active (w)))
3937 return; 4000 return;
3938 4001
3959 EV_FREQUENT_CHECK; 4022 EV_FREQUENT_CHECK;
3960} 4023}
3961 4024
3962noinline 4025noinline
3963void 4026void
3964ev_timer_again (EV_P_ ev_timer *w) EV_THROW 4027ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3965{ 4028{
3966 EV_FREQUENT_CHECK; 4029 EV_FREQUENT_CHECK;
3967 4030
3968 clear_pending (EV_A_ (W)w); 4031 clear_pending (EV_A_ (W)w);
3969 4032
3986 4049
3987 EV_FREQUENT_CHECK; 4050 EV_FREQUENT_CHECK;
3988} 4051}
3989 4052
3990ev_tstamp 4053ev_tstamp
3991ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 4054ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3992{ 4055{
3993 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4056 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3994} 4057}
3995 4058
3996#if EV_PERIODIC_ENABLE 4059#if EV_PERIODIC_ENABLE
3997noinline 4060noinline
3998void 4061void
3999ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4062ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4000{ 4063{
4001 if (expect_false (ev_is_active (w))) 4064 if (expect_false (ev_is_active (w)))
4002 return; 4065 return;
4003 4066
4004 if (w->reschedule_cb) 4067 if (w->reschedule_cb)
4013 4076
4014 EV_FREQUENT_CHECK; 4077 EV_FREQUENT_CHECK;
4015 4078
4016 ++periodiccnt; 4079 ++periodiccnt;
4017 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4080 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
4018 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4081 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
4019 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4082 ANHE_w (periodics [ev_active (w)]) = (WT)w;
4020 ANHE_at_cache (periodics [ev_active (w)]); 4083 ANHE_at_cache (periodics [ev_active (w)]);
4021 upheap (periodics, ev_active (w)); 4084 upheap (periodics, ev_active (w));
4022 4085
4023 EV_FREQUENT_CHECK; 4086 EV_FREQUENT_CHECK;
4025 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4088 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
4026} 4089}
4027 4090
4028noinline 4091noinline
4029void 4092void
4030ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4093ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4031{ 4094{
4032 clear_pending (EV_A_ (W)w); 4095 clear_pending (EV_A_ (W)w);
4033 if (expect_false (!ev_is_active (w))) 4096 if (expect_false (!ev_is_active (w)))
4034 return; 4097 return;
4035 4098
4054 EV_FREQUENT_CHECK; 4117 EV_FREQUENT_CHECK;
4055} 4118}
4056 4119
4057noinline 4120noinline
4058void 4121void
4059ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4122ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4060{ 4123{
4061 /* TODO: use adjustheap and recalculation */ 4124 /* TODO: use adjustheap and recalculation */
4062 ev_periodic_stop (EV_A_ w); 4125 ev_periodic_stop (EV_A_ w);
4063 ev_periodic_start (EV_A_ w); 4126 ev_periodic_start (EV_A_ w);
4064} 4127}
4070 4133
4071#if EV_SIGNAL_ENABLE 4134#if EV_SIGNAL_ENABLE
4072 4135
4073noinline 4136noinline
4074void 4137void
4075ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4138ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4076{ 4139{
4077 if (expect_false (ev_is_active (w))) 4140 if (expect_false (ev_is_active (w)))
4078 return; 4141 return;
4079 4142
4080 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4143 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4153 EV_FREQUENT_CHECK; 4216 EV_FREQUENT_CHECK;
4154} 4217}
4155 4218
4156noinline 4219noinline
4157void 4220void
4158ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4221ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4159{ 4222{
4160 clear_pending (EV_A_ (W)w); 4223 clear_pending (EV_A_ (W)w);
4161 if (expect_false (!ev_is_active (w))) 4224 if (expect_false (!ev_is_active (w)))
4162 return; 4225 return;
4163 4226
4194#endif 4257#endif
4195 4258
4196#if EV_CHILD_ENABLE 4259#if EV_CHILD_ENABLE
4197 4260
4198void 4261void
4199ev_child_start (EV_P_ ev_child *w) EV_THROW 4262ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4200{ 4263{
4201#if EV_MULTIPLICITY 4264#if EV_MULTIPLICITY
4202 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4265 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4203#endif 4266#endif
4204 if (expect_false (ev_is_active (w))) 4267 if (expect_false (ev_is_active (w)))
4211 4274
4212 EV_FREQUENT_CHECK; 4275 EV_FREQUENT_CHECK;
4213} 4276}
4214 4277
4215void 4278void
4216ev_child_stop (EV_P_ ev_child *w) EV_THROW 4279ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4217{ 4280{
4218 clear_pending (EV_A_ (W)w); 4281 clear_pending (EV_A_ (W)w);
4219 if (expect_false (!ev_is_active (w))) 4282 if (expect_false (!ev_is_active (w)))
4220 return; 4283 return;
4221 4284
4486#else 4549#else
4487# define EV_LSTAT(p,b) lstat (p, b) 4550# define EV_LSTAT(p,b) lstat (p, b)
4488#endif 4551#endif
4489 4552
4490void 4553void
4491ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4554ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4492{ 4555{
4493 if (lstat (w->path, &w->attr) < 0) 4556 if (lstat (w->path, &w->attr) < 0)
4494 w->attr.st_nlink = 0; 4557 w->attr.st_nlink = 0;
4495 else if (!w->attr.st_nlink) 4558 else if (!w->attr.st_nlink)
4496 w->attr.st_nlink = 1; 4559 w->attr.st_nlink = 1;
4536 ev_feed_event (EV_A_ w, EV_STAT); 4599 ev_feed_event (EV_A_ w, EV_STAT);
4537 } 4600 }
4538} 4601}
4539 4602
4540void 4603void
4541ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4604ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4542{ 4605{
4543 if (expect_false (ev_is_active (w))) 4606 if (expect_false (ev_is_active (w)))
4544 return; 4607 return;
4545 4608
4546 ev_stat_stat (EV_A_ w); 4609 ev_stat_stat (EV_A_ w);
4567 4630
4568 EV_FREQUENT_CHECK; 4631 EV_FREQUENT_CHECK;
4569} 4632}
4570 4633
4571void 4634void
4572ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4635ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4573{ 4636{
4574 clear_pending (EV_A_ (W)w); 4637 clear_pending (EV_A_ (W)w);
4575 if (expect_false (!ev_is_active (w))) 4638 if (expect_false (!ev_is_active (w)))
4576 return; 4639 return;
4577 4640
4593} 4656}
4594#endif 4657#endif
4595 4658
4596#if EV_IDLE_ENABLE 4659#if EV_IDLE_ENABLE
4597void 4660void
4598ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4661ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4599{ 4662{
4600 if (expect_false (ev_is_active (w))) 4663 if (expect_false (ev_is_active (w)))
4601 return; 4664 return;
4602 4665
4603 pri_adjust (EV_A_ (W)w); 4666 pri_adjust (EV_A_ (W)w);
4608 int active = ++idlecnt [ABSPRI (w)]; 4671 int active = ++idlecnt [ABSPRI (w)];
4609 4672
4610 ++idleall; 4673 ++idleall;
4611 ev_start (EV_A_ (W)w, active); 4674 ev_start (EV_A_ (W)w, active);
4612 4675
4613 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4676 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4614 idles [ABSPRI (w)][active - 1] = w; 4677 idles [ABSPRI (w)][active - 1] = w;
4615 } 4678 }
4616 4679
4617 EV_FREQUENT_CHECK; 4680 EV_FREQUENT_CHECK;
4618} 4681}
4619 4682
4620void 4683void
4621ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4684ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4622{ 4685{
4623 clear_pending (EV_A_ (W)w); 4686 clear_pending (EV_A_ (W)w);
4624 if (expect_false (!ev_is_active (w))) 4687 if (expect_false (!ev_is_active (w)))
4625 return; 4688 return;
4626 4689
4640} 4703}
4641#endif 4704#endif
4642 4705
4643#if EV_PREPARE_ENABLE 4706#if EV_PREPARE_ENABLE
4644void 4707void
4645ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4708ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4646{ 4709{
4647 if (expect_false (ev_is_active (w))) 4710 if (expect_false (ev_is_active (w)))
4648 return; 4711 return;
4649 4712
4650 EV_FREQUENT_CHECK; 4713 EV_FREQUENT_CHECK;
4651 4714
4652 ev_start (EV_A_ (W)w, ++preparecnt); 4715 ev_start (EV_A_ (W)w, ++preparecnt);
4653 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4716 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4654 prepares [preparecnt - 1] = w; 4717 prepares [preparecnt - 1] = w;
4655 4718
4656 EV_FREQUENT_CHECK; 4719 EV_FREQUENT_CHECK;
4657} 4720}
4658 4721
4659void 4722void
4660ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4723ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4661{ 4724{
4662 clear_pending (EV_A_ (W)w); 4725 clear_pending (EV_A_ (W)w);
4663 if (expect_false (!ev_is_active (w))) 4726 if (expect_false (!ev_is_active (w)))
4664 return; 4727 return;
4665 4728
4678} 4741}
4679#endif 4742#endif
4680 4743
4681#if EV_CHECK_ENABLE 4744#if EV_CHECK_ENABLE
4682void 4745void
4683ev_check_start (EV_P_ ev_check *w) EV_THROW 4746ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4684{ 4747{
4685 if (expect_false (ev_is_active (w))) 4748 if (expect_false (ev_is_active (w)))
4686 return; 4749 return;
4687 4750
4688 EV_FREQUENT_CHECK; 4751 EV_FREQUENT_CHECK;
4689 4752
4690 ev_start (EV_A_ (W)w, ++checkcnt); 4753 ev_start (EV_A_ (W)w, ++checkcnt);
4691 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4754 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4692 checks [checkcnt - 1] = w; 4755 checks [checkcnt - 1] = w;
4693 4756
4694 EV_FREQUENT_CHECK; 4757 EV_FREQUENT_CHECK;
4695} 4758}
4696 4759
4697void 4760void
4698ev_check_stop (EV_P_ ev_check *w) EV_THROW 4761ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4699{ 4762{
4700 clear_pending (EV_A_ (W)w); 4763 clear_pending (EV_A_ (W)w);
4701 if (expect_false (!ev_is_active (w))) 4764 if (expect_false (!ev_is_active (w)))
4702 return; 4765 return;
4703 4766
4717#endif 4780#endif
4718 4781
4719#if EV_EMBED_ENABLE 4782#if EV_EMBED_ENABLE
4720noinline 4783noinline
4721void 4784void
4722ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4785ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4723{ 4786{
4724 ev_run (w->other, EVRUN_NOWAIT); 4787 ev_run (w->other, EVRUN_NOWAIT);
4725} 4788}
4726 4789
4727static void 4790static void
4775 ev_idle_stop (EV_A_ idle); 4838 ev_idle_stop (EV_A_ idle);
4776} 4839}
4777#endif 4840#endif
4778 4841
4779void 4842void
4780ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4843ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4781{ 4844{
4782 if (expect_false (ev_is_active (w))) 4845 if (expect_false (ev_is_active (w)))
4783 return; 4846 return;
4784 4847
4785 { 4848 {
4806 4869
4807 EV_FREQUENT_CHECK; 4870 EV_FREQUENT_CHECK;
4808} 4871}
4809 4872
4810void 4873void
4811ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4874ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4812{ 4875{
4813 clear_pending (EV_A_ (W)w); 4876 clear_pending (EV_A_ (W)w);
4814 if (expect_false (!ev_is_active (w))) 4877 if (expect_false (!ev_is_active (w)))
4815 return; 4878 return;
4816 4879
4826} 4889}
4827#endif 4890#endif
4828 4891
4829#if EV_FORK_ENABLE 4892#if EV_FORK_ENABLE
4830void 4893void
4831ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4894ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4832{ 4895{
4833 if (expect_false (ev_is_active (w))) 4896 if (expect_false (ev_is_active (w)))
4834 return; 4897 return;
4835 4898
4836 EV_FREQUENT_CHECK; 4899 EV_FREQUENT_CHECK;
4837 4900
4838 ev_start (EV_A_ (W)w, ++forkcnt); 4901 ev_start (EV_A_ (W)w, ++forkcnt);
4839 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4902 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4840 forks [forkcnt - 1] = w; 4903 forks [forkcnt - 1] = w;
4841 4904
4842 EV_FREQUENT_CHECK; 4905 EV_FREQUENT_CHECK;
4843} 4906}
4844 4907
4845void 4908void
4846ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4909ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4847{ 4910{
4848 clear_pending (EV_A_ (W)w); 4911 clear_pending (EV_A_ (W)w);
4849 if (expect_false (!ev_is_active (w))) 4912 if (expect_false (!ev_is_active (w)))
4850 return; 4913 return;
4851 4914
4864} 4927}
4865#endif 4928#endif
4866 4929
4867#if EV_CLEANUP_ENABLE 4930#if EV_CLEANUP_ENABLE
4868void 4931void
4869ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4932ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4870{ 4933{
4871 if (expect_false (ev_is_active (w))) 4934 if (expect_false (ev_is_active (w)))
4872 return; 4935 return;
4873 4936
4874 EV_FREQUENT_CHECK; 4937 EV_FREQUENT_CHECK;
4875 4938
4876 ev_start (EV_A_ (W)w, ++cleanupcnt); 4939 ev_start (EV_A_ (W)w, ++cleanupcnt);
4877 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4940 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4878 cleanups [cleanupcnt - 1] = w; 4941 cleanups [cleanupcnt - 1] = w;
4879 4942
4880 /* cleanup watchers should never keep a refcount on the loop */ 4943 /* cleanup watchers should never keep a refcount on the loop */
4881 ev_unref (EV_A); 4944 ev_unref (EV_A);
4882 EV_FREQUENT_CHECK; 4945 EV_FREQUENT_CHECK;
4883} 4946}
4884 4947
4885void 4948void
4886ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4949ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4887{ 4950{
4888 clear_pending (EV_A_ (W)w); 4951 clear_pending (EV_A_ (W)w);
4889 if (expect_false (!ev_is_active (w))) 4952 if (expect_false (!ev_is_active (w)))
4890 return; 4953 return;
4891 4954
4905} 4968}
4906#endif 4969#endif
4907 4970
4908#if EV_ASYNC_ENABLE 4971#if EV_ASYNC_ENABLE
4909void 4972void
4910ev_async_start (EV_P_ ev_async *w) EV_THROW 4973ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4911{ 4974{
4912 if (expect_false (ev_is_active (w))) 4975 if (expect_false (ev_is_active (w)))
4913 return; 4976 return;
4914 4977
4915 w->sent = 0; 4978 w->sent = 0;
4917 evpipe_init (EV_A); 4980 evpipe_init (EV_A);
4918 4981
4919 EV_FREQUENT_CHECK; 4982 EV_FREQUENT_CHECK;
4920 4983
4921 ev_start (EV_A_ (W)w, ++asynccnt); 4984 ev_start (EV_A_ (W)w, ++asynccnt);
4922 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4985 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4923 asyncs [asynccnt - 1] = w; 4986 asyncs [asynccnt - 1] = w;
4924 4987
4925 EV_FREQUENT_CHECK; 4988 EV_FREQUENT_CHECK;
4926} 4989}
4927 4990
4928void 4991void
4929ev_async_stop (EV_P_ ev_async *w) EV_THROW 4992ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4930{ 4993{
4931 clear_pending (EV_A_ (W)w); 4994 clear_pending (EV_A_ (W)w);
4932 if (expect_false (!ev_is_active (w))) 4995 if (expect_false (!ev_is_active (w)))
4933 return; 4996 return;
4934 4997
4945 5008
4946 EV_FREQUENT_CHECK; 5009 EV_FREQUENT_CHECK;
4947} 5010}
4948 5011
4949void 5012void
4950ev_async_send (EV_P_ ev_async *w) EV_THROW 5013ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4951{ 5014{
4952 w->sent = 1; 5015 w->sent = 1;
4953 evpipe_write (EV_A_ &async_pending); 5016 evpipe_write (EV_A_ &async_pending);
4954} 5017}
4955#endif 5018#endif
4992 5055
4993 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5056 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4994} 5057}
4995 5058
4996void 5059void
4997ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5060ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
4998{ 5061{
4999 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5062 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
5000
5001 if (expect_false (!once))
5002 {
5003 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
5004 return;
5005 }
5006 5063
5007 once->cb = cb; 5064 once->cb = cb;
5008 once->arg = arg; 5065 once->arg = arg;
5009 5066
5010 ev_init (&once->io, once_cb_io); 5067 ev_init (&once->io, once_cb_io);
5025/*****************************************************************************/ 5082/*****************************************************************************/
5026 5083
5027#if EV_WALK_ENABLE 5084#if EV_WALK_ENABLE
5028ecb_cold 5085ecb_cold
5029void 5086void
5030ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5087ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
5031{ 5088{
5032 int i, j; 5089 int i, j;
5033 ev_watcher_list *wl, *wn; 5090 ev_watcher_list *wl, *wn;
5034 5091
5035 if (types & (EV_IO | EV_EMBED)) 5092 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines