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

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines