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

Comparing libev/ev.c (file contents):
Revision 1.488 by root, Fri Dec 21 06:57:09 2018 UTC vs.
Revision 1.500 by root, Mon Jul 1 20:47:37 2019 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007-2018 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
115# else 115# else
116# undef EV_USE_EPOLL 116# undef EV_USE_EPOLL
117# define EV_USE_EPOLL 0 117# define EV_USE_EPOLL 0
118# endif 118# endif
119 119
120# if HAVE_LINUX_AIO_ABI_H
121# ifndef EV_USE_LINUXAIO
122# define EV_USE_LINUXAIO EV_FEATURE_BACKENDS
123# endif
124# else
125# undef EV_USE_LINUXAIO
126# define EV_USE_LINUXAIO 0
127# endif
128
120# if HAVE_KQUEUE && HAVE_SYS_EVENT_H 129# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
121# ifndef EV_USE_KQUEUE 130# ifndef EV_USE_KQUEUE
122# define EV_USE_KQUEUE EV_FEATURE_BACKENDS 131# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
123# endif 132# endif
124# else 133# else
315 324
316#ifndef EV_USE_PORT 325#ifndef EV_USE_PORT
317# define EV_USE_PORT 0 326# define EV_USE_PORT 0
318#endif 327#endif
319 328
329#ifndef EV_USE_LINUXAIO
330# if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */
331# define EV_USE_LINUXAIO 1
332# else
333# define EV_USE_LINUXAIO 0
334# endif
335#endif
336
320#ifndef EV_USE_INOTIFY 337#ifndef EV_USE_INOTIFY
321# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 338# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
322# define EV_USE_INOTIFY EV_FEATURE_OS 339# define EV_USE_INOTIFY EV_FEATURE_OS
323# else 340# else
324# define EV_USE_INOTIFY 0 341# define EV_USE_INOTIFY 0
416 433
417#if !EV_USE_NANOSLEEP 434#if !EV_USE_NANOSLEEP
418/* hp-ux has it in sys/time.h, which we unconditionally include above */ 435/* hp-ux has it in sys/time.h, which we unconditionally include above */
419# if !defined _WIN32 && !defined __hpux 436# if !defined _WIN32 && !defined __hpux
420# include <sys/select.h> 437# include <sys/select.h>
438# endif
439#endif
440
441#if EV_USE_LINUXAIO
442# include <sys/syscall.h>
443# if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */
444# undef EV_USE_LINUXAIO
445# define EV_USE_LINUXAIO 0
421# endif 446# endif
422#endif 447#endif
423 448
424#if EV_USE_INOTIFY 449#if EV_USE_INOTIFY
425# include <sys/statfs.h> 450# include <sys/statfs.h>
534 559
535#ifndef ECB_H 560#ifndef ECB_H
536#define ECB_H 561#define ECB_H
537 562
538/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
539#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
540 565
541#ifdef _WIN32 566#ifdef _WIN32
542 typedef signed char int8_t; 567 typedef signed char int8_t;
543 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
544 typedef signed short int16_t; 569 typedef signed short int16_t;
658 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
659#endif 684#endif
660 685
661#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
662 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 687 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
688 #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory")
663 #if __i386 || __i386__ 689 #if __i386 || __i386__
664 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 690 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
665 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
666 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
667 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
717 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
718 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
719 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
720 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
721 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) 747 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
748 #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED)
722 749
723 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
724 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
725 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
726 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
727 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) 754 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
755 #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED)
728 756
729 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
730 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
731 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
732 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ 760 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */
742 #elif defined _WIN32 770 #elif defined _WIN32
743 #include <WinNT.h> 771 #include <WinNT.h>
744 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
745 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
746 #include <mbarrier.h> 774 #include <mbarrier.h>
747 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
748 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
749 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 777 #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier ()
778 #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier ()
750 #elif __xlC__ 779 #elif __xlC__
751 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
752 #endif 781 #endif
753#endif 782#endif
754 783
755#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
756 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
757 /* we assume that these memory fences work on all variables/all memory accesses, */ 786 /* we assume that these memory fences work on all variables/all memory accesses, */
758 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
759 #include <stdatomic.h> 788 #include <stdatomic.h>
760 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
761 /* any fence other than seq_cst, which isn't very efficient for us. */
762 /* Why that is, we don't know - either the C11 memory model is quite useless */
763 /* for most usages, or gcc and clang have a bug */
764 /* I *currently* lean towards the latter, and inefficiently implement */
765 /* all three of ecb's fences as a seq_cst fence */
766 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
767 /* for all __atomic_thread_fence's except seq_cst */
768 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) 789 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
790 #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire)
791 #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release)
769 #endif 792 #endif
770#endif 793#endif
771 794
772#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
773 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
791 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
792#endif 815#endif
793 816
794#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
795 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 818 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
819#endif
820
821#if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE
822 #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */
796#endif 823#endif
797 824
798/*****************************************************************************/ 825/*****************************************************************************/
799 826
800#if ECB_CPP 827#if ECB_CPP
1509/* ECB.H END */ 1536/* ECB.H END */
1510 1537
1511#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 1538#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
1512/* if your architecture doesn't need memory fences, e.g. because it is 1539/* if your architecture doesn't need memory fences, e.g. because it is
1513 * single-cpu/core, or if you use libev in a project that doesn't use libev 1540 * single-cpu/core, or if you use libev in a project that doesn't use libev
1514 * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling 1541 * from multiple threads, then you can define ECB_NO_THREADS when compiling
1515 * libev, in which cases the memory fences become nops. 1542 * libev, in which cases the memory fences become nops.
1516 * alternatively, you can remove this #error and link against libpthread, 1543 * alternatively, you can remove this #error and link against libpthread,
1517 * which will then provide the memory fences. 1544 * which will then provide the memory fences.
1518 */ 1545 */
1519# error "memory fences not defined for your architecture, please report" 1546# error "memory fences not defined for your architecture, please report"
1523# define ECB_MEMORY_FENCE do { } while (0) 1550# define ECB_MEMORY_FENCE do { } while (0)
1524# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 1551# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
1525# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 1552# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
1526#endif 1553#endif
1527 1554
1528#define expect_false(cond) ecb_expect_false (cond)
1529#define expect_true(cond) ecb_expect_true (cond)
1530#define noinline ecb_noinline
1531
1532#define inline_size ecb_inline 1555#define inline_size ecb_inline
1533 1556
1534#if EV_FEATURE_CODE 1557#if EV_FEATURE_CODE
1535# define inline_speed ecb_inline 1558# define inline_speed ecb_inline
1536#else 1559#else
1537# define inline_speed noinline static 1560# define inline_speed ecb_noinline static
1538#endif 1561#endif
1539 1562
1540#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1563#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1541 1564
1542#if EV_MINPRI == EV_MAXPRI 1565#if EV_MINPRI == EV_MAXPRI
1543# define ABSPRI(w) (((W)w), 0) 1566# define ABSPRI(w) (((W)w), 0)
1544#else 1567#else
1545# define ABSPRI(w) (((W)w)->priority - EV_MINPRI) 1568# define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
1546#endif 1569#endif
1547 1570
1548#define EMPTY /* required for microsofts broken pseudo-c compiler */ 1571#define EMPTY /* required for microsofts broken pseudo-c compiler */
1549#define EMPTY2(a,b) /* used to suppress some warnings */
1550 1572
1551typedef ev_watcher *W; 1573typedef ev_watcher *W;
1552typedef ev_watcher_list *WL; 1574typedef ev_watcher_list *WL;
1553typedef ev_watcher_time *WT; 1575typedef ev_watcher_time *WT;
1554 1576
1579# include "ev_win32.c" 1601# include "ev_win32.c"
1580#endif 1602#endif
1581 1603
1582/*****************************************************************************/ 1604/*****************************************************************************/
1583 1605
1606#if EV_USE_LINUXAIO
1607# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1608#endif
1609
1584/* define a suitable floor function (only used by periodics atm) */ 1610/* define a suitable floor function (only used by periodics atm) */
1585 1611
1586#if EV_USE_FLOOR 1612#if EV_USE_FLOOR
1587# include <math.h> 1613# include <math.h>
1588# define ev_floor(v) floor (v) 1614# define ev_floor(v) floor (v)
1589#else 1615#else
1590 1616
1591#include <float.h> 1617#include <float.h>
1592 1618
1593/* a floor() replacement function, should be independent of ev_tstamp type */ 1619/* a floor() replacement function, should be independent of ev_tstamp type */
1594noinline 1620ecb_noinline
1595static ev_tstamp 1621static ev_tstamp
1596ev_floor (ev_tstamp v) 1622ev_floor (ev_tstamp v)
1597{ 1623{
1598 /* the choice of shift factor is not terribly important */ 1624 /* the choice of shift factor is not terribly important */
1599#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1625#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1601#else 1627#else
1602 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; 1628 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.;
1603#endif 1629#endif
1604 1630
1605 /* argument too large for an unsigned long? */ 1631 /* argument too large for an unsigned long? */
1606 if (expect_false (v >= shift)) 1632 if (ecb_expect_false (v >= shift))
1607 { 1633 {
1608 ev_tstamp f; 1634 ev_tstamp f;
1609 1635
1610 if (v == v - 1.) 1636 if (v == v - 1.)
1611 return v; /* very large number */ 1637 return v; /* very large number */
1613 f = shift * ev_floor (v * (1. / shift)); 1639 f = shift * ev_floor (v * (1. / shift));
1614 return f + ev_floor (v - f); 1640 return f + ev_floor (v - f);
1615 } 1641 }
1616 1642
1617 /* special treatment for negative args? */ 1643 /* special treatment for negative args? */
1618 if (expect_false (v < 0.)) 1644 if (ecb_expect_false (v < 0.))
1619 { 1645 {
1620 ev_tstamp f = -ev_floor (-v); 1646 ev_tstamp f = -ev_floor (-v);
1621 1647
1622 return f - (f == v ? 0 : 1); 1648 return f - (f == v ? 0 : 1);
1623 } 1649 }
1632 1658
1633#ifdef __linux 1659#ifdef __linux
1634# include <sys/utsname.h> 1660# include <sys/utsname.h>
1635#endif 1661#endif
1636 1662
1637noinline ecb_cold 1663ecb_noinline ecb_cold
1638static unsigned int 1664static unsigned int
1639ev_linux_version (void) 1665ev_linux_version (void)
1640{ 1666{
1641#ifdef __linux 1667#ifdef __linux
1642 unsigned int v = 0; 1668 unsigned int v = 0;
1672} 1698}
1673 1699
1674/*****************************************************************************/ 1700/*****************************************************************************/
1675 1701
1676#if EV_AVOID_STDIO 1702#if EV_AVOID_STDIO
1677noinline ecb_cold 1703ecb_noinline ecb_cold
1678static void 1704static void
1679ev_printerr (const char *msg) 1705ev_printerr (const char *msg)
1680{ 1706{
1681 write (STDERR_FILENO, msg, strlen (msg)); 1707 write (STDERR_FILENO, msg, strlen (msg));
1682} 1708}
1689ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT 1715ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1690{ 1716{
1691 syserr_cb = cb; 1717 syserr_cb = cb;
1692} 1718}
1693 1719
1694noinline ecb_cold 1720ecb_noinline ecb_cold
1695static void 1721static void
1696ev_syserr (const char *msg) 1722ev_syserr (const char *msg)
1697{ 1723{
1698 if (!msg) 1724 if (!msg)
1699 msg = "(libev) system error"; 1725 msg = "(libev) system error";
1770typedef struct 1796typedef struct
1771{ 1797{
1772 WL head; 1798 WL head;
1773 unsigned char events; /* the events watched for */ 1799 unsigned char events; /* the events watched for */
1774 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ 1800 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
1775 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 1801 unsigned char emask; /* some backends store the actual kernel mask in here */
1776 unsigned char unused; 1802 unsigned char unused;
1777#if EV_USE_EPOLL 1803#if EV_USE_EPOLL
1778 unsigned int egen; /* generation counter to counter epoll bugs */ 1804 unsigned int egen; /* generation counter to counter epoll bugs */
1779#endif 1805#endif
1780#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 1806#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
1845 static int ev_default_loop_ptr; 1871 static int ev_default_loop_ptr;
1846 1872
1847#endif 1873#endif
1848 1874
1849#if EV_FEATURE_API 1875#if EV_FEATURE_API
1850# define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) 1876# define EV_RELEASE_CB if (ecb_expect_false (release_cb)) release_cb (EV_A)
1851# define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) 1877# define EV_ACQUIRE_CB if (ecb_expect_false (acquire_cb)) acquire_cb (EV_A)
1852# define EV_INVOKE_PENDING invoke_cb (EV_A) 1878# define EV_INVOKE_PENDING invoke_cb (EV_A)
1853#else 1879#else
1854# define EV_RELEASE_CB (void)0 1880# define EV_RELEASE_CB (void)0
1855# define EV_ACQUIRE_CB (void)0 1881# define EV_ACQUIRE_CB (void)0
1856# define EV_INVOKE_PENDING ev_invoke_pending (EV_A) 1882# define EV_INVOKE_PENDING ev_invoke_pending (EV_A)
1863#ifndef EV_HAVE_EV_TIME 1889#ifndef EV_HAVE_EV_TIME
1864ev_tstamp 1890ev_tstamp
1865ev_time (void) EV_NOEXCEPT 1891ev_time (void) EV_NOEXCEPT
1866{ 1892{
1867#if EV_USE_REALTIME 1893#if EV_USE_REALTIME
1868 if (expect_true (have_realtime)) 1894 if (ecb_expect_true (have_realtime))
1869 { 1895 {
1870 struct timespec ts; 1896 struct timespec ts;
1871 clock_gettime (CLOCK_REALTIME, &ts); 1897 clock_gettime (CLOCK_REALTIME, &ts);
1872 return ts.tv_sec + ts.tv_nsec * 1e-9; 1898 return ts.tv_sec + ts.tv_nsec * 1e-9;
1873 } 1899 }
1881 1907
1882inline_size ev_tstamp 1908inline_size ev_tstamp
1883get_clock (void) 1909get_clock (void)
1884{ 1910{
1885#if EV_USE_MONOTONIC 1911#if EV_USE_MONOTONIC
1886 if (expect_true (have_monotonic)) 1912 if (ecb_expect_true (have_monotonic))
1887 { 1913 {
1888 struct timespec ts; 1914 struct timespec ts;
1889 clock_gettime (CLOCK_MONOTONIC, &ts); 1915 clock_gettime (CLOCK_MONOTONIC, &ts);
1890 return ts.tv_sec + ts.tv_nsec * 1e-9; 1916 return ts.tv_sec + ts.tv_nsec * 1e-9;
1891 } 1917 }
1953 } 1979 }
1954 1980
1955 return ncur; 1981 return ncur;
1956} 1982}
1957 1983
1958noinline ecb_cold 1984ecb_noinline ecb_cold
1959static void * 1985static void *
1960array_realloc (int elem, void *base, int *cur, int cnt) 1986array_realloc (int elem, void *base, int *cur, int cnt)
1961{ 1987{
1962 *cur = array_nextsize (elem, *cur, cnt); 1988 *cur = array_nextsize (elem, *cur, cnt);
1963 return ev_realloc (base, elem * *cur); 1989 return ev_realloc (base, elem * *cur);
1964} 1990}
1965 1991
1992#define array_needsize_noinit(base,offset,count)
1993
1966#define array_init_zero(base,count) \ 1994#define array_needsize_zerofill(base,offset,count) \
1967 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1995 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1968 1996
1969#define array_needsize(type,base,cur,cnt,init) \ 1997#define array_needsize(type,base,cur,cnt,init) \
1970 if (expect_false ((cnt) > (cur))) \ 1998 if (ecb_expect_false ((cnt) > (cur))) \
1971 { \ 1999 { \
1972 ecb_unused int ocur_ = (cur); \ 2000 ecb_unused int ocur_ = (cur); \
1973 (base) = (type *)array_realloc \ 2001 (base) = (type *)array_realloc \
1974 (sizeof (type), (base), &(cur), (cnt)); \ 2002 (sizeof (type), (base), &(cur), (cnt)); \
1975 init ((base) + (ocur_), (cur) - ocur_); \ 2003 init ((base), ocur_, ((cur) - ocur_)); \
1976 } 2004 }
1977 2005
1978#if 0 2006#if 0
1979#define array_slim(type,stem) \ 2007#define array_slim(type,stem) \
1980 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2008 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
1989 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 2017 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0
1990 2018
1991/*****************************************************************************/ 2019/*****************************************************************************/
1992 2020
1993/* dummy callback for pending events */ 2021/* dummy callback for pending events */
1994noinline 2022ecb_noinline
1995static void 2023static void
1996pendingcb (EV_P_ ev_prepare *w, int revents) 2024pendingcb (EV_P_ ev_prepare *w, int revents)
1997{ 2025{
1998} 2026}
1999 2027
2000noinline 2028ecb_noinline
2001void 2029void
2002ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT 2030ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
2003{ 2031{
2004 W w_ = (W)w; 2032 W w_ = (W)w;
2005 int pri = ABSPRI (w_); 2033 int pri = ABSPRI (w_);
2006 2034
2007 if (expect_false (w_->pending)) 2035 if (ecb_expect_false (w_->pending))
2008 pendings [pri][w_->pending - 1].events |= revents; 2036 pendings [pri][w_->pending - 1].events |= revents;
2009 else 2037 else
2010 { 2038 {
2011 w_->pending = ++pendingcnt [pri]; 2039 w_->pending = ++pendingcnt [pri];
2012 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 2040 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
2013 pendings [pri][w_->pending - 1].w = w_; 2041 pendings [pri][w_->pending - 1].w = w_;
2014 pendings [pri][w_->pending - 1].events = revents; 2042 pendings [pri][w_->pending - 1].events = revents;
2015 } 2043 }
2016 2044
2017 pendingpri = NUMPRI - 1; 2045 pendingpri = NUMPRI - 1;
2018} 2046}
2019 2047
2020inline_speed void 2048inline_speed void
2021feed_reverse (EV_P_ W w) 2049feed_reverse (EV_P_ W w)
2022{ 2050{
2023 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); 2051 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit);
2024 rfeeds [rfeedcnt++] = w; 2052 rfeeds [rfeedcnt++] = w;
2025} 2053}
2026 2054
2027inline_size void 2055inline_size void
2028feed_reverse_done (EV_P_ int revents) 2056feed_reverse_done (EV_P_ int revents)
2063inline_speed void 2091inline_speed void
2064fd_event (EV_P_ int fd, int revents) 2092fd_event (EV_P_ int fd, int revents)
2065{ 2093{
2066 ANFD *anfd = anfds + fd; 2094 ANFD *anfd = anfds + fd;
2067 2095
2068 if (expect_true (!anfd->reify)) 2096 if (ecb_expect_true (!anfd->reify))
2069 fd_event_nocheck (EV_A_ fd, revents); 2097 fd_event_nocheck (EV_A_ fd, revents);
2070} 2098}
2071 2099
2072void 2100void
2073ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT 2101ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2115 ev_io *w; 2143 ev_io *w;
2116 2144
2117 unsigned char o_events = anfd->events; 2145 unsigned char o_events = anfd->events;
2118 unsigned char o_reify = anfd->reify; 2146 unsigned char o_reify = anfd->reify;
2119 2147
2120 anfd->reify = 0; 2148 anfd->reify = 0;
2121 2149
2122 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2150 /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2123 { 2151 {
2124 anfd->events = 0; 2152 anfd->events = 0;
2125 2153
2126 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) 2154 for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next)
2127 anfd->events |= (unsigned char)w->events; 2155 anfd->events |= (unsigned char)w->events;
2143fd_change (EV_P_ int fd, int flags) 2171fd_change (EV_P_ int fd, int flags)
2144{ 2172{
2145 unsigned char reify = anfds [fd].reify; 2173 unsigned char reify = anfds [fd].reify;
2146 anfds [fd].reify |= flags; 2174 anfds [fd].reify |= flags;
2147 2175
2148 if (expect_true (!reify)) 2176 if (ecb_expect_true (!reify))
2149 { 2177 {
2150 ++fdchangecnt; 2178 ++fdchangecnt;
2151 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 2179 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2152 fdchanges [fdchangecnt - 1] = fd; 2180 fdchanges [fdchangecnt - 1] = fd;
2153 } 2181 }
2154} 2182}
2155 2183
2156/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 2184/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
2176 return fcntl (fd, F_GETFD) != -1; 2204 return fcntl (fd, F_GETFD) != -1;
2177#endif 2205#endif
2178} 2206}
2179 2207
2180/* called on EBADF to verify fds */ 2208/* called on EBADF to verify fds */
2181noinline ecb_cold 2209ecb_noinline ecb_cold
2182static void 2210static void
2183fd_ebadf (EV_P) 2211fd_ebadf (EV_P)
2184{ 2212{
2185 int fd; 2213 int fd;
2186 2214
2189 if (!fd_valid (fd) && errno == EBADF) 2217 if (!fd_valid (fd) && errno == EBADF)
2190 fd_kill (EV_A_ fd); 2218 fd_kill (EV_A_ fd);
2191} 2219}
2192 2220
2193/* called on ENOMEM in select/poll to kill some fds and retry */ 2221/* called on ENOMEM in select/poll to kill some fds and retry */
2194noinline ecb_cold 2222ecb_noinline ecb_cold
2195static void 2223static void
2196fd_enomem (EV_P) 2224fd_enomem (EV_P)
2197{ 2225{
2198 int fd; 2226 int fd;
2199 2227
2204 break; 2232 break;
2205 } 2233 }
2206} 2234}
2207 2235
2208/* usually called after fork if backend needs to re-arm all fds from scratch */ 2236/* usually called after fork if backend needs to re-arm all fds from scratch */
2209noinline 2237ecb_noinline
2210static void 2238static void
2211fd_rearm_all (EV_P) 2239fd_rearm_all (EV_P)
2212{ 2240{
2213 int fd; 2241 int fd;
2214 2242
2268 ev_tstamp minat; 2296 ev_tstamp minat;
2269 ANHE *minpos; 2297 ANHE *minpos;
2270 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; 2298 ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1;
2271 2299
2272 /* find minimum child */ 2300 /* find minimum child */
2273 if (expect_true (pos + DHEAP - 1 < E)) 2301 if (ecb_expect_true (pos + DHEAP - 1 < E))
2274 { 2302 {
2275 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); 2303 /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos));
2276 if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); 2304 if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos));
2277 if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); 2305 if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos));
2278 if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); 2306 if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos));
2396 2424
2397/*****************************************************************************/ 2425/*****************************************************************************/
2398 2426
2399#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2427#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2400 2428
2401noinline ecb_cold 2429ecb_noinline ecb_cold
2402static void 2430static void
2403evpipe_init (EV_P) 2431evpipe_init (EV_P)
2404{ 2432{
2405 if (!ev_is_active (&pipe_w)) 2433 if (!ev_is_active (&pipe_w))
2406 { 2434 {
2447inline_speed void 2475inline_speed void
2448evpipe_write (EV_P_ EV_ATOMIC_T *flag) 2476evpipe_write (EV_P_ EV_ATOMIC_T *flag)
2449{ 2477{
2450 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ 2478 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
2451 2479
2452 if (expect_true (*flag)) 2480 if (ecb_expect_true (*flag))
2453 return; 2481 return;
2454 2482
2455 *flag = 1; 2483 *flag = 1;
2456 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ 2484 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
2457 2485
2534 sig_pending = 0; 2562 sig_pending = 0;
2535 2563
2536 ECB_MEMORY_FENCE; 2564 ECB_MEMORY_FENCE;
2537 2565
2538 for (i = EV_NSIG - 1; i--; ) 2566 for (i = EV_NSIG - 1; i--; )
2539 if (expect_false (signals [i].pending)) 2567 if (ecb_expect_false (signals [i].pending))
2540 ev_feed_signal_event (EV_A_ i + 1); 2568 ev_feed_signal_event (EV_A_ i + 1);
2541 } 2569 }
2542#endif 2570#endif
2543 2571
2544#if EV_ASYNC_ENABLE 2572#if EV_ASYNC_ENABLE
2585#endif 2613#endif
2586 2614
2587 ev_feed_signal (signum); 2615 ev_feed_signal (signum);
2588} 2616}
2589 2617
2590noinline 2618ecb_noinline
2591void 2619void
2592ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT 2620ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2593{ 2621{
2594 WL w; 2622 WL w;
2595 2623
2596 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2624 if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG))
2597 return; 2625 return;
2598 2626
2599 --signum; 2627 --signum;
2600 2628
2601#if EV_MULTIPLICITY 2629#if EV_MULTIPLICITY
2602 /* it is permissible to try to feed a signal to the wrong loop */ 2630 /* it is permissible to try to feed a signal to the wrong loop */
2603 /* or, likely more useful, feeding a signal nobody is waiting for */ 2631 /* or, likely more useful, feeding a signal nobody is waiting for */
2604 2632
2605 if (expect_false (signals [signum].loop != EV_A)) 2633 if (ecb_expect_false (signals [signum].loop != EV_A))
2606 return; 2634 return;
2607#endif 2635#endif
2608 2636
2609 signals [signum].pending = 0; 2637 signals [signum].pending = 0;
2610 ECB_MEMORY_FENCE_RELEASE; 2638 ECB_MEMORY_FENCE_RELEASE;
2706# include "ev_kqueue.c" 2734# include "ev_kqueue.c"
2707#endif 2735#endif
2708#if EV_USE_EPOLL 2736#if EV_USE_EPOLL
2709# include "ev_epoll.c" 2737# include "ev_epoll.c"
2710#endif 2738#endif
2739#if EV_USE_LINUXAIO
2740# include "ev_linuxaio.c"
2741#endif
2711#if EV_USE_POLL 2742#if EV_USE_POLL
2712# include "ev_poll.c" 2743# include "ev_poll.c"
2713#endif 2744#endif
2714#if EV_USE_SELECT 2745#if EV_USE_SELECT
2715# include "ev_select.c" 2746# include "ev_select.c"
2743unsigned int 2774unsigned int
2744ev_supported_backends (void) EV_NOEXCEPT 2775ev_supported_backends (void) EV_NOEXCEPT
2745{ 2776{
2746 unsigned int flags = 0; 2777 unsigned int flags = 0;
2747 2778
2748 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2779 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2749 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2780 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2750 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 2781 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2782 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO;
2751 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 2783 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2752 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 2784 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2753 2785
2754 return flags; 2786 return flags;
2755} 2787}
2756 2788
2757ecb_cold 2789ecb_cold
2772#endif 2804#endif
2773#ifdef __FreeBSD__ 2805#ifdef __FreeBSD__
2774 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ 2806 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
2775#endif 2807#endif
2776 2808
2809 /* TODO: linuxaio is very experimental */
2810#if !EV_RECOMMEND_LINUXAIO
2811 flags &= ~EVBACKEND_LINUXAIO;
2812#endif
2813
2777 return flags; 2814 return flags;
2778} 2815}
2779 2816
2780ecb_cold 2817ecb_cold
2781unsigned int 2818unsigned int
2846 acquire_cb = acquire; 2883 acquire_cb = acquire;
2847} 2884}
2848#endif 2885#endif
2849 2886
2850/* initialise a loop structure, must be zero-initialised */ 2887/* initialise a loop structure, must be zero-initialised */
2851noinline ecb_cold 2888ecb_noinline ecb_cold
2852static void 2889static void
2853loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT 2890loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2854{ 2891{
2855 if (!backend) 2892 if (!backend)
2856 { 2893 {
2916 2953
2917 if (!(flags & EVBACKEND_MASK)) 2954 if (!(flags & EVBACKEND_MASK))
2918 flags |= ev_recommended_backends (); 2955 flags |= ev_recommended_backends ();
2919 2956
2920#if EV_USE_IOCP 2957#if EV_USE_IOCP
2921 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 2958 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
2922#endif 2959#endif
2923#if EV_USE_PORT 2960#if EV_USE_PORT
2924 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 2961 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
2925#endif 2962#endif
2926#if EV_USE_KQUEUE 2963#if EV_USE_KQUEUE
2927 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 2964 if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags);
2965#endif
2966#if EV_USE_LINUXAIO
2967 if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags);
2928#endif 2968#endif
2929#if EV_USE_EPOLL 2969#if EV_USE_EPOLL
2930 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); 2970 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
2931#endif 2971#endif
2932#if EV_USE_POLL 2972#if EV_USE_POLL
2933 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); 2973 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
2934#endif 2974#endif
2935#if EV_USE_SELECT 2975#if EV_USE_SELECT
2936 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 2976 if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags);
2937#endif 2977#endif
2938 2978
2939 ev_prepare_init (&pending_w, pendingcb); 2979 ev_prepare_init (&pending_w, pendingcb);
2940 2980
2941#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2981#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2958 return; 2998 return;
2959#endif 2999#endif
2960 3000
2961#if EV_CLEANUP_ENABLE 3001#if EV_CLEANUP_ENABLE
2962 /* queue cleanup watchers (and execute them) */ 3002 /* queue cleanup watchers (and execute them) */
2963 if (expect_false (cleanupcnt)) 3003 if (ecb_expect_false (cleanupcnt))
2964 { 3004 {
2965 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); 3005 queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP);
2966 EV_INVOKE_PENDING; 3006 EV_INVOKE_PENDING;
2967 } 3007 }
2968#endif 3008#endif
2996 3036
2997 if (backend_fd >= 0) 3037 if (backend_fd >= 0)
2998 close (backend_fd); 3038 close (backend_fd);
2999 3039
3000#if EV_USE_IOCP 3040#if EV_USE_IOCP
3001 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); 3041 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
3002#endif 3042#endif
3003#if EV_USE_PORT 3043#if EV_USE_PORT
3004 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 3044 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
3005#endif 3045#endif
3006#if EV_USE_KQUEUE 3046#if EV_USE_KQUEUE
3007 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 3047 if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A);
3048#endif
3049#if EV_USE_LINUXAIO
3050 if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A);
3008#endif 3051#endif
3009#if EV_USE_EPOLL 3052#if EV_USE_EPOLL
3010 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 3053 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
3011#endif 3054#endif
3012#if EV_USE_POLL 3055#if EV_USE_POLL
3013 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); 3056 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
3014#endif 3057#endif
3015#if EV_USE_SELECT 3058#if EV_USE_SELECT
3016 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 3059 if (backend == EVBACKEND_SELECT ) select_destroy (EV_A);
3017#endif 3060#endif
3018 3061
3019 for (i = NUMPRI; i--; ) 3062 for (i = NUMPRI; i--; )
3020 { 3063 {
3021 array_free (pending, [i]); 3064 array_free (pending, [i]);
3063 3106
3064inline_size void 3107inline_size void
3065loop_fork (EV_P) 3108loop_fork (EV_P)
3066{ 3109{
3067#if EV_USE_PORT 3110#if EV_USE_PORT
3068 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 3111 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
3069#endif 3112#endif
3070#if EV_USE_KQUEUE 3113#if EV_USE_KQUEUE
3071 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 3114 if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A);
3115#endif
3116#if EV_USE_LINUXAIO
3117 if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A);
3072#endif 3118#endif
3073#if EV_USE_EPOLL 3119#if EV_USE_EPOLL
3074 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 3120 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
3075#endif 3121#endif
3076#if EV_USE_INOTIFY 3122#if EV_USE_INOTIFY
3077 infy_fork (EV_A); 3123 infy_fork (EV_A);
3078#endif 3124#endif
3079 3125
3116} 3162}
3117 3163
3118#endif /* multiplicity */ 3164#endif /* multiplicity */
3119 3165
3120#if EV_VERIFY 3166#if EV_VERIFY
3121noinline ecb_cold 3167ecb_noinline ecb_cold
3122static void 3168static void
3123verify_watcher (EV_P_ W w) 3169verify_watcher (EV_P_ W w)
3124{ 3170{
3125 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 3171 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
3126 3172
3127 if (w->pending) 3173 if (w->pending)
3128 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 3174 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
3129} 3175}
3130 3176
3131noinline ecb_cold 3177ecb_noinline ecb_cold
3132static void 3178static void
3133verify_heap (EV_P_ ANHE *heap, int N) 3179verify_heap (EV_P_ ANHE *heap, int N)
3134{ 3180{
3135 int i; 3181 int i;
3136 3182
3142 3188
3143 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3189 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3144 } 3190 }
3145} 3191}
3146 3192
3147noinline ecb_cold 3193ecb_noinline ecb_cold
3148static void 3194static void
3149array_verify (EV_P_ W *ws, int cnt) 3195array_verify (EV_P_ W *ws, int cnt)
3150{ 3196{
3151 while (cnt--) 3197 while (cnt--)
3152 { 3198 {
3301 count += pendingcnt [pri]; 3347 count += pendingcnt [pri];
3302 3348
3303 return count; 3349 return count;
3304} 3350}
3305 3351
3306noinline 3352ecb_noinline
3307void 3353void
3308ev_invoke_pending (EV_P) 3354ev_invoke_pending (EV_P)
3309{ 3355{
3310 pendingpri = NUMPRI; 3356 pendingpri = NUMPRI;
3311 3357
3330/* make idle watchers pending. this handles the "call-idle */ 3376/* make idle watchers pending. this handles the "call-idle */
3331/* only when higher priorities are idle" logic */ 3377/* only when higher priorities are idle" logic */
3332inline_size void 3378inline_size void
3333idle_reify (EV_P) 3379idle_reify (EV_P)
3334{ 3380{
3335 if (expect_false (idleall)) 3381 if (ecb_expect_false (idleall))
3336 { 3382 {
3337 int pri; 3383 int pri;
3338 3384
3339 for (pri = NUMPRI; pri--; ) 3385 for (pri = NUMPRI; pri--; )
3340 { 3386 {
3389 } 3435 }
3390} 3436}
3391 3437
3392#if EV_PERIODIC_ENABLE 3438#if EV_PERIODIC_ENABLE
3393 3439
3394noinline 3440ecb_noinline
3395static void 3441static void
3396periodic_recalc (EV_P_ ev_periodic *w) 3442periodic_recalc (EV_P_ ev_periodic *w)
3397{ 3443{
3398 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3444 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL;
3399 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); 3445 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval);
3402 while (at <= ev_rt_now) 3448 while (at <= ev_rt_now)
3403 { 3449 {
3404 ev_tstamp nat = at + w->interval; 3450 ev_tstamp nat = at + w->interval;
3405 3451
3406 /* when resolution fails us, we use ev_rt_now */ 3452 /* when resolution fails us, we use ev_rt_now */
3407 if (expect_false (nat == at)) 3453 if (ecb_expect_false (nat == at))
3408 { 3454 {
3409 at = ev_rt_now; 3455 at = ev_rt_now;
3410 break; 3456 break;
3411 } 3457 }
3412 3458
3458 } 3504 }
3459} 3505}
3460 3506
3461/* simply recalculate all periodics */ 3507/* simply recalculate all periodics */
3462/* TODO: maybe ensure that at least one event happens when jumping forward? */ 3508/* TODO: maybe ensure that at least one event happens when jumping forward? */
3463noinline ecb_cold 3509ecb_noinline ecb_cold
3464static void 3510static void
3465periodics_reschedule (EV_P) 3511periodics_reschedule (EV_P)
3466{ 3512{
3467 int i; 3513 int i;
3468 3514
3482 reheap (periodics, periodiccnt); 3528 reheap (periodics, periodiccnt);
3483} 3529}
3484#endif 3530#endif
3485 3531
3486/* adjust all timers by a given offset */ 3532/* adjust all timers by a given offset */
3487noinline ecb_cold 3533ecb_noinline ecb_cold
3488static void 3534static void
3489timers_reschedule (EV_P_ ev_tstamp adjust) 3535timers_reschedule (EV_P_ ev_tstamp adjust)
3490{ 3536{
3491 int i; 3537 int i;
3492 3538
3502/* also detect if there was a timejump, and act accordingly */ 3548/* also detect if there was a timejump, and act accordingly */
3503inline_speed void 3549inline_speed void
3504time_update (EV_P_ ev_tstamp max_block) 3550time_update (EV_P_ ev_tstamp max_block)
3505{ 3551{
3506#if EV_USE_MONOTONIC 3552#if EV_USE_MONOTONIC
3507 if (expect_true (have_monotonic)) 3553 if (ecb_expect_true (have_monotonic))
3508 { 3554 {
3509 int i; 3555 int i;
3510 ev_tstamp odiff = rtmn_diff; 3556 ev_tstamp odiff = rtmn_diff;
3511 3557
3512 mn_now = get_clock (); 3558 mn_now = get_clock ();
3513 3559
3514 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ 3560 /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */
3515 /* interpolate in the meantime */ 3561 /* interpolate in the meantime */
3516 if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) 3562 if (ecb_expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5))
3517 { 3563 {
3518 ev_rt_now = rtmn_diff + mn_now; 3564 ev_rt_now = rtmn_diff + mn_now;
3519 return; 3565 return;
3520 } 3566 }
3521 3567
3535 ev_tstamp diff; 3581 ev_tstamp diff;
3536 rtmn_diff = ev_rt_now - mn_now; 3582 rtmn_diff = ev_rt_now - mn_now;
3537 3583
3538 diff = odiff - rtmn_diff; 3584 diff = odiff - rtmn_diff;
3539 3585
3540 if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) 3586 if (ecb_expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP))
3541 return; /* all is well */ 3587 return; /* all is well */
3542 3588
3543 ev_rt_now = ev_time (); 3589 ev_rt_now = ev_time ();
3544 mn_now = get_clock (); 3590 mn_now = get_clock ();
3545 now_floor = mn_now; 3591 now_floor = mn_now;
3554 else 3600 else
3555#endif 3601#endif
3556 { 3602 {
3557 ev_rt_now = ev_time (); 3603 ev_rt_now = ev_time ();
3558 3604
3559 if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) 3605 if (ecb_expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP))
3560 { 3606 {
3561 /* adjust timers. this is easy, as the offset is the same for all of them */ 3607 /* adjust timers. this is easy, as the offset is the same for all of them */
3562 timers_reschedule (EV_A_ ev_rt_now - mn_now); 3608 timers_reschedule (EV_A_ ev_rt_now - mn_now);
3563#if EV_PERIODIC_ENABLE 3609#if EV_PERIODIC_ENABLE
3564 periodics_reschedule (EV_A); 3610 periodics_reschedule (EV_A);
3587#if EV_VERIFY >= 2 3633#if EV_VERIFY >= 2
3588 ev_verify (EV_A); 3634 ev_verify (EV_A);
3589#endif 3635#endif
3590 3636
3591#ifndef _WIN32 3637#ifndef _WIN32
3592 if (expect_false (curpid)) /* penalise the forking check even more */ 3638 if (ecb_expect_false (curpid)) /* penalise the forking check even more */
3593 if (expect_false (getpid () != curpid)) 3639 if (ecb_expect_false (getpid () != curpid))
3594 { 3640 {
3595 curpid = getpid (); 3641 curpid = getpid ();
3596 postfork = 1; 3642 postfork = 1;
3597 } 3643 }
3598#endif 3644#endif
3599 3645
3600#if EV_FORK_ENABLE 3646#if EV_FORK_ENABLE
3601 /* we might have forked, so queue fork handlers */ 3647 /* we might have forked, so queue fork handlers */
3602 if (expect_false (postfork)) 3648 if (ecb_expect_false (postfork))
3603 if (forkcnt) 3649 if (forkcnt)
3604 { 3650 {
3605 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); 3651 queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK);
3606 EV_INVOKE_PENDING; 3652 EV_INVOKE_PENDING;
3607 } 3653 }
3608#endif 3654#endif
3609 3655
3610#if EV_PREPARE_ENABLE 3656#if EV_PREPARE_ENABLE
3611 /* queue prepare watchers (and execute them) */ 3657 /* queue prepare watchers (and execute them) */
3612 if (expect_false (preparecnt)) 3658 if (ecb_expect_false (preparecnt))
3613 { 3659 {
3614 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); 3660 queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE);
3615 EV_INVOKE_PENDING; 3661 EV_INVOKE_PENDING;
3616 } 3662 }
3617#endif 3663#endif
3618 3664
3619 if (expect_false (loop_done)) 3665 if (ecb_expect_false (loop_done))
3620 break; 3666 break;
3621 3667
3622 /* we might have forked, so reify kernel state if necessary */ 3668 /* we might have forked, so reify kernel state if necessary */
3623 if (expect_false (postfork)) 3669 if (ecb_expect_false (postfork))
3624 loop_fork (EV_A); 3670 loop_fork (EV_A);
3625 3671
3626 /* update fd-related kernel structures */ 3672 /* update fd-related kernel structures */
3627 fd_reify (EV_A); 3673 fd_reify (EV_A);
3628 3674
3640 /* from now on, we want a pipe-wake-up */ 3686 /* from now on, we want a pipe-wake-up */
3641 pipe_write_wanted = 1; 3687 pipe_write_wanted = 1;
3642 3688
3643 ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ 3689 ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */
3644 3690
3645 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 3691 if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
3646 { 3692 {
3647 waittime = MAX_BLOCKTIME; 3693 waittime = MAX_BLOCKTIME;
3648 3694
3649 if (timercnt) 3695 if (timercnt)
3650 { 3696 {
3659 if (waittime > to) waittime = to; 3705 if (waittime > to) waittime = to;
3660 } 3706 }
3661#endif 3707#endif
3662 3708
3663 /* don't let timeouts decrease the waittime below timeout_blocktime */ 3709 /* don't let timeouts decrease the waittime below timeout_blocktime */
3664 if (expect_false (waittime < timeout_blocktime)) 3710 if (ecb_expect_false (waittime < timeout_blocktime))
3665 waittime = timeout_blocktime; 3711 waittime = timeout_blocktime;
3666 3712
3667 /* at this point, we NEED to wait, so we have to ensure */ 3713 /* at this point, we NEED to wait, so we have to ensure */
3668 /* to pass a minimum nonzero value to the backend */ 3714 /* to pass a minimum nonzero value to the backend */
3669 if (expect_false (waittime < backend_mintime)) 3715 if (ecb_expect_false (waittime < backend_mintime))
3670 waittime = backend_mintime; 3716 waittime = backend_mintime;
3671 3717
3672 /* extra check because io_blocktime is commonly 0 */ 3718 /* extra check because io_blocktime is commonly 0 */
3673 if (expect_false (io_blocktime)) 3719 if (ecb_expect_false (io_blocktime))
3674 { 3720 {
3675 sleeptime = io_blocktime - (mn_now - prev_mn_now); 3721 sleeptime = io_blocktime - (mn_now - prev_mn_now);
3676 3722
3677 if (sleeptime > waittime - backend_mintime) 3723 if (sleeptime > waittime - backend_mintime)
3678 sleeptime = waittime - backend_mintime; 3724 sleeptime = waittime - backend_mintime;
3679 3725
3680 if (expect_true (sleeptime > 0.)) 3726 if (ecb_expect_true (sleeptime > 0.))
3681 { 3727 {
3682 ev_sleep (sleeptime); 3728 ev_sleep (sleeptime);
3683 waittime -= sleeptime; 3729 waittime -= sleeptime;
3684 } 3730 }
3685 } 3731 }
3699 { 3745 {
3700 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 3746 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
3701 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3747 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3702 } 3748 }
3703 3749
3704
3705 /* update ev_rt_now, do magic */ 3750 /* update ev_rt_now, do magic */
3706 time_update (EV_A_ waittime + sleeptime); 3751 time_update (EV_A_ waittime + sleeptime);
3707 } 3752 }
3708 3753
3709 /* queue pending timers and reschedule them */ 3754 /* queue pending timers and reschedule them */
3717 idle_reify (EV_A); 3762 idle_reify (EV_A);
3718#endif 3763#endif
3719 3764
3720#if EV_CHECK_ENABLE 3765#if EV_CHECK_ENABLE
3721 /* queue check watchers, to be executed first */ 3766 /* queue check watchers, to be executed first */
3722 if (expect_false (checkcnt)) 3767 if (ecb_expect_false (checkcnt))
3723 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); 3768 queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK);
3724#endif 3769#endif
3725 3770
3726 EV_INVOKE_PENDING; 3771 EV_INVOKE_PENDING;
3727 } 3772 }
3728 while (expect_true ( 3773 while (ecb_expect_true (
3729 activecnt 3774 activecnt
3730 && !loop_done 3775 && !loop_done
3731 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) 3776 && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT))
3732 )); 3777 ));
3733 3778
3797inline_size void 3842inline_size void
3798wlist_del (WL *head, WL elem) 3843wlist_del (WL *head, WL elem)
3799{ 3844{
3800 while (*head) 3845 while (*head)
3801 { 3846 {
3802 if (expect_true (*head == elem)) 3847 if (ecb_expect_true (*head == elem))
3803 { 3848 {
3804 *head = elem->next; 3849 *head = elem->next;
3805 break; 3850 break;
3806 } 3851 }
3807 3852
3824ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT 3869ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3825{ 3870{
3826 W w_ = (W)w; 3871 W w_ = (W)w;
3827 int pending = w_->pending; 3872 int pending = w_->pending;
3828 3873
3829 if (expect_true (pending)) 3874 if (ecb_expect_true (pending))
3830 { 3875 {
3831 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; 3876 ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1;
3832 p->w = (W)&pending_w; 3877 p->w = (W)&pending_w;
3833 w_->pending = 0; 3878 w_->pending = 0;
3834 return p->events; 3879 return p->events;
3861 w->active = 0; 3906 w->active = 0;
3862} 3907}
3863 3908
3864/*****************************************************************************/ 3909/*****************************************************************************/
3865 3910
3866noinline 3911ecb_noinline
3867void 3912void
3868ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT 3913ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3869{ 3914{
3870 int fd = w->fd; 3915 int fd = w->fd;
3871 3916
3872 if (expect_false (ev_is_active (w))) 3917 if (ecb_expect_false (ev_is_active (w)))
3873 return; 3918 return;
3874 3919
3875 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3920 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3876 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3921 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3877 3922
3923#if EV_VERIFY >= 2
3924 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3925#endif
3878 EV_FREQUENT_CHECK; 3926 EV_FREQUENT_CHECK;
3879 3927
3880 ev_start (EV_A_ (W)w, 1); 3928 ev_start (EV_A_ (W)w, 1);
3881 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3929 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3882 wlist_add (&anfds[fd].head, (WL)w); 3930 wlist_add (&anfds[fd].head, (WL)w);
3883 3931
3884 /* common bug, apparently */ 3932 /* common bug, apparently */
3885 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));
3886 3934
3888 w->events &= ~EV__IOFDSET; 3936 w->events &= ~EV__IOFDSET;
3889 3937
3890 EV_FREQUENT_CHECK; 3938 EV_FREQUENT_CHECK;
3891} 3939}
3892 3940
3893noinline 3941ecb_noinline
3894void 3942void
3895ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT 3943ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3896{ 3944{
3897 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3898 if (expect_false (!ev_is_active (w))) 3946 if (ecb_expect_false (!ev_is_active (w)))
3899 return; 3947 return;
3900 3948
3901 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 3949 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
3902 3950
3951#if EV_VERIFY >= 2
3952 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3953#endif
3903 EV_FREQUENT_CHECK; 3954 EV_FREQUENT_CHECK;
3904 3955
3905 wlist_del (&anfds[w->fd].head, (WL)w); 3956 wlist_del (&anfds[w->fd].head, (WL)w);
3906 ev_stop (EV_A_ (W)w); 3957 ev_stop (EV_A_ (W)w);
3907 3958
3908 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3959 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3909 3960
3910 EV_FREQUENT_CHECK; 3961 EV_FREQUENT_CHECK;
3911} 3962}
3912 3963
3913noinline 3964ecb_noinline
3914void 3965void
3915ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT 3966ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3916{ 3967{
3917 if (expect_false (ev_is_active (w))) 3968 if (ecb_expect_false (ev_is_active (w)))
3918 return; 3969 return;
3919 3970
3920 ev_at (w) += mn_now; 3971 ev_at (w) += mn_now;
3921 3972
3922 assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); 3973 assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.));
3923 3974
3924 EV_FREQUENT_CHECK; 3975 EV_FREQUENT_CHECK;
3925 3976
3926 ++timercnt; 3977 ++timercnt;
3927 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3978 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3928 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3979 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3929 ANHE_w (timers [ev_active (w)]) = (WT)w; 3980 ANHE_w (timers [ev_active (w)]) = (WT)w;
3930 ANHE_at_cache (timers [ev_active (w)]); 3981 ANHE_at_cache (timers [ev_active (w)]);
3931 upheap (timers, ev_active (w)); 3982 upheap (timers, ev_active (w));
3932 3983
3933 EV_FREQUENT_CHECK; 3984 EV_FREQUENT_CHECK;
3934 3985
3935 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3986 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3936} 3987}
3937 3988
3938noinline 3989ecb_noinline
3939void 3990void
3940ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT 3991ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3941{ 3992{
3942 clear_pending (EV_A_ (W)w); 3993 clear_pending (EV_A_ (W)w);
3943 if (expect_false (!ev_is_active (w))) 3994 if (ecb_expect_false (!ev_is_active (w)))
3944 return; 3995 return;
3945 3996
3946 EV_FREQUENT_CHECK; 3997 EV_FREQUENT_CHECK;
3947 3998
3948 { 3999 {
3950 4001
3951 assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); 4002 assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w));
3952 4003
3953 --timercnt; 4004 --timercnt;
3954 4005
3955 if (expect_true (active < timercnt + HEAP0)) 4006 if (ecb_expect_true (active < timercnt + HEAP0))
3956 { 4007 {
3957 timers [active] = timers [timercnt + HEAP0]; 4008 timers [active] = timers [timercnt + HEAP0];
3958 adjustheap (timers, timercnt, active); 4009 adjustheap (timers, timercnt, active);
3959 } 4010 }
3960 } 4011 }
3964 ev_stop (EV_A_ (W)w); 4015 ev_stop (EV_A_ (W)w);
3965 4016
3966 EV_FREQUENT_CHECK; 4017 EV_FREQUENT_CHECK;
3967} 4018}
3968 4019
3969noinline 4020ecb_noinline
3970void 4021void
3971ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT 4022ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3972{ 4023{
3973 EV_FREQUENT_CHECK; 4024 EV_FREQUENT_CHECK;
3974 4025
3999{ 4050{
4000 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4051 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
4001} 4052}
4002 4053
4003#if EV_PERIODIC_ENABLE 4054#if EV_PERIODIC_ENABLE
4004noinline 4055ecb_noinline
4005void 4056void
4006ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT 4057ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4007{ 4058{
4008 if (expect_false (ev_is_active (w))) 4059 if (ecb_expect_false (ev_is_active (w)))
4009 return; 4060 return;
4010 4061
4011 if (w->reschedule_cb) 4062 if (w->reschedule_cb)
4012 ev_at (w) = w->reschedule_cb (w, ev_rt_now); 4063 ev_at (w) = w->reschedule_cb (w, ev_rt_now);
4013 else if (w->interval) 4064 else if (w->interval)
4020 4071
4021 EV_FREQUENT_CHECK; 4072 EV_FREQUENT_CHECK;
4022 4073
4023 ++periodiccnt; 4074 ++periodiccnt;
4024 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4075 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
4025 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4076 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
4026 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4077 ANHE_w (periodics [ev_active (w)]) = (WT)w;
4027 ANHE_at_cache (periodics [ev_active (w)]); 4078 ANHE_at_cache (periodics [ev_active (w)]);
4028 upheap (periodics, ev_active (w)); 4079 upheap (periodics, ev_active (w));
4029 4080
4030 EV_FREQUENT_CHECK; 4081 EV_FREQUENT_CHECK;
4031 4082
4032 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4083 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
4033} 4084}
4034 4085
4035noinline 4086ecb_noinline
4036void 4087void
4037ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT 4088ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4038{ 4089{
4039 clear_pending (EV_A_ (W)w); 4090 clear_pending (EV_A_ (W)w);
4040 if (expect_false (!ev_is_active (w))) 4091 if (ecb_expect_false (!ev_is_active (w)))
4041 return; 4092 return;
4042 4093
4043 EV_FREQUENT_CHECK; 4094 EV_FREQUENT_CHECK;
4044 4095
4045 { 4096 {
4047 4098
4048 assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); 4099 assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w));
4049 4100
4050 --periodiccnt; 4101 --periodiccnt;
4051 4102
4052 if (expect_true (active < periodiccnt + HEAP0)) 4103 if (ecb_expect_true (active < periodiccnt + HEAP0))
4053 { 4104 {
4054 periodics [active] = periodics [periodiccnt + HEAP0]; 4105 periodics [active] = periodics [periodiccnt + HEAP0];
4055 adjustheap (periodics, periodiccnt, active); 4106 adjustheap (periodics, periodiccnt, active);
4056 } 4107 }
4057 } 4108 }
4059 ev_stop (EV_A_ (W)w); 4110 ev_stop (EV_A_ (W)w);
4060 4111
4061 EV_FREQUENT_CHECK; 4112 EV_FREQUENT_CHECK;
4062} 4113}
4063 4114
4064noinline 4115ecb_noinline
4065void 4116void
4066ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT 4117ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4067{ 4118{
4068 /* TODO: use adjustheap and recalculation */ 4119 /* TODO: use adjustheap and recalculation */
4069 ev_periodic_stop (EV_A_ w); 4120 ev_periodic_stop (EV_A_ w);
4075# define SA_RESTART 0 4126# define SA_RESTART 0
4076#endif 4127#endif
4077 4128
4078#if EV_SIGNAL_ENABLE 4129#if EV_SIGNAL_ENABLE
4079 4130
4080noinline 4131ecb_noinline
4081void 4132void
4082ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT 4133ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4083{ 4134{
4084 if (expect_false (ev_is_active (w))) 4135 if (ecb_expect_false (ev_is_active (w)))
4085 return; 4136 return;
4086 4137
4087 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4138 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4088 4139
4089#if EV_MULTIPLICITY 4140#if EV_MULTIPLICITY
4158 } 4209 }
4159 4210
4160 EV_FREQUENT_CHECK; 4211 EV_FREQUENT_CHECK;
4161} 4212}
4162 4213
4163noinline 4214ecb_noinline
4164void 4215void
4165ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT 4216ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4166{ 4217{
4167 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4168 if (expect_false (!ev_is_active (w))) 4219 if (ecb_expect_false (!ev_is_active (w)))
4169 return; 4220 return;
4170 4221
4171 EV_FREQUENT_CHECK; 4222 EV_FREQUENT_CHECK;
4172 4223
4173 wlist_del (&signals [w->signum - 1].head, (WL)w); 4224 wlist_del (&signals [w->signum - 1].head, (WL)w);
4206ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT 4257ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4207{ 4258{
4208#if EV_MULTIPLICITY 4259#if EV_MULTIPLICITY
4209 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4260 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4210#endif 4261#endif
4211 if (expect_false (ev_is_active (w))) 4262 if (ecb_expect_false (ev_is_active (w)))
4212 return; 4263 return;
4213 4264
4214 EV_FREQUENT_CHECK; 4265 EV_FREQUENT_CHECK;
4215 4266
4216 ev_start (EV_A_ (W)w, 1); 4267 ev_start (EV_A_ (W)w, 1);
4221 4272
4222void 4273void
4223ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT 4274ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4224{ 4275{
4225 clear_pending (EV_A_ (W)w); 4276 clear_pending (EV_A_ (W)w);
4226 if (expect_false (!ev_is_active (w))) 4277 if (ecb_expect_false (!ev_is_active (w)))
4227 return; 4278 return;
4228 4279
4229 EV_FREQUENT_CHECK; 4280 EV_FREQUENT_CHECK;
4230 4281
4231 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); 4282 wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w);
4245 4296
4246#define DEF_STAT_INTERVAL 5.0074891 4297#define DEF_STAT_INTERVAL 5.0074891
4247#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4298#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4248#define MIN_STAT_INTERVAL 0.1074891 4299#define MIN_STAT_INTERVAL 0.1074891
4249 4300
4250noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4301ecb_noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4251 4302
4252#if EV_USE_INOTIFY 4303#if EV_USE_INOTIFY
4253 4304
4254/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4305/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */
4255# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 4306# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4256 4307
4257noinline 4308ecb_noinline
4258static void 4309static void
4259infy_add (EV_P_ ev_stat *w) 4310infy_add (EV_P_ ev_stat *w)
4260{ 4311{
4261 w->wd = inotify_add_watch (fs_fd, w->path, 4312 w->wd = inotify_add_watch (fs_fd, w->path,
4262 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4313 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4327 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4378 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4328 ev_timer_again (EV_A_ &w->timer); 4379 ev_timer_again (EV_A_ &w->timer);
4329 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4380 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4330} 4381}
4331 4382
4332noinline 4383ecb_noinline
4333static void 4384static void
4334infy_del (EV_P_ ev_stat *w) 4385infy_del (EV_P_ ev_stat *w)
4335{ 4386{
4336 int slot; 4387 int slot;
4337 int wd = w->wd; 4388 int wd = w->wd;
4345 4396
4346 /* remove this watcher, if others are watching it, they will rearm */ 4397 /* remove this watcher, if others are watching it, they will rearm */
4347 inotify_rm_watch (fs_fd, wd); 4398 inotify_rm_watch (fs_fd, wd);
4348} 4399}
4349 4400
4350noinline 4401ecb_noinline
4351static void 4402static void
4352infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4403infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4353{ 4404{
4354 if (slot < 0) 4405 if (slot < 0)
4355 /* overflow, need to check for all hash slots */ 4406 /* overflow, need to check for all hash slots */
4501 w->attr.st_nlink = 0; 4552 w->attr.st_nlink = 0;
4502 else if (!w->attr.st_nlink) 4553 else if (!w->attr.st_nlink)
4503 w->attr.st_nlink = 1; 4554 w->attr.st_nlink = 1;
4504} 4555}
4505 4556
4506noinline 4557ecb_noinline
4507static void 4558static void
4508stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4559stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4509{ 4560{
4510 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4561 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4511 4562
4545} 4596}
4546 4597
4547void 4598void
4548ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT 4599ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4549{ 4600{
4550 if (expect_false (ev_is_active (w))) 4601 if (ecb_expect_false (ev_is_active (w)))
4551 return; 4602 return;
4552 4603
4553 ev_stat_stat (EV_A_ w); 4604 ev_stat_stat (EV_A_ w);
4554 4605
4555 if (w->interval < MIN_STAT_INTERVAL && w->interval) 4606 if (w->interval < MIN_STAT_INTERVAL && w->interval)
4577 4628
4578void 4629void
4579ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT 4630ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4580{ 4631{
4581 clear_pending (EV_A_ (W)w); 4632 clear_pending (EV_A_ (W)w);
4582 if (expect_false (!ev_is_active (w))) 4633 if (ecb_expect_false (!ev_is_active (w)))
4583 return; 4634 return;
4584 4635
4585 EV_FREQUENT_CHECK; 4636 EV_FREQUENT_CHECK;
4586 4637
4587#if EV_USE_INOTIFY 4638#if EV_USE_INOTIFY
4602 4653
4603#if EV_IDLE_ENABLE 4654#if EV_IDLE_ENABLE
4604void 4655void
4605ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT 4656ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4606{ 4657{
4607 if (expect_false (ev_is_active (w))) 4658 if (ecb_expect_false (ev_is_active (w)))
4608 return; 4659 return;
4609 4660
4610 pri_adjust (EV_A_ (W)w); 4661 pri_adjust (EV_A_ (W)w);
4611 4662
4612 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4615 int active = ++idlecnt [ABSPRI (w)]; 4666 int active = ++idlecnt [ABSPRI (w)];
4616 4667
4617 ++idleall; 4668 ++idleall;
4618 ev_start (EV_A_ (W)w, active); 4669 ev_start (EV_A_ (W)w, active);
4619 4670
4620 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4671 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4621 idles [ABSPRI (w)][active - 1] = w; 4672 idles [ABSPRI (w)][active - 1] = w;
4622 } 4673 }
4623 4674
4624 EV_FREQUENT_CHECK; 4675 EV_FREQUENT_CHECK;
4625} 4676}
4626 4677
4627void 4678void
4628ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT 4679ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4629{ 4680{
4630 clear_pending (EV_A_ (W)w); 4681 clear_pending (EV_A_ (W)w);
4631 if (expect_false (!ev_is_active (w))) 4682 if (ecb_expect_false (!ev_is_active (w)))
4632 return; 4683 return;
4633 4684
4634 EV_FREQUENT_CHECK; 4685 EV_FREQUENT_CHECK;
4635 4686
4636 { 4687 {
4649 4700
4650#if EV_PREPARE_ENABLE 4701#if EV_PREPARE_ENABLE
4651void 4702void
4652ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT 4703ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4653{ 4704{
4654 if (expect_false (ev_is_active (w))) 4705 if (ecb_expect_false (ev_is_active (w)))
4655 return; 4706 return;
4656 4707
4657 EV_FREQUENT_CHECK; 4708 EV_FREQUENT_CHECK;
4658 4709
4659 ev_start (EV_A_ (W)w, ++preparecnt); 4710 ev_start (EV_A_ (W)w, ++preparecnt);
4660 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4711 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4661 prepares [preparecnt - 1] = w; 4712 prepares [preparecnt - 1] = w;
4662 4713
4663 EV_FREQUENT_CHECK; 4714 EV_FREQUENT_CHECK;
4664} 4715}
4665 4716
4666void 4717void
4667ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT 4718ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4668{ 4719{
4669 clear_pending (EV_A_ (W)w); 4720 clear_pending (EV_A_ (W)w);
4670 if (expect_false (!ev_is_active (w))) 4721 if (ecb_expect_false (!ev_is_active (w)))
4671 return; 4722 return;
4672 4723
4673 EV_FREQUENT_CHECK; 4724 EV_FREQUENT_CHECK;
4674 4725
4675 { 4726 {
4687 4738
4688#if EV_CHECK_ENABLE 4739#if EV_CHECK_ENABLE
4689void 4740void
4690ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT 4741ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4691{ 4742{
4692 if (expect_false (ev_is_active (w))) 4743 if (ecb_expect_false (ev_is_active (w)))
4693 return; 4744 return;
4694 4745
4695 EV_FREQUENT_CHECK; 4746 EV_FREQUENT_CHECK;
4696 4747
4697 ev_start (EV_A_ (W)w, ++checkcnt); 4748 ev_start (EV_A_ (W)w, ++checkcnt);
4698 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4749 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4699 checks [checkcnt - 1] = w; 4750 checks [checkcnt - 1] = w;
4700 4751
4701 EV_FREQUENT_CHECK; 4752 EV_FREQUENT_CHECK;
4702} 4753}
4703 4754
4704void 4755void
4705ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT 4756ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4706{ 4757{
4707 clear_pending (EV_A_ (W)w); 4758 clear_pending (EV_A_ (W)w);
4708 if (expect_false (!ev_is_active (w))) 4759 if (ecb_expect_false (!ev_is_active (w)))
4709 return; 4760 return;
4710 4761
4711 EV_FREQUENT_CHECK; 4762 EV_FREQUENT_CHECK;
4712 4763
4713 { 4764 {
4722 EV_FREQUENT_CHECK; 4773 EV_FREQUENT_CHECK;
4723} 4774}
4724#endif 4775#endif
4725 4776
4726#if EV_EMBED_ENABLE 4777#if EV_EMBED_ENABLE
4727noinline 4778ecb_noinline
4728void 4779void
4729ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT 4780ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4730{ 4781{
4731 ev_run (w->other, EVRUN_NOWAIT); 4782 ev_run (w->other, EVRUN_NOWAIT);
4732} 4783}
4784#endif 4835#endif
4785 4836
4786void 4837void
4787ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT 4838ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4788{ 4839{
4789 if (expect_false (ev_is_active (w))) 4840 if (ecb_expect_false (ev_is_active (w)))
4790 return; 4841 return;
4791 4842
4792 { 4843 {
4793 EV_P = w->other; 4844 EV_P = w->other;
4794 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); 4845 assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ()));
4816 4867
4817void 4868void
4818ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT 4869ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4819{ 4870{
4820 clear_pending (EV_A_ (W)w); 4871 clear_pending (EV_A_ (W)w);
4821 if (expect_false (!ev_is_active (w))) 4872 if (ecb_expect_false (!ev_is_active (w)))
4822 return; 4873 return;
4823 4874
4824 EV_FREQUENT_CHECK; 4875 EV_FREQUENT_CHECK;
4825 4876
4826 ev_io_stop (EV_A_ &w->io); 4877 ev_io_stop (EV_A_ &w->io);
4835 4886
4836#if EV_FORK_ENABLE 4887#if EV_FORK_ENABLE
4837void 4888void
4838ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT 4889ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4839{ 4890{
4840 if (expect_false (ev_is_active (w))) 4891 if (ecb_expect_false (ev_is_active (w)))
4841 return; 4892 return;
4842 4893
4843 EV_FREQUENT_CHECK; 4894 EV_FREQUENT_CHECK;
4844 4895
4845 ev_start (EV_A_ (W)w, ++forkcnt); 4896 ev_start (EV_A_ (W)w, ++forkcnt);
4846 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4897 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4847 forks [forkcnt - 1] = w; 4898 forks [forkcnt - 1] = w;
4848 4899
4849 EV_FREQUENT_CHECK; 4900 EV_FREQUENT_CHECK;
4850} 4901}
4851 4902
4852void 4903void
4853ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT 4904ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4854{ 4905{
4855 clear_pending (EV_A_ (W)w); 4906 clear_pending (EV_A_ (W)w);
4856 if (expect_false (!ev_is_active (w))) 4907 if (ecb_expect_false (!ev_is_active (w)))
4857 return; 4908 return;
4858 4909
4859 EV_FREQUENT_CHECK; 4910 EV_FREQUENT_CHECK;
4860 4911
4861 { 4912 {
4873 4924
4874#if EV_CLEANUP_ENABLE 4925#if EV_CLEANUP_ENABLE
4875void 4926void
4876ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4927ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4877{ 4928{
4878 if (expect_false (ev_is_active (w))) 4929 if (ecb_expect_false (ev_is_active (w)))
4879 return; 4930 return;
4880 4931
4881 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4882 4933
4883 ev_start (EV_A_ (W)w, ++cleanupcnt); 4934 ev_start (EV_A_ (W)w, ++cleanupcnt);
4884 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4935 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4885 cleanups [cleanupcnt - 1] = w; 4936 cleanups [cleanupcnt - 1] = w;
4886 4937
4887 /* cleanup watchers should never keep a refcount on the loop */ 4938 /* cleanup watchers should never keep a refcount on the loop */
4888 ev_unref (EV_A); 4939 ev_unref (EV_A);
4889 EV_FREQUENT_CHECK; 4940 EV_FREQUENT_CHECK;
4891 4942
4892void 4943void
4893ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT 4944ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4894{ 4945{
4895 clear_pending (EV_A_ (W)w); 4946 clear_pending (EV_A_ (W)w);
4896 if (expect_false (!ev_is_active (w))) 4947 if (ecb_expect_false (!ev_is_active (w)))
4897 return; 4948 return;
4898 4949
4899 EV_FREQUENT_CHECK; 4950 EV_FREQUENT_CHECK;
4900 ev_ref (EV_A); 4951 ev_ref (EV_A);
4901 4952
4914 4965
4915#if EV_ASYNC_ENABLE 4966#if EV_ASYNC_ENABLE
4916void 4967void
4917ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT 4968ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4918{ 4969{
4919 if (expect_false (ev_is_active (w))) 4970 if (ecb_expect_false (ev_is_active (w)))
4920 return; 4971 return;
4921 4972
4922 w->sent = 0; 4973 w->sent = 0;
4923 4974
4924 evpipe_init (EV_A); 4975 evpipe_init (EV_A);
4925 4976
4926 EV_FREQUENT_CHECK; 4977 EV_FREQUENT_CHECK;
4927 4978
4928 ev_start (EV_A_ (W)w, ++asynccnt); 4979 ev_start (EV_A_ (W)w, ++asynccnt);
4929 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4980 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4930 asyncs [asynccnt - 1] = w; 4981 asyncs [asynccnt - 1] = w;
4931 4982
4932 EV_FREQUENT_CHECK; 4983 EV_FREQUENT_CHECK;
4933} 4984}
4934 4985
4935void 4986void
4936ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT 4987ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4937{ 4988{
4938 clear_pending (EV_A_ (W)w); 4989 clear_pending (EV_A_ (W)w);
4939 if (expect_false (!ev_is_active (w))) 4990 if (ecb_expect_false (!ev_is_active (w)))
4940 return; 4991 return;
4941 4992
4942 EV_FREQUENT_CHECK; 4993 EV_FREQUENT_CHECK;
4943 4994
4944 { 4995 {
5002 5053
5003void 5054void
5004ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT 5055ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
5005{ 5056{
5006 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5057 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
5007
5008 if (expect_false (!once))
5009 {
5010 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
5011 return;
5012 }
5013 5058
5014 once->cb = cb; 5059 once->cb = cb;
5015 once->arg = arg; 5060 once->arg = arg;
5016 5061
5017 ev_init (&once->io, once_cb_io); 5062 ev_init (&once->io, once_cb_io);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines