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

Comparing libev/ev.c (file contents):
Revision 1.479 by root, Sun Dec 20 01:31:17 2015 UTC vs.
Revision 1.494 by root, Sun Jun 23 23:28:45 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
363 382
364#ifndef EV_HEAP_CACHE_AT 383#ifndef EV_HEAP_CACHE_AT
365# define EV_HEAP_CACHE_AT EV_FEATURE_DATA 384# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
366#endif 385#endif
367 386
368#ifdef ANDROID 387#ifdef __ANDROID__
369/* supposedly, android doesn't typedef fd_mask */ 388/* supposedly, android doesn't typedef fd_mask */
370# undef EV_USE_SELECT 389# undef EV_USE_SELECT
371# define EV_USE_SELECT 0 390# define EV_USE_SELECT 0
372/* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ 391/* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */
373# undef EV_USE_CLOCK_SYSCALL 392# undef EV_USE_CLOCK_SYSCALL
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
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>
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 }
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
658 #if __i386 || __i386__ 688 #if __i386 || __i386__
659 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 689 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
660 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 690 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
661 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 691 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
662 #elif ECB_GCC_AMD64 692 #elif ECB_GCC_AMD64
663 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 693 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
664 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 694 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
665 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 695 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
666 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 696 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
667 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 697 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
668 #elif defined __ARM_ARCH_2__ \ 698 #elif defined __ARM_ARCH_2__ \
669 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ 699 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
670 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ 700 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
1527#define inline_size ecb_inline 1557#define inline_size ecb_inline
1528 1558
1529#if EV_FEATURE_CODE 1559#if EV_FEATURE_CODE
1530# define inline_speed ecb_inline 1560# define inline_speed ecb_inline
1531#else 1561#else
1532# define inline_speed static noinline 1562# define inline_speed noinline static
1533#endif 1563#endif
1534 1564
1535#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1565#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1536 1566
1537#if EV_MINPRI == EV_MAXPRI 1567#if EV_MINPRI == EV_MAXPRI
1538# define ABSPRI(w) (((W)w), 0) 1568# define ABSPRI(w) (((W)w), 0)
1539#else 1569#else
1540# define ABSPRI(w) (((W)w)->priority - EV_MINPRI) 1570# define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
1541#endif 1571#endif
1542 1572
1543#define EMPTY /* required for microsofts broken pseudo-c compiler */ 1573#define EMPTY /* required for microsofts broken pseudo-c compiler */
1544#define EMPTY2(a,b) /* used to suppress some warnings */
1545 1574
1546typedef ev_watcher *W; 1575typedef ev_watcher *W;
1547typedef ev_watcher_list *WL; 1576typedef ev_watcher_list *WL;
1548typedef ev_watcher_time *WT; 1577typedef ev_watcher_time *WT;
1549 1578
1574# include "ev_win32.c" 1603# include "ev_win32.c"
1575#endif 1604#endif
1576 1605
1577/*****************************************************************************/ 1606/*****************************************************************************/
1578 1607
1608#if EV_USE_LINUXAIO
1609# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1610#endif
1611
1579/* define a suitable floor function (only used by periodics atm) */ 1612/* define a suitable floor function (only used by periodics atm) */
1580 1613
1581#if EV_USE_FLOOR 1614#if EV_USE_FLOOR
1582# include <math.h> 1615# include <math.h>
1583# define ev_floor(v) floor (v) 1616# define ev_floor(v) floor (v)
1584#else 1617#else
1585 1618
1586#include <float.h> 1619#include <float.h>
1587 1620
1588/* a floor() replacement function, should be independent of ev_tstamp type */ 1621/* a floor() replacement function, should be independent of ev_tstamp type */
1622noinline
1589static ev_tstamp noinline 1623static ev_tstamp
1590ev_floor (ev_tstamp v) 1624ev_floor (ev_tstamp v)
1591{ 1625{
1592 /* the choice of shift factor is not terribly important */ 1626 /* the choice of shift factor is not terribly important */
1593#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1627#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1594 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; 1628 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.;
1626 1660
1627#ifdef __linux 1661#ifdef __linux
1628# include <sys/utsname.h> 1662# include <sys/utsname.h>
1629#endif 1663#endif
1630 1664
1631static unsigned int noinline ecb_cold 1665noinline ecb_cold
1666static unsigned int
1632ev_linux_version (void) 1667ev_linux_version (void)
1633{ 1668{
1634#ifdef __linux 1669#ifdef __linux
1635 unsigned int v = 0; 1670 unsigned int v = 0;
1636 struct utsname buf; 1671 struct utsname buf;
1665} 1700}
1666 1701
1667/*****************************************************************************/ 1702/*****************************************************************************/
1668 1703
1669#if EV_AVOID_STDIO 1704#if EV_AVOID_STDIO
1670static void noinline ecb_cold 1705noinline ecb_cold
1706static void
1671ev_printerr (const char *msg) 1707ev_printerr (const char *msg)
1672{ 1708{
1673 write (STDERR_FILENO, msg, strlen (msg)); 1709 write (STDERR_FILENO, msg, strlen (msg));
1674} 1710}
1675#endif 1711#endif
1676 1712
1677static void (*syserr_cb)(const char *msg) EV_THROW; 1713static void (*syserr_cb)(const char *msg) EV_NOEXCEPT;
1678 1714
1679void ecb_cold 1715ecb_cold
1716void
1680ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW 1717ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1681{ 1718{
1682 syserr_cb = cb; 1719 syserr_cb = cb;
1683} 1720}
1684 1721
1685static void noinline ecb_cold 1722noinline ecb_cold
1723static void
1686ev_syserr (const char *msg) 1724ev_syserr (const char *msg)
1687{ 1725{
1688 if (!msg) 1726 if (!msg)
1689 msg = "(libev) system error"; 1727 msg = "(libev) system error";
1690 1728
1703 abort (); 1741 abort ();
1704 } 1742 }
1705} 1743}
1706 1744
1707static void * 1745static void *
1708ev_realloc_emul (void *ptr, long size) EV_THROW 1746ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT
1709{ 1747{
1710 /* some systems, notably openbsd and darwin, fail to properly 1748 /* some systems, notably openbsd and darwin, fail to properly
1711 * implement realloc (x, 0) (as required by both ansi c-89 and 1749 * implement realloc (x, 0) (as required by both ansi c-89 and
1712 * the single unix specification, so work around them here. 1750 * the single unix specification, so work around them here.
1713 * recently, also (at least) fedora and debian started breaking it, 1751 * recently, also (at least) fedora and debian started breaking it,
1719 1757
1720 free (ptr); 1758 free (ptr);
1721 return 0; 1759 return 0;
1722} 1760}
1723 1761
1724static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1762static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul;
1725 1763
1726void ecb_cold 1764ecb_cold
1765void
1727ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW 1766ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT
1728{ 1767{
1729 alloc = cb; 1768 alloc = cb;
1730} 1769}
1731 1770
1732inline_speed void * 1771inline_speed void *
1759typedef struct 1798typedef struct
1760{ 1799{
1761 WL head; 1800 WL head;
1762 unsigned char events; /* the events watched for */ 1801 unsigned char events; /* the events watched for */
1763 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ 1802 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
1764 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 1803 unsigned char emask; /* some backends store the actual kernel mask in here */
1765 unsigned char unused; 1804 unsigned char unused;
1766#if EV_USE_EPOLL 1805#if EV_USE_EPOLL
1767 unsigned int egen; /* generation counter to counter epoll bugs */ 1806 unsigned int egen; /* generation counter to counter epoll bugs */
1768#endif 1807#endif
1769#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 1808#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
1849 1888
1850/*****************************************************************************/ 1889/*****************************************************************************/
1851 1890
1852#ifndef EV_HAVE_EV_TIME 1891#ifndef EV_HAVE_EV_TIME
1853ev_tstamp 1892ev_tstamp
1854ev_time (void) EV_THROW 1893ev_time (void) EV_NOEXCEPT
1855{ 1894{
1856#if EV_USE_REALTIME 1895#if EV_USE_REALTIME
1857 if (expect_true (have_realtime)) 1896 if (expect_true (have_realtime))
1858 { 1897 {
1859 struct timespec ts; 1898 struct timespec ts;
1883 return ev_time (); 1922 return ev_time ();
1884} 1923}
1885 1924
1886#if EV_MULTIPLICITY 1925#if EV_MULTIPLICITY
1887ev_tstamp 1926ev_tstamp
1888ev_now (EV_P) EV_THROW 1927ev_now (EV_P) EV_NOEXCEPT
1889{ 1928{
1890 return ev_rt_now; 1929 return ev_rt_now;
1891} 1930}
1892#endif 1931#endif
1893 1932
1894void 1933void
1895ev_sleep (ev_tstamp delay) EV_THROW 1934ev_sleep (ev_tstamp delay) EV_NOEXCEPT
1896{ 1935{
1897 if (delay > 0.) 1936 if (delay > 0.)
1898 { 1937 {
1899#if EV_USE_NANOSLEEP 1938#if EV_USE_NANOSLEEP
1900 struct timespec ts; 1939 struct timespec ts;
1901 1940
1902 EV_TS_SET (ts, delay); 1941 EV_TS_SET (ts, delay);
1903 nanosleep (&ts, 0); 1942 nanosleep (&ts, 0);
1904#elif defined _WIN32 1943#elif defined _WIN32
1944 /* maybe this should round up, as ms is very low resolution */
1945 /* compared to select (µs) or nanosleep (ns) */
1905 Sleep ((unsigned long)(delay * 1e3)); 1946 Sleep ((unsigned long)(delay * 1e3));
1906#else 1947#else
1907 struct timeval tv; 1948 struct timeval tv;
1908 1949
1909 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ 1950 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
1940 } 1981 }
1941 1982
1942 return ncur; 1983 return ncur;
1943} 1984}
1944 1985
1945static void * noinline ecb_cold 1986noinline ecb_cold
1987static void *
1946array_realloc (int elem, void *base, int *cur, int cnt) 1988array_realloc (int elem, void *base, int *cur, int cnt)
1947{ 1989{
1948 *cur = array_nextsize (elem, *cur, cnt); 1990 *cur = array_nextsize (elem, *cur, cnt);
1949 return ev_realloc (base, elem * *cur); 1991 return ev_realloc (base, elem * *cur);
1950} 1992}
1951 1993
1994#define array_needsize_noinit(base,count)
1995
1952#define array_init_zero(base,count) \ 1996#define array_needsize_zerofill(base,count) \
1953 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1997 memset ((void *)(base), 0, sizeof (*(base)) * (count))
1954 1998
1955#define array_needsize(type,base,cur,cnt,init) \ 1999#define array_needsize(type,base,cur,cnt,init) \
1956 if (expect_false ((cnt) > (cur))) \ 2000 if (expect_false ((cnt) > (cur))) \
1957 { \ 2001 { \
1958 int ecb_unused ocur_ = (cur); \ 2002 ecb_unused int ocur_ = (cur); \
1959 (base) = (type *)array_realloc \ 2003 (base) = (type *)array_realloc \
1960 (sizeof (type), (base), &(cur), (cnt)); \ 2004 (sizeof (type), (base), &(cur), (cnt)); \
1961 init ((base) + (ocur_), (cur) - ocur_); \ 2005 init ((base) + (ocur_), (cur) - ocur_); \
1962 } 2006 }
1963 2007
1975 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 2019 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0
1976 2020
1977/*****************************************************************************/ 2021/*****************************************************************************/
1978 2022
1979/* dummy callback for pending events */ 2023/* dummy callback for pending events */
1980static void noinline 2024noinline
2025static void
1981pendingcb (EV_P_ ev_prepare *w, int revents) 2026pendingcb (EV_P_ ev_prepare *w, int revents)
1982{ 2027{
1983} 2028}
1984 2029
1985void noinline 2030noinline
2031void
1986ev_feed_event (EV_P_ void *w, int revents) EV_THROW 2032ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
1987{ 2033{
1988 W w_ = (W)w; 2034 W w_ = (W)w;
1989 int pri = ABSPRI (w_); 2035 int pri = ABSPRI (w_);
1990 2036
1991 if (expect_false (w_->pending)) 2037 if (expect_false (w_->pending))
1992 pendings [pri][w_->pending - 1].events |= revents; 2038 pendings [pri][w_->pending - 1].events |= revents;
1993 else 2039 else
1994 { 2040 {
1995 w_->pending = ++pendingcnt [pri]; 2041 w_->pending = ++pendingcnt [pri];
1996 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 2042 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
1997 pendings [pri][w_->pending - 1].w = w_; 2043 pendings [pri][w_->pending - 1].w = w_;
1998 pendings [pri][w_->pending - 1].events = revents; 2044 pendings [pri][w_->pending - 1].events = revents;
1999 } 2045 }
2000 2046
2001 pendingpri = NUMPRI - 1; 2047 pendingpri = NUMPRI - 1;
2002} 2048}
2003 2049
2004inline_speed void 2050inline_speed void
2005feed_reverse (EV_P_ W w) 2051feed_reverse (EV_P_ W w)
2006{ 2052{
2007 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); 2053 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit);
2008 rfeeds [rfeedcnt++] = w; 2054 rfeeds [rfeedcnt++] = w;
2009} 2055}
2010 2056
2011inline_size void 2057inline_size void
2012feed_reverse_done (EV_P_ int revents) 2058feed_reverse_done (EV_P_ int revents)
2052 if (expect_true (!anfd->reify)) 2098 if (expect_true (!anfd->reify))
2053 fd_event_nocheck (EV_A_ fd, revents); 2099 fd_event_nocheck (EV_A_ fd, revents);
2054} 2100}
2055 2101
2056void 2102void
2057ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW 2103ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2058{ 2104{
2059 if (fd >= 0 && fd < anfdmax) 2105 if (fd >= 0 && fd < anfdmax)
2060 fd_event_nocheck (EV_A_ fd, revents); 2106 fd_event_nocheck (EV_A_ fd, revents);
2061} 2107}
2062 2108
2120 2166
2121 fdchangecnt = 0; 2167 fdchangecnt = 0;
2122} 2168}
2123 2169
2124/* something about the given fd changed */ 2170/* something about the given fd changed */
2125inline_size void 2171inline_size
2172void
2126fd_change (EV_P_ int fd, int flags) 2173fd_change (EV_P_ int fd, int flags)
2127{ 2174{
2128 unsigned char reify = anfds [fd].reify; 2175 unsigned char reify = anfds [fd].reify;
2129 anfds [fd].reify |= flags; 2176 anfds [fd].reify |= flags;
2130 2177
2131 if (expect_true (!reify)) 2178 if (expect_true (!reify))
2132 { 2179 {
2133 ++fdchangecnt; 2180 ++fdchangecnt;
2134 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 2181 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2135 fdchanges [fdchangecnt - 1] = fd; 2182 fdchanges [fdchangecnt - 1] = fd;
2136 } 2183 }
2137} 2184}
2138 2185
2139/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 2186/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
2140inline_speed void ecb_cold 2187inline_speed ecb_cold void
2141fd_kill (EV_P_ int fd) 2188fd_kill (EV_P_ int fd)
2142{ 2189{
2143 ev_io *w; 2190 ev_io *w;
2144 2191
2145 while ((w = (ev_io *)anfds [fd].head)) 2192 while ((w = (ev_io *)anfds [fd].head))
2148 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 2195 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
2149 } 2196 }
2150} 2197}
2151 2198
2152/* check whether the given fd is actually valid, for error recovery */ 2199/* check whether the given fd is actually valid, for error recovery */
2153inline_size int ecb_cold 2200inline_size ecb_cold int
2154fd_valid (int fd) 2201fd_valid (int fd)
2155{ 2202{
2156#ifdef _WIN32 2203#ifdef _WIN32
2157 return EV_FD_TO_WIN32_HANDLE (fd) != -1; 2204 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
2158#else 2205#else
2159 return fcntl (fd, F_GETFD) != -1; 2206 return fcntl (fd, F_GETFD) != -1;
2160#endif 2207#endif
2161} 2208}
2162 2209
2163/* called on EBADF to verify fds */ 2210/* called on EBADF to verify fds */
2164static void noinline ecb_cold 2211noinline ecb_cold
2212static void
2165fd_ebadf (EV_P) 2213fd_ebadf (EV_P)
2166{ 2214{
2167 int fd; 2215 int fd;
2168 2216
2169 for (fd = 0; fd < anfdmax; ++fd) 2217 for (fd = 0; fd < anfdmax; ++fd)
2171 if (!fd_valid (fd) && errno == EBADF) 2219 if (!fd_valid (fd) && errno == EBADF)
2172 fd_kill (EV_A_ fd); 2220 fd_kill (EV_A_ fd);
2173} 2221}
2174 2222
2175/* called on ENOMEM in select/poll to kill some fds and retry */ 2223/* called on ENOMEM in select/poll to kill some fds and retry */
2176static void noinline ecb_cold 2224noinline ecb_cold
2225static void
2177fd_enomem (EV_P) 2226fd_enomem (EV_P)
2178{ 2227{
2179 int fd; 2228 int fd;
2180 2229
2181 for (fd = anfdmax; fd--; ) 2230 for (fd = anfdmax; fd--; )
2185 break; 2234 break;
2186 } 2235 }
2187} 2236}
2188 2237
2189/* usually called after fork if backend needs to re-arm all fds from scratch */ 2238/* usually called after fork if backend needs to re-arm all fds from scratch */
2190static void noinline 2239noinline
2240static void
2191fd_rearm_all (EV_P) 2241fd_rearm_all (EV_P)
2192{ 2242{
2193 int fd; 2243 int fd;
2194 2244
2195 for (fd = 0; fd < anfdmax; ++fd) 2245 for (fd = 0; fd < anfdmax; ++fd)
2376 2426
2377/*****************************************************************************/ 2427/*****************************************************************************/
2378 2428
2379#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2429#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2380 2430
2381static void noinline ecb_cold 2431noinline ecb_cold
2432static void
2382evpipe_init (EV_P) 2433evpipe_init (EV_P)
2383{ 2434{
2384 if (!ev_is_active (&pipe_w)) 2435 if (!ev_is_active (&pipe_w))
2385 { 2436 {
2386 int fds [2]; 2437 int fds [2];
2457#endif 2508#endif
2458 { 2509 {
2459#ifdef _WIN32 2510#ifdef _WIN32
2460 WSABUF buf; 2511 WSABUF buf;
2461 DWORD sent; 2512 DWORD sent;
2462 buf.buf = &buf; 2513 buf.buf = (char *)&buf;
2463 buf.len = 1; 2514 buf.len = 1;
2464 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); 2515 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
2465#else 2516#else
2466 write (evpipe [1], &(evpipe [1]), 1); 2517 write (evpipe [1], &(evpipe [1]), 1);
2467#endif 2518#endif
2539} 2590}
2540 2591
2541/*****************************************************************************/ 2592/*****************************************************************************/
2542 2593
2543void 2594void
2544ev_feed_signal (int signum) EV_THROW 2595ev_feed_signal (int signum) EV_NOEXCEPT
2545{ 2596{
2546#if EV_MULTIPLICITY 2597#if EV_MULTIPLICITY
2547 EV_P; 2598 EV_P;
2548 ECB_MEMORY_FENCE_ACQUIRE; 2599 ECB_MEMORY_FENCE_ACQUIRE;
2549 EV_A = signals [signum - 1].loop; 2600 EV_A = signals [signum - 1].loop;
2564#endif 2615#endif
2565 2616
2566 ev_feed_signal (signum); 2617 ev_feed_signal (signum);
2567} 2618}
2568 2619
2569void noinline 2620noinline
2621void
2570ev_feed_signal_event (EV_P_ int signum) EV_THROW 2622ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2571{ 2623{
2572 WL w; 2624 WL w;
2573 2625
2574 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2626 if (expect_false (signum <= 0 || signum >= EV_NSIG))
2575 return; 2627 return;
2684# include "ev_kqueue.c" 2736# include "ev_kqueue.c"
2685#endif 2737#endif
2686#if EV_USE_EPOLL 2738#if EV_USE_EPOLL
2687# include "ev_epoll.c" 2739# include "ev_epoll.c"
2688#endif 2740#endif
2741#if EV_USE_LINUXAIO
2742# include "ev_linuxaio.c"
2743#endif
2689#if EV_USE_POLL 2744#if EV_USE_POLL
2690# include "ev_poll.c" 2745# include "ev_poll.c"
2691#endif 2746#endif
2692#if EV_USE_SELECT 2747#if EV_USE_SELECT
2693# include "ev_select.c" 2748# include "ev_select.c"
2694#endif 2749#endif
2695 2750
2696int ecb_cold 2751ecb_cold int
2697ev_version_major (void) EV_THROW 2752ev_version_major (void) EV_NOEXCEPT
2698{ 2753{
2699 return EV_VERSION_MAJOR; 2754 return EV_VERSION_MAJOR;
2700} 2755}
2701 2756
2702int ecb_cold 2757ecb_cold int
2703ev_version_minor (void) EV_THROW 2758ev_version_minor (void) EV_NOEXCEPT
2704{ 2759{
2705 return EV_VERSION_MINOR; 2760 return EV_VERSION_MINOR;
2706} 2761}
2707 2762
2708/* return true if we are running with elevated privileges and should ignore env variables */ 2763/* return true if we are running with elevated privileges and should ignore env variables */
2709int inline_size ecb_cold 2764inline_size ecb_cold int
2710enable_secure (void) 2765enable_secure (void)
2711{ 2766{
2712#ifdef _WIN32 2767#ifdef _WIN32
2713 return 0; 2768 return 0;
2714#else 2769#else
2715 return getuid () != geteuid () 2770 return getuid () != geteuid ()
2716 || getgid () != getegid (); 2771 || getgid () != getegid ();
2717#endif 2772#endif
2718} 2773}
2719 2774
2720unsigned int ecb_cold 2775ecb_cold
2776unsigned int
2721ev_supported_backends (void) EV_THROW 2777ev_supported_backends (void) EV_NOEXCEPT
2722{ 2778{
2723 unsigned int flags = 0; 2779 unsigned int flags = 0;
2724 2780
2725 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2781 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2726 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2782 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2727 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 2783 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2784 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO;
2728 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 2785 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2729 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 2786 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2730 2787
2731 return flags; 2788 return flags;
2732} 2789}
2733 2790
2734unsigned int ecb_cold 2791ecb_cold
2792unsigned int
2735ev_recommended_backends (void) EV_THROW 2793ev_recommended_backends (void) EV_NOEXCEPT
2736{ 2794{
2737 unsigned int flags = ev_supported_backends (); 2795 unsigned int flags = ev_supported_backends ();
2738 2796
2739#ifndef __NetBSD__ 2797#ifndef __NetBSD__
2740 /* kqueue is borked on everything but netbsd apparently */ 2798 /* kqueue is borked on everything but netbsd apparently */
2748#endif 2806#endif
2749#ifdef __FreeBSD__ 2807#ifdef __FreeBSD__
2750 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ 2808 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
2751#endif 2809#endif
2752 2810
2811 /* TODO: linuxaio is very experimental */
2812#if !EV_RECOMMEND_LINUXAIO
2813 flags &= ~EVBACKEND_LINUXAIO;
2814#endif
2815
2753 return flags; 2816 return flags;
2754} 2817}
2755 2818
2756unsigned int ecb_cold 2819ecb_cold
2820unsigned int
2757ev_embeddable_backends (void) EV_THROW 2821ev_embeddable_backends (void) EV_NOEXCEPT
2758{ 2822{
2759 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2823 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2760 2824
2761 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2825 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2762 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2826 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2764 2828
2765 return flags; 2829 return flags;
2766} 2830}
2767 2831
2768unsigned int 2832unsigned int
2769ev_backend (EV_P) EV_THROW 2833ev_backend (EV_P) EV_NOEXCEPT
2770{ 2834{
2771 return backend; 2835 return backend;
2772} 2836}
2773 2837
2774#if EV_FEATURE_API 2838#if EV_FEATURE_API
2775unsigned int 2839unsigned int
2776ev_iteration (EV_P) EV_THROW 2840ev_iteration (EV_P) EV_NOEXCEPT
2777{ 2841{
2778 return loop_count; 2842 return loop_count;
2779} 2843}
2780 2844
2781unsigned int 2845unsigned int
2782ev_depth (EV_P) EV_THROW 2846ev_depth (EV_P) EV_NOEXCEPT
2783{ 2847{
2784 return loop_depth; 2848 return loop_depth;
2785} 2849}
2786 2850
2787void 2851void
2788ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2852ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2789{ 2853{
2790 io_blocktime = interval; 2854 io_blocktime = interval;
2791} 2855}
2792 2856
2793void 2857void
2794ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2858ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2795{ 2859{
2796 timeout_blocktime = interval; 2860 timeout_blocktime = interval;
2797} 2861}
2798 2862
2799void 2863void
2800ev_set_userdata (EV_P_ void *data) EV_THROW 2864ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT
2801{ 2865{
2802 userdata = data; 2866 userdata = data;
2803} 2867}
2804 2868
2805void * 2869void *
2806ev_userdata (EV_P) EV_THROW 2870ev_userdata (EV_P) EV_NOEXCEPT
2807{ 2871{
2808 return userdata; 2872 return userdata;
2809} 2873}
2810 2874
2811void 2875void
2812ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW 2876ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT
2813{ 2877{
2814 invoke_cb = invoke_pending_cb; 2878 invoke_cb = invoke_pending_cb;
2815} 2879}
2816 2880
2817void 2881void
2818ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW 2882ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT
2819{ 2883{
2820 release_cb = release; 2884 release_cb = release;
2821 acquire_cb = acquire; 2885 acquire_cb = acquire;
2822} 2886}
2823#endif 2887#endif
2824 2888
2825/* initialise a loop structure, must be zero-initialised */ 2889/* initialise a loop structure, must be zero-initialised */
2826static void noinline ecb_cold 2890noinline ecb_cold
2891static void
2827loop_init (EV_P_ unsigned int flags) EV_THROW 2892loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2828{ 2893{
2829 if (!backend) 2894 if (!backend)
2830 { 2895 {
2831 origflags = flags; 2896 origflags = flags;
2832 2897
2890 2955
2891 if (!(flags & EVBACKEND_MASK)) 2956 if (!(flags & EVBACKEND_MASK))
2892 flags |= ev_recommended_backends (); 2957 flags |= ev_recommended_backends ();
2893 2958
2894#if EV_USE_IOCP 2959#if EV_USE_IOCP
2895 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 2960 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
2896#endif 2961#endif
2897#if EV_USE_PORT 2962#if EV_USE_PORT
2898 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 2963 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
2899#endif 2964#endif
2900#if EV_USE_KQUEUE 2965#if EV_USE_KQUEUE
2901 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 2966 if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags);
2967#endif
2968#if EV_USE_LINUXAIO
2969 if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags);
2902#endif 2970#endif
2903#if EV_USE_EPOLL 2971#if EV_USE_EPOLL
2904 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); 2972 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
2905#endif 2973#endif
2906#if EV_USE_POLL 2974#if EV_USE_POLL
2907 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); 2975 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
2908#endif 2976#endif
2909#if EV_USE_SELECT 2977#if EV_USE_SELECT
2910 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 2978 if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags);
2911#endif 2979#endif
2912 2980
2913 ev_prepare_init (&pending_w, pendingcb); 2981 ev_prepare_init (&pending_w, pendingcb);
2914 2982
2915#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2983#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2918#endif 2986#endif
2919 } 2987 }
2920} 2988}
2921 2989
2922/* free up a loop structure */ 2990/* free up a loop structure */
2923void ecb_cold 2991ecb_cold
2992void
2924ev_loop_destroy (EV_P) 2993ev_loop_destroy (EV_P)
2925{ 2994{
2926 int i; 2995 int i;
2927 2996
2928#if EV_MULTIPLICITY 2997#if EV_MULTIPLICITY
2969 3038
2970 if (backend_fd >= 0) 3039 if (backend_fd >= 0)
2971 close (backend_fd); 3040 close (backend_fd);
2972 3041
2973#if EV_USE_IOCP 3042#if EV_USE_IOCP
2974 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); 3043 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
2975#endif 3044#endif
2976#if EV_USE_PORT 3045#if EV_USE_PORT
2977 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 3046 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
2978#endif 3047#endif
2979#if EV_USE_KQUEUE 3048#if EV_USE_KQUEUE
2980 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 3049 if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A);
3050#endif
3051#if EV_USE_LINUXAIO
3052 if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A);
2981#endif 3053#endif
2982#if EV_USE_EPOLL 3054#if EV_USE_EPOLL
2983 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 3055 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
2984#endif 3056#endif
2985#if EV_USE_POLL 3057#if EV_USE_POLL
2986 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); 3058 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
2987#endif 3059#endif
2988#if EV_USE_SELECT 3060#if EV_USE_SELECT
2989 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 3061 if (backend == EVBACKEND_SELECT ) select_destroy (EV_A);
2990#endif 3062#endif
2991 3063
2992 for (i = NUMPRI; i--; ) 3064 for (i = NUMPRI; i--; )
2993 { 3065 {
2994 array_free (pending, [i]); 3066 array_free (pending, [i]);
3036 3108
3037inline_size void 3109inline_size void
3038loop_fork (EV_P) 3110loop_fork (EV_P)
3039{ 3111{
3040#if EV_USE_PORT 3112#if EV_USE_PORT
3041 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 3113 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
3042#endif 3114#endif
3043#if EV_USE_KQUEUE 3115#if EV_USE_KQUEUE
3044 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 3116 if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A);
3117#endif
3118#if EV_USE_LINUXAIO
3119 if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A);
3045#endif 3120#endif
3046#if EV_USE_EPOLL 3121#if EV_USE_EPOLL
3047 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 3122 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
3048#endif 3123#endif
3049#if EV_USE_INOTIFY 3124#if EV_USE_INOTIFY
3050 infy_fork (EV_A); 3125 infy_fork (EV_A);
3051#endif 3126#endif
3052 3127
3070 postfork = 0; 3145 postfork = 0;
3071} 3146}
3072 3147
3073#if EV_MULTIPLICITY 3148#if EV_MULTIPLICITY
3074 3149
3150ecb_cold
3075struct ev_loop * ecb_cold 3151struct ev_loop *
3076ev_loop_new (unsigned int flags) EV_THROW 3152ev_loop_new (unsigned int flags) EV_NOEXCEPT
3077{ 3153{
3078 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 3154 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
3079 3155
3080 memset (EV_A, 0, sizeof (struct ev_loop)); 3156 memset (EV_A, 0, sizeof (struct ev_loop));
3081 loop_init (EV_A_ flags); 3157 loop_init (EV_A_ flags);
3088} 3164}
3089 3165
3090#endif /* multiplicity */ 3166#endif /* multiplicity */
3091 3167
3092#if EV_VERIFY 3168#if EV_VERIFY
3093static void noinline ecb_cold 3169noinline ecb_cold
3170static void
3094verify_watcher (EV_P_ W w) 3171verify_watcher (EV_P_ W w)
3095{ 3172{
3096 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 3173 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
3097 3174
3098 if (w->pending) 3175 if (w->pending)
3099 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 3176 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
3100} 3177}
3101 3178
3102static void noinline ecb_cold 3179noinline ecb_cold
3180static void
3103verify_heap (EV_P_ ANHE *heap, int N) 3181verify_heap (EV_P_ ANHE *heap, int N)
3104{ 3182{
3105 int i; 3183 int i;
3106 3184
3107 for (i = HEAP0; i < N + HEAP0; ++i) 3185 for (i = HEAP0; i < N + HEAP0; ++i)
3112 3190
3113 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3191 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3114 } 3192 }
3115} 3193}
3116 3194
3117static void noinline ecb_cold 3195noinline ecb_cold
3196static void
3118array_verify (EV_P_ W *ws, int cnt) 3197array_verify (EV_P_ W *ws, int cnt)
3119{ 3198{
3120 while (cnt--) 3199 while (cnt--)
3121 { 3200 {
3122 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 3201 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1));
3125} 3204}
3126#endif 3205#endif
3127 3206
3128#if EV_FEATURE_API 3207#if EV_FEATURE_API
3129void ecb_cold 3208void ecb_cold
3130ev_verify (EV_P) EV_THROW 3209ev_verify (EV_P) EV_NOEXCEPT
3131{ 3210{
3132#if EV_VERIFY 3211#if EV_VERIFY
3133 int i; 3212 int i;
3134 WL w, w2; 3213 WL w, w2;
3135 3214
3211#endif 3290#endif
3212} 3291}
3213#endif 3292#endif
3214 3293
3215#if EV_MULTIPLICITY 3294#if EV_MULTIPLICITY
3295ecb_cold
3216struct ev_loop * ecb_cold 3296struct ev_loop *
3217#else 3297#else
3218int 3298int
3219#endif 3299#endif
3220ev_default_loop (unsigned int flags) EV_THROW 3300ev_default_loop (unsigned int flags) EV_NOEXCEPT
3221{ 3301{
3222 if (!ev_default_loop_ptr) 3302 if (!ev_default_loop_ptr)
3223 { 3303 {
3224#if EV_MULTIPLICITY 3304#if EV_MULTIPLICITY
3225 EV_P = ev_default_loop_ptr = &default_loop_struct; 3305 EV_P = ev_default_loop_ptr = &default_loop_struct;
3244 3324
3245 return ev_default_loop_ptr; 3325 return ev_default_loop_ptr;
3246} 3326}
3247 3327
3248void 3328void
3249ev_loop_fork (EV_P) EV_THROW 3329ev_loop_fork (EV_P) EV_NOEXCEPT
3250{ 3330{
3251 postfork = 1; 3331 postfork = 1;
3252} 3332}
3253 3333
3254/*****************************************************************************/ 3334/*****************************************************************************/
3258{ 3338{
3259 EV_CB_INVOKE ((W)w, revents); 3339 EV_CB_INVOKE ((W)w, revents);
3260} 3340}
3261 3341
3262unsigned int 3342unsigned int
3263ev_pending_count (EV_P) EV_THROW 3343ev_pending_count (EV_P) EV_NOEXCEPT
3264{ 3344{
3265 int pri; 3345 int pri;
3266 unsigned int count = 0; 3346 unsigned int count = 0;
3267 3347
3268 for (pri = NUMPRI; pri--; ) 3348 for (pri = NUMPRI; pri--; )
3269 count += pendingcnt [pri]; 3349 count += pendingcnt [pri];
3270 3350
3271 return count; 3351 return count;
3272} 3352}
3273 3353
3274void noinline 3354noinline
3355void
3275ev_invoke_pending (EV_P) 3356ev_invoke_pending (EV_P)
3276{ 3357{
3277 pendingpri = NUMPRI; 3358 pendingpri = NUMPRI;
3278 3359
3279 while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ 3360 do
3280 { 3361 {
3281 --pendingpri; 3362 --pendingpri;
3282 3363
3364 /* pendingpri possibly gets modified in the inner loop */
3283 while (pendingcnt [pendingpri]) 3365 while (pendingcnt [pendingpri])
3284 { 3366 {
3285 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; 3367 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
3286 3368
3287 p->w->pending = 0; 3369 p->w->pending = 0;
3288 EV_CB_INVOKE (p->w, p->events); 3370 EV_CB_INVOKE (p->w, p->events);
3289 EV_FREQUENT_CHECK; 3371 EV_FREQUENT_CHECK;
3290 } 3372 }
3291 } 3373 }
3374 while (pendingpri);
3292} 3375}
3293 3376
3294#if EV_IDLE_ENABLE 3377#if EV_IDLE_ENABLE
3295/* make idle watchers pending. this handles the "call-idle */ 3378/* make idle watchers pending. this handles the "call-idle */
3296/* only when higher priorities are idle" logic */ 3379/* only when higher priorities are idle" logic */
3354 } 3437 }
3355} 3438}
3356 3439
3357#if EV_PERIODIC_ENABLE 3440#if EV_PERIODIC_ENABLE
3358 3441
3359static void noinline 3442noinline
3443static void
3360periodic_recalc (EV_P_ ev_periodic *w) 3444periodic_recalc (EV_P_ ev_periodic *w)
3361{ 3445{
3362 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3446 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL;
3363 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); 3447 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval);
3364 3448
3422 } 3506 }
3423} 3507}
3424 3508
3425/* simply recalculate all periodics */ 3509/* simply recalculate all periodics */
3426/* TODO: maybe ensure that at least one event happens when jumping forward? */ 3510/* TODO: maybe ensure that at least one event happens when jumping forward? */
3427static void noinline ecb_cold 3511noinline ecb_cold
3512static void
3428periodics_reschedule (EV_P) 3513periodics_reschedule (EV_P)
3429{ 3514{
3430 int i; 3515 int i;
3431 3516
3432 /* adjust periodics after time jump */ 3517 /* adjust periodics after time jump */
3445 reheap (periodics, periodiccnt); 3530 reheap (periodics, periodiccnt);
3446} 3531}
3447#endif 3532#endif
3448 3533
3449/* adjust all timers by a given offset */ 3534/* adjust all timers by a given offset */
3450static void noinline ecb_cold 3535noinline ecb_cold
3536static void
3451timers_reschedule (EV_P_ ev_tstamp adjust) 3537timers_reschedule (EV_P_ ev_tstamp adjust)
3452{ 3538{
3453 int i; 3539 int i;
3454 3540
3455 for (i = 0; i < timercnt; ++i) 3541 for (i = 0; i < timercnt; ++i)
3702 3788
3703 return activecnt; 3789 return activecnt;
3704} 3790}
3705 3791
3706void 3792void
3707ev_break (EV_P_ int how) EV_THROW 3793ev_break (EV_P_ int how) EV_NOEXCEPT
3708{ 3794{
3709 loop_done = how; 3795 loop_done = how;
3710} 3796}
3711 3797
3712void 3798void
3713ev_ref (EV_P) EV_THROW 3799ev_ref (EV_P) EV_NOEXCEPT
3714{ 3800{
3715 ++activecnt; 3801 ++activecnt;
3716} 3802}
3717 3803
3718void 3804void
3719ev_unref (EV_P) EV_THROW 3805ev_unref (EV_P) EV_NOEXCEPT
3720{ 3806{
3721 --activecnt; 3807 --activecnt;
3722} 3808}
3723 3809
3724void 3810void
3725ev_now_update (EV_P) EV_THROW 3811ev_now_update (EV_P) EV_NOEXCEPT
3726{ 3812{
3727 time_update (EV_A_ 1e100); 3813 time_update (EV_A_ 1e100);
3728} 3814}
3729 3815
3730void 3816void
3731ev_suspend (EV_P) EV_THROW 3817ev_suspend (EV_P) EV_NOEXCEPT
3732{ 3818{
3733 ev_now_update (EV_A); 3819 ev_now_update (EV_A);
3734} 3820}
3735 3821
3736void 3822void
3737ev_resume (EV_P) EV_THROW 3823ev_resume (EV_P) EV_NOEXCEPT
3738{ 3824{
3739 ev_tstamp mn_prev = mn_now; 3825 ev_tstamp mn_prev = mn_now;
3740 3826
3741 ev_now_update (EV_A); 3827 ev_now_update (EV_A);
3742 timers_reschedule (EV_A_ mn_now - mn_prev); 3828 timers_reschedule (EV_A_ mn_now - mn_prev);
3781 w->pending = 0; 3867 w->pending = 0;
3782 } 3868 }
3783} 3869}
3784 3870
3785int 3871int
3786ev_clear_pending (EV_P_ void *w) EV_THROW 3872ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3787{ 3873{
3788 W w_ = (W)w; 3874 W w_ = (W)w;
3789 int pending = w_->pending; 3875 int pending = w_->pending;
3790 3876
3791 if (expect_true (pending)) 3877 if (expect_true (pending))
3823 w->active = 0; 3909 w->active = 0;
3824} 3910}
3825 3911
3826/*****************************************************************************/ 3912/*****************************************************************************/
3827 3913
3828void noinline 3914noinline
3915void
3829ev_io_start (EV_P_ ev_io *w) EV_THROW 3916ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3830{ 3917{
3831 int fd = w->fd; 3918 int fd = w->fd;
3832 3919
3833 if (expect_false (ev_is_active (w))) 3920 if (expect_false (ev_is_active (w)))
3834 return; 3921 return;
3837 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3924 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3838 3925
3839 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3840 3927
3841 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3842 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3843 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3844 3931
3845 /* common bug, apparently */ 3932 /* common bug, apparently */
3846 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3933 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3847 3934
3849 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3850 3937
3851 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3852} 3939}
3853 3940
3854void noinline 3941noinline
3942void
3855ev_io_stop (EV_P_ ev_io *w) EV_THROW 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3856{ 3944{
3857 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3858 if (expect_false (!ev_is_active (w))) 3946 if (expect_false (!ev_is_active (w)))
3859 return; 3947 return;
3860 3948
3868 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3956 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3869 3957
3870 EV_FREQUENT_CHECK; 3958 EV_FREQUENT_CHECK;
3871} 3959}
3872 3960
3873void noinline 3961noinline
3962void
3874ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3963ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3875{ 3964{
3876 if (expect_false (ev_is_active (w))) 3965 if (expect_false (ev_is_active (w)))
3877 return; 3966 return;
3878 3967
3879 ev_at (w) += mn_now; 3968 ev_at (w) += mn_now;
3882 3971
3883 EV_FREQUENT_CHECK; 3972 EV_FREQUENT_CHECK;
3884 3973
3885 ++timercnt; 3974 ++timercnt;
3886 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3975 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3887 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3976 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3888 ANHE_w (timers [ev_active (w)]) = (WT)w; 3977 ANHE_w (timers [ev_active (w)]) = (WT)w;
3889 ANHE_at_cache (timers [ev_active (w)]); 3978 ANHE_at_cache (timers [ev_active (w)]);
3890 upheap (timers, ev_active (w)); 3979 upheap (timers, ev_active (w));
3891 3980
3892 EV_FREQUENT_CHECK; 3981 EV_FREQUENT_CHECK;
3893 3982
3894 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3983 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3895} 3984}
3896 3985
3897void noinline 3986noinline
3987void
3898ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3988ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3899{ 3989{
3900 clear_pending (EV_A_ (W)w); 3990 clear_pending (EV_A_ (W)w);
3901 if (expect_false (!ev_is_active (w))) 3991 if (expect_false (!ev_is_active (w)))
3902 return; 3992 return;
3903 3993
3922 ev_stop (EV_A_ (W)w); 4012 ev_stop (EV_A_ (W)w);
3923 4013
3924 EV_FREQUENT_CHECK; 4014 EV_FREQUENT_CHECK;
3925} 4015}
3926 4016
3927void noinline 4017noinline
4018void
3928ev_timer_again (EV_P_ ev_timer *w) EV_THROW 4019ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3929{ 4020{
3930 EV_FREQUENT_CHECK; 4021 EV_FREQUENT_CHECK;
3931 4022
3932 clear_pending (EV_A_ (W)w); 4023 clear_pending (EV_A_ (W)w);
3933 4024
3950 4041
3951 EV_FREQUENT_CHECK; 4042 EV_FREQUENT_CHECK;
3952} 4043}
3953 4044
3954ev_tstamp 4045ev_tstamp
3955ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 4046ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3956{ 4047{
3957 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4048 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3958} 4049}
3959 4050
3960#if EV_PERIODIC_ENABLE 4051#if EV_PERIODIC_ENABLE
3961void noinline 4052noinline
4053void
3962ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4054ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
3963{ 4055{
3964 if (expect_false (ev_is_active (w))) 4056 if (expect_false (ev_is_active (w)))
3965 return; 4057 return;
3966 4058
3967 if (w->reschedule_cb) 4059 if (w->reschedule_cb)
3976 4068
3977 EV_FREQUENT_CHECK; 4069 EV_FREQUENT_CHECK;
3978 4070
3979 ++periodiccnt; 4071 ++periodiccnt;
3980 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4072 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
3981 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4073 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
3982 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4074 ANHE_w (periodics [ev_active (w)]) = (WT)w;
3983 ANHE_at_cache (periodics [ev_active (w)]); 4075 ANHE_at_cache (periodics [ev_active (w)]);
3984 upheap (periodics, ev_active (w)); 4076 upheap (periodics, ev_active (w));
3985 4077
3986 EV_FREQUENT_CHECK; 4078 EV_FREQUENT_CHECK;
3987 4079
3988 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4080 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3989} 4081}
3990 4082
3991void noinline 4083noinline
4084void
3992ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4085ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
3993{ 4086{
3994 clear_pending (EV_A_ (W)w); 4087 clear_pending (EV_A_ (W)w);
3995 if (expect_false (!ev_is_active (w))) 4088 if (expect_false (!ev_is_active (w)))
3996 return; 4089 return;
3997 4090
4014 ev_stop (EV_A_ (W)w); 4107 ev_stop (EV_A_ (W)w);
4015 4108
4016 EV_FREQUENT_CHECK; 4109 EV_FREQUENT_CHECK;
4017} 4110}
4018 4111
4019void noinline 4112noinline
4113void
4020ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4114ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4021{ 4115{
4022 /* TODO: use adjustheap and recalculation */ 4116 /* TODO: use adjustheap and recalculation */
4023 ev_periodic_stop (EV_A_ w); 4117 ev_periodic_stop (EV_A_ w);
4024 ev_periodic_start (EV_A_ w); 4118 ev_periodic_start (EV_A_ w);
4025} 4119}
4029# define SA_RESTART 0 4123# define SA_RESTART 0
4030#endif 4124#endif
4031 4125
4032#if EV_SIGNAL_ENABLE 4126#if EV_SIGNAL_ENABLE
4033 4127
4034void noinline 4128noinline
4129void
4035ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4130ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4036{ 4131{
4037 if (expect_false (ev_is_active (w))) 4132 if (expect_false (ev_is_active (w)))
4038 return; 4133 return;
4039 4134
4040 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4135 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4111 } 4206 }
4112 4207
4113 EV_FREQUENT_CHECK; 4208 EV_FREQUENT_CHECK;
4114} 4209}
4115 4210
4116void noinline 4211noinline
4212void
4117ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4213ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4118{ 4214{
4119 clear_pending (EV_A_ (W)w); 4215 clear_pending (EV_A_ (W)w);
4120 if (expect_false (!ev_is_active (w))) 4216 if (expect_false (!ev_is_active (w)))
4121 return; 4217 return;
4122 4218
4153#endif 4249#endif
4154 4250
4155#if EV_CHILD_ENABLE 4251#if EV_CHILD_ENABLE
4156 4252
4157void 4253void
4158ev_child_start (EV_P_ ev_child *w) EV_THROW 4254ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4159{ 4255{
4160#if EV_MULTIPLICITY 4256#if EV_MULTIPLICITY
4161 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4257 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4162#endif 4258#endif
4163 if (expect_false (ev_is_active (w))) 4259 if (expect_false (ev_is_active (w)))
4170 4266
4171 EV_FREQUENT_CHECK; 4267 EV_FREQUENT_CHECK;
4172} 4268}
4173 4269
4174void 4270void
4175ev_child_stop (EV_P_ ev_child *w) EV_THROW 4271ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4176{ 4272{
4177 clear_pending (EV_A_ (W)w); 4273 clear_pending (EV_A_ (W)w);
4178 if (expect_false (!ev_is_active (w))) 4274 if (expect_false (!ev_is_active (w)))
4179 return; 4275 return;
4180 4276
4197 4293
4198#define DEF_STAT_INTERVAL 5.0074891 4294#define DEF_STAT_INTERVAL 5.0074891
4199#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4295#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4200#define MIN_STAT_INTERVAL 0.1074891 4296#define MIN_STAT_INTERVAL 0.1074891
4201 4297
4202static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4298noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4203 4299
4204#if EV_USE_INOTIFY 4300#if EV_USE_INOTIFY
4205 4301
4206/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4302/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */
4207# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4303# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4208 4304
4209static void noinline 4305noinline
4306static void
4210infy_add (EV_P_ ev_stat *w) 4307infy_add (EV_P_ ev_stat *w)
4211{ 4308{
4212 w->wd = inotify_add_watch (fs_fd, w->path, 4309 w->wd = inotify_add_watch (fs_fd, w->path,
4213 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4310 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4214 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO 4311 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
4278 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4375 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4279 ev_timer_again (EV_A_ &w->timer); 4376 ev_timer_again (EV_A_ &w->timer);
4280 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4377 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4281} 4378}
4282 4379
4283static void noinline 4380noinline
4381static void
4284infy_del (EV_P_ ev_stat *w) 4382infy_del (EV_P_ ev_stat *w)
4285{ 4383{
4286 int slot; 4384 int slot;
4287 int wd = w->wd; 4385 int wd = w->wd;
4288 4386
4295 4393
4296 /* remove this watcher, if others are watching it, they will rearm */ 4394 /* remove this watcher, if others are watching it, they will rearm */
4297 inotify_rm_watch (fs_fd, wd); 4395 inotify_rm_watch (fs_fd, wd);
4298} 4396}
4299 4397
4300static void noinline 4398noinline
4399static void
4301infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4400infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4302{ 4401{
4303 if (slot < 0) 4402 if (slot < 0)
4304 /* overflow, need to check for all hash slots */ 4403 /* overflow, need to check for all hash slots */
4305 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) 4404 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
4341 infy_wd (EV_A_ ev->wd, ev->wd, ev); 4440 infy_wd (EV_A_ ev->wd, ev->wd, ev);
4342 ofs += sizeof (struct inotify_event) + ev->len; 4441 ofs += sizeof (struct inotify_event) + ev->len;
4343 } 4442 }
4344} 4443}
4345 4444
4346inline_size void ecb_cold 4445inline_size ecb_cold
4446void
4347ev_check_2625 (EV_P) 4447ev_check_2625 (EV_P)
4348{ 4448{
4349 /* kernels < 2.6.25 are borked 4449 /* kernels < 2.6.25 are borked
4350 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 4450 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
4351 */ 4451 */
4441#else 4541#else
4442# define EV_LSTAT(p,b) lstat (p, b) 4542# define EV_LSTAT(p,b) lstat (p, b)
4443#endif 4543#endif
4444 4544
4445void 4545void
4446ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4546ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4447{ 4547{
4448 if (lstat (w->path, &w->attr) < 0) 4548 if (lstat (w->path, &w->attr) < 0)
4449 w->attr.st_nlink = 0; 4549 w->attr.st_nlink = 0;
4450 else if (!w->attr.st_nlink) 4550 else if (!w->attr.st_nlink)
4451 w->attr.st_nlink = 1; 4551 w->attr.st_nlink = 1;
4452} 4552}
4453 4553
4454static void noinline 4554noinline
4555static void
4455stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4556stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4456{ 4557{
4457 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4558 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4458 4559
4459 ev_statdata prev = w->attr; 4560 ev_statdata prev = w->attr;
4490 ev_feed_event (EV_A_ w, EV_STAT); 4591 ev_feed_event (EV_A_ w, EV_STAT);
4491 } 4592 }
4492} 4593}
4493 4594
4494void 4595void
4495ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4596ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4496{ 4597{
4497 if (expect_false (ev_is_active (w))) 4598 if (expect_false (ev_is_active (w)))
4498 return; 4599 return;
4499 4600
4500 ev_stat_stat (EV_A_ w); 4601 ev_stat_stat (EV_A_ w);
4521 4622
4522 EV_FREQUENT_CHECK; 4623 EV_FREQUENT_CHECK;
4523} 4624}
4524 4625
4525void 4626void
4526ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4627ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4527{ 4628{
4528 clear_pending (EV_A_ (W)w); 4629 clear_pending (EV_A_ (W)w);
4529 if (expect_false (!ev_is_active (w))) 4630 if (expect_false (!ev_is_active (w)))
4530 return; 4631 return;
4531 4632
4547} 4648}
4548#endif 4649#endif
4549 4650
4550#if EV_IDLE_ENABLE 4651#if EV_IDLE_ENABLE
4551void 4652void
4552ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4653ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4553{ 4654{
4554 if (expect_false (ev_is_active (w))) 4655 if (expect_false (ev_is_active (w)))
4555 return; 4656 return;
4556 4657
4557 pri_adjust (EV_A_ (W)w); 4658 pri_adjust (EV_A_ (W)w);
4562 int active = ++idlecnt [ABSPRI (w)]; 4663 int active = ++idlecnt [ABSPRI (w)];
4563 4664
4564 ++idleall; 4665 ++idleall;
4565 ev_start (EV_A_ (W)w, active); 4666 ev_start (EV_A_ (W)w, active);
4566 4667
4567 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4668 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4568 idles [ABSPRI (w)][active - 1] = w; 4669 idles [ABSPRI (w)][active - 1] = w;
4569 } 4670 }
4570 4671
4571 EV_FREQUENT_CHECK; 4672 EV_FREQUENT_CHECK;
4572} 4673}
4573 4674
4574void 4675void
4575ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4676ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4576{ 4677{
4577 clear_pending (EV_A_ (W)w); 4678 clear_pending (EV_A_ (W)w);
4578 if (expect_false (!ev_is_active (w))) 4679 if (expect_false (!ev_is_active (w)))
4579 return; 4680 return;
4580 4681
4594} 4695}
4595#endif 4696#endif
4596 4697
4597#if EV_PREPARE_ENABLE 4698#if EV_PREPARE_ENABLE
4598void 4699void
4599ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4700ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4600{ 4701{
4601 if (expect_false (ev_is_active (w))) 4702 if (expect_false (ev_is_active (w)))
4602 return; 4703 return;
4603 4704
4604 EV_FREQUENT_CHECK; 4705 EV_FREQUENT_CHECK;
4605 4706
4606 ev_start (EV_A_ (W)w, ++preparecnt); 4707 ev_start (EV_A_ (W)w, ++preparecnt);
4607 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4708 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4608 prepares [preparecnt - 1] = w; 4709 prepares [preparecnt - 1] = w;
4609 4710
4610 EV_FREQUENT_CHECK; 4711 EV_FREQUENT_CHECK;
4611} 4712}
4612 4713
4613void 4714void
4614ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4715ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4615{ 4716{
4616 clear_pending (EV_A_ (W)w); 4717 clear_pending (EV_A_ (W)w);
4617 if (expect_false (!ev_is_active (w))) 4718 if (expect_false (!ev_is_active (w)))
4618 return; 4719 return;
4619 4720
4632} 4733}
4633#endif 4734#endif
4634 4735
4635#if EV_CHECK_ENABLE 4736#if EV_CHECK_ENABLE
4636void 4737void
4637ev_check_start (EV_P_ ev_check *w) EV_THROW 4738ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4638{ 4739{
4639 if (expect_false (ev_is_active (w))) 4740 if (expect_false (ev_is_active (w)))
4640 return; 4741 return;
4641 4742
4642 EV_FREQUENT_CHECK; 4743 EV_FREQUENT_CHECK;
4643 4744
4644 ev_start (EV_A_ (W)w, ++checkcnt); 4745 ev_start (EV_A_ (W)w, ++checkcnt);
4645 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4746 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4646 checks [checkcnt - 1] = w; 4747 checks [checkcnt - 1] = w;
4647 4748
4648 EV_FREQUENT_CHECK; 4749 EV_FREQUENT_CHECK;
4649} 4750}
4650 4751
4651void 4752void
4652ev_check_stop (EV_P_ ev_check *w) EV_THROW 4753ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4653{ 4754{
4654 clear_pending (EV_A_ (W)w); 4755 clear_pending (EV_A_ (W)w);
4655 if (expect_false (!ev_is_active (w))) 4756 if (expect_false (!ev_is_active (w)))
4656 return; 4757 return;
4657 4758
4669 EV_FREQUENT_CHECK; 4770 EV_FREQUENT_CHECK;
4670} 4771}
4671#endif 4772#endif
4672 4773
4673#if EV_EMBED_ENABLE 4774#if EV_EMBED_ENABLE
4674void noinline 4775noinline
4776void
4675ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4777ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4676{ 4778{
4677 ev_run (w->other, EVRUN_NOWAIT); 4779 ev_run (w->other, EVRUN_NOWAIT);
4678} 4780}
4679 4781
4680static void 4782static void
4728 ev_idle_stop (EV_A_ idle); 4830 ev_idle_stop (EV_A_ idle);
4729} 4831}
4730#endif 4832#endif
4731 4833
4732void 4834void
4733ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4835ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4734{ 4836{
4735 if (expect_false (ev_is_active (w))) 4837 if (expect_false (ev_is_active (w)))
4736 return; 4838 return;
4737 4839
4738 { 4840 {
4759 4861
4760 EV_FREQUENT_CHECK; 4862 EV_FREQUENT_CHECK;
4761} 4863}
4762 4864
4763void 4865void
4764ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4866ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4765{ 4867{
4766 clear_pending (EV_A_ (W)w); 4868 clear_pending (EV_A_ (W)w);
4767 if (expect_false (!ev_is_active (w))) 4869 if (expect_false (!ev_is_active (w)))
4768 return; 4870 return;
4769 4871
4779} 4881}
4780#endif 4882#endif
4781 4883
4782#if EV_FORK_ENABLE 4884#if EV_FORK_ENABLE
4783void 4885void
4784ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4886ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4785{ 4887{
4786 if (expect_false (ev_is_active (w))) 4888 if (expect_false (ev_is_active (w)))
4787 return; 4889 return;
4788 4890
4789 EV_FREQUENT_CHECK; 4891 EV_FREQUENT_CHECK;
4790 4892
4791 ev_start (EV_A_ (W)w, ++forkcnt); 4893 ev_start (EV_A_ (W)w, ++forkcnt);
4792 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4894 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4793 forks [forkcnt - 1] = w; 4895 forks [forkcnt - 1] = w;
4794 4896
4795 EV_FREQUENT_CHECK; 4897 EV_FREQUENT_CHECK;
4796} 4898}
4797 4899
4798void 4900void
4799ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4901ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4800{ 4902{
4801 clear_pending (EV_A_ (W)w); 4903 clear_pending (EV_A_ (W)w);
4802 if (expect_false (!ev_is_active (w))) 4904 if (expect_false (!ev_is_active (w)))
4803 return; 4905 return;
4804 4906
4817} 4919}
4818#endif 4920#endif
4819 4921
4820#if EV_CLEANUP_ENABLE 4922#if EV_CLEANUP_ENABLE
4821void 4923void
4822ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4924ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4823{ 4925{
4824 if (expect_false (ev_is_active (w))) 4926 if (expect_false (ev_is_active (w)))
4825 return; 4927 return;
4826 4928
4827 EV_FREQUENT_CHECK; 4929 EV_FREQUENT_CHECK;
4828 4930
4829 ev_start (EV_A_ (W)w, ++cleanupcnt); 4931 ev_start (EV_A_ (W)w, ++cleanupcnt);
4830 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4932 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4831 cleanups [cleanupcnt - 1] = w; 4933 cleanups [cleanupcnt - 1] = w;
4832 4934
4833 /* cleanup watchers should never keep a refcount on the loop */ 4935 /* cleanup watchers should never keep a refcount on the loop */
4834 ev_unref (EV_A); 4936 ev_unref (EV_A);
4835 EV_FREQUENT_CHECK; 4937 EV_FREQUENT_CHECK;
4836} 4938}
4837 4939
4838void 4940void
4839ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4941ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4840{ 4942{
4841 clear_pending (EV_A_ (W)w); 4943 clear_pending (EV_A_ (W)w);
4842 if (expect_false (!ev_is_active (w))) 4944 if (expect_false (!ev_is_active (w)))
4843 return; 4945 return;
4844 4946
4858} 4960}
4859#endif 4961#endif
4860 4962
4861#if EV_ASYNC_ENABLE 4963#if EV_ASYNC_ENABLE
4862void 4964void
4863ev_async_start (EV_P_ ev_async *w) EV_THROW 4965ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4864{ 4966{
4865 if (expect_false (ev_is_active (w))) 4967 if (expect_false (ev_is_active (w)))
4866 return; 4968 return;
4867 4969
4868 w->sent = 0; 4970 w->sent = 0;
4870 evpipe_init (EV_A); 4972 evpipe_init (EV_A);
4871 4973
4872 EV_FREQUENT_CHECK; 4974 EV_FREQUENT_CHECK;
4873 4975
4874 ev_start (EV_A_ (W)w, ++asynccnt); 4976 ev_start (EV_A_ (W)w, ++asynccnt);
4875 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4977 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4876 asyncs [asynccnt - 1] = w; 4978 asyncs [asynccnt - 1] = w;
4877 4979
4878 EV_FREQUENT_CHECK; 4980 EV_FREQUENT_CHECK;
4879} 4981}
4880 4982
4881void 4983void
4882ev_async_stop (EV_P_ ev_async *w) EV_THROW 4984ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4883{ 4985{
4884 clear_pending (EV_A_ (W)w); 4986 clear_pending (EV_A_ (W)w);
4885 if (expect_false (!ev_is_active (w))) 4987 if (expect_false (!ev_is_active (w)))
4886 return; 4988 return;
4887 4989
4898 5000
4899 EV_FREQUENT_CHECK; 5001 EV_FREQUENT_CHECK;
4900} 5002}
4901 5003
4902void 5004void
4903ev_async_send (EV_P_ ev_async *w) EV_THROW 5005ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4904{ 5006{
4905 w->sent = 1; 5007 w->sent = 1;
4906 evpipe_write (EV_A_ &async_pending); 5008 evpipe_write (EV_A_ &async_pending);
4907} 5009}
4908#endif 5010#endif
4945 5047
4946 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5048 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4947} 5049}
4948 5050
4949void 5051void
4950ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5052ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
4951{ 5053{
4952 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5054 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4953
4954 if (expect_false (!once))
4955 {
4956 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
4957 return;
4958 }
4959 5055
4960 once->cb = cb; 5056 once->cb = cb;
4961 once->arg = arg; 5057 once->arg = arg;
4962 5058
4963 ev_init (&once->io, once_cb_io); 5059 ev_init (&once->io, once_cb_io);
4976} 5072}
4977 5073
4978/*****************************************************************************/ 5074/*****************************************************************************/
4979 5075
4980#if EV_WALK_ENABLE 5076#if EV_WALK_ENABLE
4981void ecb_cold 5077ecb_cold
5078void
4982ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5079ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
4983{ 5080{
4984 int i, j; 5081 int i, j;
4985 ev_watcher_list *wl, *wn; 5082 ev_watcher_list *wl, *wn;
4986 5083
4987 if (types & (EV_IO | EV_EMBED)) 5084 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines