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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines