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.496 by root, Mon Jun 24 22:27:29 2019 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
115# else 115# else
116# undef EV_USE_EPOLL 116# undef EV_USE_EPOLL
117# define EV_USE_EPOLL 0 117# define EV_USE_EPOLL 0
118# endif 118# endif
119 119
120# if HAVE_LINUX_AIO_ABI_H
121# ifndef EV_USE_LINUXAIO
122# define EV_USE_LINUXAIO EV_FEATURE_BACKENDS
123# endif
124# else
125# undef EV_USE_LINUXAIO
126# define EV_USE_LINUXAIO 0
127# endif
128
120# if HAVE_KQUEUE && HAVE_SYS_EVENT_H 129# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
121# ifndef EV_USE_KQUEUE 130# ifndef EV_USE_KQUEUE
122# define EV_USE_KQUEUE EV_FEATURE_BACKENDS 131# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
123# endif 132# endif
124# else 133# else
162# define EV_USE_EVENTFD 0 171# define EV_USE_EVENTFD 0
163# endif 172# endif
164 173
165#endif 174#endif
166 175
176/* OS X, in its infinite idiocy, actually HARDCODES
177 * a limit of 1024 into their select. Where people have brains,
178 * OS X engineers apparently have a vacuum. Or maybe they were
179 * ordered to have a vacuum, or they do anything for money.
180 * This might help. Or not.
181 * Note that this must be defined early, as other include files
182 * will rely on this define as well.
183 */
184#define _DARWIN_UNLIMITED_SELECT 1
185
167#include <stdlib.h> 186#include <stdlib.h>
168#include <string.h> 187#include <string.h>
169#include <fcntl.h> 188#include <fcntl.h>
170#include <stddef.h> 189#include <stddef.h>
171 190
208# ifndef EV_SELECT_IS_WINSOCKET 227# ifndef EV_SELECT_IS_WINSOCKET
209# define EV_SELECT_IS_WINSOCKET 1 228# define EV_SELECT_IS_WINSOCKET 1
210# endif 229# endif
211# undef EV_AVOID_STDIO 230# undef EV_AVOID_STDIO
212#endif 231#endif
213
214/* OS X, in its infinite idiocy, actually HARDCODES
215 * a limit of 1024 into their select. Where people have brains,
216 * OS X engineers apparently have a vacuum. Or maybe they were
217 * ordered to have a vacuum, or they do anything for money.
218 * This might help. Or not.
219 */
220#define _DARWIN_UNLIMITED_SELECT 1
221 232
222/* this block tries to deduce configuration from header-defined symbols and defaults */ 233/* this block tries to deduce configuration from header-defined symbols and defaults */
223 234
224/* try to deduce the maximum number of signals on this platform */ 235/* try to deduce the maximum number of signals on this platform */
225#if defined EV_NSIG 236#if defined EV_NSIG
313 324
314#ifndef EV_USE_PORT 325#ifndef EV_USE_PORT
315# define EV_USE_PORT 0 326# define EV_USE_PORT 0
316#endif 327#endif
317 328
329#ifndef EV_USE_LINUXAIO
330# if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */
331# define EV_USE_LINUXAIO 1
332# else
333# define EV_USE_LINUXAIO 0
334# endif
335#endif
336
318#ifndef EV_USE_INOTIFY 337#ifndef EV_USE_INOTIFY
319# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) 338# if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4))
320# define EV_USE_INOTIFY EV_FEATURE_OS 339# define EV_USE_INOTIFY EV_FEATURE_OS
321# else 340# else
322# define EV_USE_INOTIFY 0 341# define EV_USE_INOTIFY 0
363 382
364#ifndef EV_HEAP_CACHE_AT 383#ifndef EV_HEAP_CACHE_AT
365# define EV_HEAP_CACHE_AT EV_FEATURE_DATA 384# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
366#endif 385#endif
367 386
368#ifdef ANDROID 387#ifdef __ANDROID__
369/* supposedly, android doesn't typedef fd_mask */ 388/* supposedly, android doesn't typedef fd_mask */
370# undef EV_USE_SELECT 389# undef EV_USE_SELECT
371# define EV_USE_SELECT 0 390# define EV_USE_SELECT 0
372/* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ 391/* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */
373# undef EV_USE_CLOCK_SYSCALL 392# undef EV_USE_CLOCK_SYSCALL
414 433
415#if !EV_USE_NANOSLEEP 434#if !EV_USE_NANOSLEEP
416/* hp-ux has it in sys/time.h, which we unconditionally include above */ 435/* hp-ux has it in sys/time.h, which we unconditionally include above */
417# if !defined _WIN32 && !defined __hpux 436# if !defined _WIN32 && !defined __hpux
418# include <sys/select.h> 437# include <sys/select.h>
438# endif
439#endif
440
441#if EV_USE_LINUXAIO
442# include <sys/syscall.h>
443# if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */
444# undef EV_USE_LINUXAIO
445# define EV_USE_LINUXAIO 0
419# endif 446# endif
420#endif 447#endif
421 448
422#if EV_USE_INOTIFY 449#if EV_USE_INOTIFY
423# include <sys/statfs.h> 450# include <sys/statfs.h>
532 559
533#ifndef ECB_H 560#ifndef ECB_H
534#define ECB_H 561#define ECB_H
535 562
536/* 16 bits major, 16 bits minor */ 563/* 16 bits major, 16 bits minor */
537#define ECB_VERSION 0x00010005 564#define ECB_VERSION 0x00010006
538 565
539#ifdef _WIN32 566#ifdef _WIN32
540 typedef signed char int8_t; 567 typedef signed char int8_t;
541 typedef unsigned char uint8_t; 568 typedef unsigned char uint8_t;
542 typedef signed short int16_t; 569 typedef signed short int16_t;
607 #define ECB_CLANG_EXTENSION(x) 0 634 #define ECB_CLANG_EXTENSION(x) 0
608#endif 635#endif
609 636
610#define ECB_CPP (__cplusplus+0) 637#define ECB_CPP (__cplusplus+0)
611#define ECB_CPP11 (__cplusplus >= 201103L) 638#define ECB_CPP11 (__cplusplus >= 201103L)
639#define ECB_CPP14 (__cplusplus >= 201402L)
640#define ECB_CPP17 (__cplusplus >= 201703L)
612 641
613#if ECB_CPP 642#if ECB_CPP
614 #define ECB_C 0 643 #define ECB_C 0
615 #define ECB_STDC_VERSION 0 644 #define ECB_STDC_VERSION 0
616#else 645#else
618 #define ECB_STDC_VERSION __STDC_VERSION__ 647 #define ECB_STDC_VERSION __STDC_VERSION__
619#endif 648#endif
620 649
621#define ECB_C99 (ECB_STDC_VERSION >= 199901L) 650#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
622#define ECB_C11 (ECB_STDC_VERSION >= 201112L) 651#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
652#define ECB_C17 (ECB_STDC_VERSION >= 201710L)
623 653
624#if ECB_CPP 654#if ECB_CPP
625 #define ECB_EXTERN_C extern "C" 655 #define ECB_EXTERN_C extern "C"
626 #define ECB_EXTERN_C_BEG ECB_EXTERN_C { 656 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
627 #define ECB_EXTERN_C_END } 657 #define ECB_EXTERN_C_END }
653 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ 683 #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */
654#endif 684#endif
655 685
656#ifndef ECB_MEMORY_FENCE 686#ifndef ECB_MEMORY_FENCE
657 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 687 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
688 #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory")
658 #if __i386 || __i386__ 689 #if __i386 || __i386__
659 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 690 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
660 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 691 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
661 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 692 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
662 #elif ECB_GCC_AMD64 693 #elif ECB_GCC_AMD64
663 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 694 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
664 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 695 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
665 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 696 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
666 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 697 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
667 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 698 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
668 #elif defined __ARM_ARCH_2__ \ 699 #elif defined __ARM_ARCH_2__ \
669 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ 700 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
670 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ 701 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
712 #if ECB_GCC_VERSION(4,7) 743 #if ECB_GCC_VERSION(4,7)
713 /* see comment below (stdatomic.h) about the C11 memory model. */ 744 /* see comment below (stdatomic.h) about the C11 memory model. */
714 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) 745 #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST)
715 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) 746 #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE)
716 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) 747 #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE)
748 #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED)
717 749
718 #elif ECB_CLANG_EXTENSION(c_atomic) 750 #elif ECB_CLANG_EXTENSION(c_atomic)
719 /* see comment below (stdatomic.h) about the C11 memory model. */ 751 /* see comment below (stdatomic.h) about the C11 memory model. */
720 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) 752 #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST)
721 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) 753 #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE)
722 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) 754 #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE)
755 #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED)
723 756
724 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ 757 #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
725 #define ECB_MEMORY_FENCE __sync_synchronize () 758 #define ECB_MEMORY_FENCE __sync_synchronize ()
726 #elif _MSC_VER >= 1500 /* VC++ 2008 */ 759 #elif _MSC_VER >= 1500 /* VC++ 2008 */
727 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ 760 /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */
737 #elif defined _WIN32 770 #elif defined _WIN32
738 #include <WinNT.h> 771 #include <WinNT.h>
739 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 772 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
740 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 773 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
741 #include <mbarrier.h> 774 #include <mbarrier.h>
742 #define ECB_MEMORY_FENCE __machine_rw_barrier () 775 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
743 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 776 #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier ()
744 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 777 #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier ()
778 #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier ()
745 #elif __xlC__ 779 #elif __xlC__
746 #define ECB_MEMORY_FENCE __sync () 780 #define ECB_MEMORY_FENCE __sync ()
747 #endif 781 #endif
748#endif 782#endif
749 783
750#ifndef ECB_MEMORY_FENCE 784#ifndef ECB_MEMORY_FENCE
751 #if ECB_C11 && !defined __STDC_NO_ATOMICS__ 785 #if ECB_C11 && !defined __STDC_NO_ATOMICS__
752 /* we assume that these memory fences work on all variables/all memory accesses, */ 786 /* we assume that these memory fences work on all variables/all memory accesses, */
753 /* not just C11 atomics and atomic accesses */ 787 /* not just C11 atomics and atomic accesses */
754 #include <stdatomic.h> 788 #include <stdatomic.h>
755 /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */
756 /* any fence other than seq_cst, which isn't very efficient for us. */
757 /* Why that is, we don't know - either the C11 memory model is quite useless */
758 /* for most usages, or gcc and clang have a bug */
759 /* I *currently* lean towards the latter, and inefficiently implement */
760 /* all three of ecb's fences as a seq_cst fence */
761 /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */
762 /* for all __atomic_thread_fence's except seq_cst */
763 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) 789 #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst)
790 #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire)
791 #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release)
764 #endif 792 #endif
765#endif 793#endif
766 794
767#ifndef ECB_MEMORY_FENCE 795#ifndef ECB_MEMORY_FENCE
768 #if !ECB_AVOID_PTHREADS 796 #if !ECB_AVOID_PTHREADS
786 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 814 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
787#endif 815#endif
788 816
789#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE 817#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
790 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 818 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
819#endif
820
821#if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE
822 #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */
791#endif 823#endif
792 824
793/*****************************************************************************/ 825/*****************************************************************************/
794 826
795#if ECB_CPP 827#if ECB_CPP
1527#define inline_size ecb_inline 1559#define inline_size ecb_inline
1528 1560
1529#if EV_FEATURE_CODE 1561#if EV_FEATURE_CODE
1530# define inline_speed ecb_inline 1562# define inline_speed ecb_inline
1531#else 1563#else
1532# define inline_speed static noinline 1564# define inline_speed noinline static
1533#endif 1565#endif
1534 1566
1535#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) 1567#define NUMPRI (EV_MAXPRI - EV_MINPRI + 1)
1536 1568
1537#if EV_MINPRI == EV_MAXPRI 1569#if EV_MINPRI == EV_MAXPRI
1538# define ABSPRI(w) (((W)w), 0) 1570# define ABSPRI(w) (((W)w), 0)
1539#else 1571#else
1540# define ABSPRI(w) (((W)w)->priority - EV_MINPRI) 1572# define ABSPRI(w) (((W)w)->priority - EV_MINPRI)
1541#endif 1573#endif
1542 1574
1543#define EMPTY /* required for microsofts broken pseudo-c compiler */ 1575#define EMPTY /* required for microsofts broken pseudo-c compiler */
1544#define EMPTY2(a,b) /* used to suppress some warnings */
1545 1576
1546typedef ev_watcher *W; 1577typedef ev_watcher *W;
1547typedef ev_watcher_list *WL; 1578typedef ev_watcher_list *WL;
1548typedef ev_watcher_time *WT; 1579typedef ev_watcher_time *WT;
1549 1580
1574# include "ev_win32.c" 1605# include "ev_win32.c"
1575#endif 1606#endif
1576 1607
1577/*****************************************************************************/ 1608/*****************************************************************************/
1578 1609
1610#if EV_USE_LINUXAIO
1611# include <linux/aio_abi.h> /* probably only needed for aio_context_t */
1612#endif
1613
1579/* define a suitable floor function (only used by periodics atm) */ 1614/* define a suitable floor function (only used by periodics atm) */
1580 1615
1581#if EV_USE_FLOOR 1616#if EV_USE_FLOOR
1582# include <math.h> 1617# include <math.h>
1583# define ev_floor(v) floor (v) 1618# define ev_floor(v) floor (v)
1584#else 1619#else
1585 1620
1586#include <float.h> 1621#include <float.h>
1587 1622
1588/* a floor() replacement function, should be independent of ev_tstamp type */ 1623/* a floor() replacement function, should be independent of ev_tstamp type */
1624noinline
1589static ev_tstamp noinline 1625static ev_tstamp
1590ev_floor (ev_tstamp v) 1626ev_floor (ev_tstamp v)
1591{ 1627{
1592 /* the choice of shift factor is not terribly important */ 1628 /* the choice of shift factor is not terribly important */
1593#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ 1629#if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */
1594 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; 1630 const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.;
1626 1662
1627#ifdef __linux 1663#ifdef __linux
1628# include <sys/utsname.h> 1664# include <sys/utsname.h>
1629#endif 1665#endif
1630 1666
1631static unsigned int noinline ecb_cold 1667noinline ecb_cold
1668static unsigned int
1632ev_linux_version (void) 1669ev_linux_version (void)
1633{ 1670{
1634#ifdef __linux 1671#ifdef __linux
1635 unsigned int v = 0; 1672 unsigned int v = 0;
1636 struct utsname buf; 1673 struct utsname buf;
1665} 1702}
1666 1703
1667/*****************************************************************************/ 1704/*****************************************************************************/
1668 1705
1669#if EV_AVOID_STDIO 1706#if EV_AVOID_STDIO
1670static void noinline ecb_cold 1707noinline ecb_cold
1708static void
1671ev_printerr (const char *msg) 1709ev_printerr (const char *msg)
1672{ 1710{
1673 write (STDERR_FILENO, msg, strlen (msg)); 1711 write (STDERR_FILENO, msg, strlen (msg));
1674} 1712}
1675#endif 1713#endif
1676 1714
1677static void (*syserr_cb)(const char *msg) EV_THROW; 1715static void (*syserr_cb)(const char *msg) EV_NOEXCEPT;
1678 1716
1679void ecb_cold 1717ecb_cold
1718void
1680ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW 1719ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1681{ 1720{
1682 syserr_cb = cb; 1721 syserr_cb = cb;
1683} 1722}
1684 1723
1685static void noinline ecb_cold 1724noinline ecb_cold
1725static void
1686ev_syserr (const char *msg) 1726ev_syserr (const char *msg)
1687{ 1727{
1688 if (!msg) 1728 if (!msg)
1689 msg = "(libev) system error"; 1729 msg = "(libev) system error";
1690 1730
1703 abort (); 1743 abort ();
1704 } 1744 }
1705} 1745}
1706 1746
1707static void * 1747static void *
1708ev_realloc_emul (void *ptr, long size) EV_THROW 1748ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT
1709{ 1749{
1710 /* some systems, notably openbsd and darwin, fail to properly 1750 /* some systems, notably openbsd and darwin, fail to properly
1711 * implement realloc (x, 0) (as required by both ansi c-89 and 1751 * implement realloc (x, 0) (as required by both ansi c-89 and
1712 * the single unix specification, so work around them here. 1752 * the single unix specification, so work around them here.
1713 * recently, also (at least) fedora and debian started breaking it, 1753 * recently, also (at least) fedora and debian started breaking it,
1719 1759
1720 free (ptr); 1760 free (ptr);
1721 return 0; 1761 return 0;
1722} 1762}
1723 1763
1724static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1764static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul;
1725 1765
1726void ecb_cold 1766ecb_cold
1767void
1727ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW 1768ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT
1728{ 1769{
1729 alloc = cb; 1770 alloc = cb;
1730} 1771}
1731 1772
1732inline_speed void * 1773inline_speed void *
1759typedef struct 1800typedef struct
1760{ 1801{
1761 WL head; 1802 WL head;
1762 unsigned char events; /* the events watched for */ 1803 unsigned char events; /* the events watched for */
1763 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ 1804 unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */
1764 unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ 1805 unsigned char emask; /* some backends store the actual kernel mask in here */
1765 unsigned char unused; 1806 unsigned char unused;
1766#if EV_USE_EPOLL 1807#if EV_USE_EPOLL
1767 unsigned int egen; /* generation counter to counter epoll bugs */ 1808 unsigned int egen; /* generation counter to counter epoll bugs */
1768#endif 1809#endif
1769#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP 1810#if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP
1849 1890
1850/*****************************************************************************/ 1891/*****************************************************************************/
1851 1892
1852#ifndef EV_HAVE_EV_TIME 1893#ifndef EV_HAVE_EV_TIME
1853ev_tstamp 1894ev_tstamp
1854ev_time (void) EV_THROW 1895ev_time (void) EV_NOEXCEPT
1855{ 1896{
1856#if EV_USE_REALTIME 1897#if EV_USE_REALTIME
1857 if (expect_true (have_realtime)) 1898 if (expect_true (have_realtime))
1858 { 1899 {
1859 struct timespec ts; 1900 struct timespec ts;
1883 return ev_time (); 1924 return ev_time ();
1884} 1925}
1885 1926
1886#if EV_MULTIPLICITY 1927#if EV_MULTIPLICITY
1887ev_tstamp 1928ev_tstamp
1888ev_now (EV_P) EV_THROW 1929ev_now (EV_P) EV_NOEXCEPT
1889{ 1930{
1890 return ev_rt_now; 1931 return ev_rt_now;
1891} 1932}
1892#endif 1933#endif
1893 1934
1894void 1935void
1895ev_sleep (ev_tstamp delay) EV_THROW 1936ev_sleep (ev_tstamp delay) EV_NOEXCEPT
1896{ 1937{
1897 if (delay > 0.) 1938 if (delay > 0.)
1898 { 1939 {
1899#if EV_USE_NANOSLEEP 1940#if EV_USE_NANOSLEEP
1900 struct timespec ts; 1941 struct timespec ts;
1901 1942
1902 EV_TS_SET (ts, delay); 1943 EV_TS_SET (ts, delay);
1903 nanosleep (&ts, 0); 1944 nanosleep (&ts, 0);
1904#elif defined _WIN32 1945#elif defined _WIN32
1946 /* maybe this should round up, as ms is very low resolution */
1947 /* compared to select (µs) or nanosleep (ns) */
1905 Sleep ((unsigned long)(delay * 1e3)); 1948 Sleep ((unsigned long)(delay * 1e3));
1906#else 1949#else
1907 struct timeval tv; 1950 struct timeval tv;
1908 1951
1909 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ 1952 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
1940 } 1983 }
1941 1984
1942 return ncur; 1985 return ncur;
1943} 1986}
1944 1987
1945static void * noinline ecb_cold 1988noinline ecb_cold
1989static void *
1946array_realloc (int elem, void *base, int *cur, int cnt) 1990array_realloc (int elem, void *base, int *cur, int cnt)
1947{ 1991{
1948 *cur = array_nextsize (elem, *cur, cnt); 1992 *cur = array_nextsize (elem, *cur, cnt);
1949 return ev_realloc (base, elem * *cur); 1993 return ev_realloc (base, elem * *cur);
1950} 1994}
1951 1995
1996#define array_needsize_noinit(base,offset,count)
1997
1952#define array_init_zero(base,count) \ 1998#define array_needsize_zerofill(base,offset,count) \
1953 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1999 memset ((void *)(base + offset), 0, sizeof (*(base)) * (count))
1954 2000
1955#define array_needsize(type,base,cur,cnt,init) \ 2001#define array_needsize(type,base,cur,cnt,init) \
1956 if (expect_false ((cnt) > (cur))) \ 2002 if (expect_false ((cnt) > (cur))) \
1957 { \ 2003 { \
1958 int ecb_unused ocur_ = (cur); \ 2004 ecb_unused int ocur_ = (cur); \
1959 (base) = (type *)array_realloc \ 2005 (base) = (type *)array_realloc \
1960 (sizeof (type), (base), &(cur), (cnt)); \ 2006 (sizeof (type), (base), &(cur), (cnt)); \
1961 init ((base) + (ocur_), (cur) - ocur_); \ 2007 init ((base), ocur_, ((cur) - ocur_)); \
1962 } 2008 }
1963 2009
1964#if 0 2010#if 0
1965#define array_slim(type,stem) \ 2011#define array_slim(type,stem) \
1966 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ 2012 if (stem ## max < array_roundsize (stem ## cnt >> 2)) \
1975 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 2021 ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0
1976 2022
1977/*****************************************************************************/ 2023/*****************************************************************************/
1978 2024
1979/* dummy callback for pending events */ 2025/* dummy callback for pending events */
1980static void noinline 2026noinline
2027static void
1981pendingcb (EV_P_ ev_prepare *w, int revents) 2028pendingcb (EV_P_ ev_prepare *w, int revents)
1982{ 2029{
1983} 2030}
1984 2031
1985void noinline 2032noinline
2033void
1986ev_feed_event (EV_P_ void *w, int revents) EV_THROW 2034ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
1987{ 2035{
1988 W w_ = (W)w; 2036 W w_ = (W)w;
1989 int pri = ABSPRI (w_); 2037 int pri = ABSPRI (w_);
1990 2038
1991 if (expect_false (w_->pending)) 2039 if (expect_false (w_->pending))
1992 pendings [pri][w_->pending - 1].events |= revents; 2040 pendings [pri][w_->pending - 1].events |= revents;
1993 else 2041 else
1994 { 2042 {
1995 w_->pending = ++pendingcnt [pri]; 2043 w_->pending = ++pendingcnt [pri];
1996 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 2044 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit);
1997 pendings [pri][w_->pending - 1].w = w_; 2045 pendings [pri][w_->pending - 1].w = w_;
1998 pendings [pri][w_->pending - 1].events = revents; 2046 pendings [pri][w_->pending - 1].events = revents;
1999 } 2047 }
2000 2048
2001 pendingpri = NUMPRI - 1; 2049 pendingpri = NUMPRI - 1;
2002} 2050}
2003 2051
2004inline_speed void 2052inline_speed void
2005feed_reverse (EV_P_ W w) 2053feed_reverse (EV_P_ W w)
2006{ 2054{
2007 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); 2055 array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit);
2008 rfeeds [rfeedcnt++] = w; 2056 rfeeds [rfeedcnt++] = w;
2009} 2057}
2010 2058
2011inline_size void 2059inline_size void
2012feed_reverse_done (EV_P_ int revents) 2060feed_reverse_done (EV_P_ int revents)
2052 if (expect_true (!anfd->reify)) 2100 if (expect_true (!anfd->reify))
2053 fd_event_nocheck (EV_A_ fd, revents); 2101 fd_event_nocheck (EV_A_ fd, revents);
2054} 2102}
2055 2103
2056void 2104void
2057ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW 2105ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2058{ 2106{
2059 if (fd >= 0 && fd < anfdmax) 2107 if (fd >= 0 && fd < anfdmax)
2060 fd_event_nocheck (EV_A_ fd, revents); 2108 fd_event_nocheck (EV_A_ fd, revents);
2061} 2109}
2062 2110
2120 2168
2121 fdchangecnt = 0; 2169 fdchangecnt = 0;
2122} 2170}
2123 2171
2124/* something about the given fd changed */ 2172/* something about the given fd changed */
2125inline_size void 2173inline_size
2174void
2126fd_change (EV_P_ int fd, int flags) 2175fd_change (EV_P_ int fd, int flags)
2127{ 2176{
2128 unsigned char reify = anfds [fd].reify; 2177 unsigned char reify = anfds [fd].reify;
2129 anfds [fd].reify |= flags; 2178 anfds [fd].reify |= flags;
2130 2179
2131 if (expect_true (!reify)) 2180 if (expect_true (!reify))
2132 { 2181 {
2133 ++fdchangecnt; 2182 ++fdchangecnt;
2134 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); 2183 array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit);
2135 fdchanges [fdchangecnt - 1] = fd; 2184 fdchanges [fdchangecnt - 1] = fd;
2136 } 2185 }
2137} 2186}
2138 2187
2139/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ 2188/* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */
2140inline_speed void ecb_cold 2189inline_speed ecb_cold void
2141fd_kill (EV_P_ int fd) 2190fd_kill (EV_P_ int fd)
2142{ 2191{
2143 ev_io *w; 2192 ev_io *w;
2144 2193
2145 while ((w = (ev_io *)anfds [fd].head)) 2194 while ((w = (ev_io *)anfds [fd].head))
2148 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); 2197 ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE);
2149 } 2198 }
2150} 2199}
2151 2200
2152/* check whether the given fd is actually valid, for error recovery */ 2201/* check whether the given fd is actually valid, for error recovery */
2153inline_size int ecb_cold 2202inline_size ecb_cold int
2154fd_valid (int fd) 2203fd_valid (int fd)
2155{ 2204{
2156#ifdef _WIN32 2205#ifdef _WIN32
2157 return EV_FD_TO_WIN32_HANDLE (fd) != -1; 2206 return EV_FD_TO_WIN32_HANDLE (fd) != -1;
2158#else 2207#else
2159 return fcntl (fd, F_GETFD) != -1; 2208 return fcntl (fd, F_GETFD) != -1;
2160#endif 2209#endif
2161} 2210}
2162 2211
2163/* called on EBADF to verify fds */ 2212/* called on EBADF to verify fds */
2164static void noinline ecb_cold 2213noinline ecb_cold
2214static void
2165fd_ebadf (EV_P) 2215fd_ebadf (EV_P)
2166{ 2216{
2167 int fd; 2217 int fd;
2168 2218
2169 for (fd = 0; fd < anfdmax; ++fd) 2219 for (fd = 0; fd < anfdmax; ++fd)
2171 if (!fd_valid (fd) && errno == EBADF) 2221 if (!fd_valid (fd) && errno == EBADF)
2172 fd_kill (EV_A_ fd); 2222 fd_kill (EV_A_ fd);
2173} 2223}
2174 2224
2175/* called on ENOMEM in select/poll to kill some fds and retry */ 2225/* called on ENOMEM in select/poll to kill some fds and retry */
2176static void noinline ecb_cold 2226noinline ecb_cold
2227static void
2177fd_enomem (EV_P) 2228fd_enomem (EV_P)
2178{ 2229{
2179 int fd; 2230 int fd;
2180 2231
2181 for (fd = anfdmax; fd--; ) 2232 for (fd = anfdmax; fd--; )
2185 break; 2236 break;
2186 } 2237 }
2187} 2238}
2188 2239
2189/* usually called after fork if backend needs to re-arm all fds from scratch */ 2240/* usually called after fork if backend needs to re-arm all fds from scratch */
2190static void noinline 2241noinline
2242static void
2191fd_rearm_all (EV_P) 2243fd_rearm_all (EV_P)
2192{ 2244{
2193 int fd; 2245 int fd;
2194 2246
2195 for (fd = 0; fd < anfdmax; ++fd) 2247 for (fd = 0; fd < anfdmax; ++fd)
2376 2428
2377/*****************************************************************************/ 2429/*****************************************************************************/
2378 2430
2379#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2431#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2380 2432
2381static void noinline ecb_cold 2433noinline ecb_cold
2434static void
2382evpipe_init (EV_P) 2435evpipe_init (EV_P)
2383{ 2436{
2384 if (!ev_is_active (&pipe_w)) 2437 if (!ev_is_active (&pipe_w))
2385 { 2438 {
2386 int fds [2]; 2439 int fds [2];
2457#endif 2510#endif
2458 { 2511 {
2459#ifdef _WIN32 2512#ifdef _WIN32
2460 WSABUF buf; 2513 WSABUF buf;
2461 DWORD sent; 2514 DWORD sent;
2462 buf.buf = &buf; 2515 buf.buf = (char *)&buf;
2463 buf.len = 1; 2516 buf.len = 1;
2464 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); 2517 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
2465#else 2518#else
2466 write (evpipe [1], &(evpipe [1]), 1); 2519 write (evpipe [1], &(evpipe [1]), 1);
2467#endif 2520#endif
2539} 2592}
2540 2593
2541/*****************************************************************************/ 2594/*****************************************************************************/
2542 2595
2543void 2596void
2544ev_feed_signal (int signum) EV_THROW 2597ev_feed_signal (int signum) EV_NOEXCEPT
2545{ 2598{
2546#if EV_MULTIPLICITY 2599#if EV_MULTIPLICITY
2547 EV_P; 2600 EV_P;
2548 ECB_MEMORY_FENCE_ACQUIRE; 2601 ECB_MEMORY_FENCE_ACQUIRE;
2549 EV_A = signals [signum - 1].loop; 2602 EV_A = signals [signum - 1].loop;
2564#endif 2617#endif
2565 2618
2566 ev_feed_signal (signum); 2619 ev_feed_signal (signum);
2567} 2620}
2568 2621
2569void noinline 2622noinline
2623void
2570ev_feed_signal_event (EV_P_ int signum) EV_THROW 2624ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2571{ 2625{
2572 WL w; 2626 WL w;
2573 2627
2574 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2628 if (expect_false (signum <= 0 || signum >= EV_NSIG))
2575 return; 2629 return;
2684# include "ev_kqueue.c" 2738# include "ev_kqueue.c"
2685#endif 2739#endif
2686#if EV_USE_EPOLL 2740#if EV_USE_EPOLL
2687# include "ev_epoll.c" 2741# include "ev_epoll.c"
2688#endif 2742#endif
2743#if EV_USE_LINUXAIO
2744# include "ev_linuxaio.c"
2745#endif
2689#if EV_USE_POLL 2746#if EV_USE_POLL
2690# include "ev_poll.c" 2747# include "ev_poll.c"
2691#endif 2748#endif
2692#if EV_USE_SELECT 2749#if EV_USE_SELECT
2693# include "ev_select.c" 2750# include "ev_select.c"
2694#endif 2751#endif
2695 2752
2696int ecb_cold 2753ecb_cold int
2697ev_version_major (void) EV_THROW 2754ev_version_major (void) EV_NOEXCEPT
2698{ 2755{
2699 return EV_VERSION_MAJOR; 2756 return EV_VERSION_MAJOR;
2700} 2757}
2701 2758
2702int ecb_cold 2759ecb_cold int
2703ev_version_minor (void) EV_THROW 2760ev_version_minor (void) EV_NOEXCEPT
2704{ 2761{
2705 return EV_VERSION_MINOR; 2762 return EV_VERSION_MINOR;
2706} 2763}
2707 2764
2708/* return true if we are running with elevated privileges and should ignore env variables */ 2765/* return true if we are running with elevated privileges and should ignore env variables */
2709int inline_size ecb_cold 2766inline_size ecb_cold int
2710enable_secure (void) 2767enable_secure (void)
2711{ 2768{
2712#ifdef _WIN32 2769#ifdef _WIN32
2713 return 0; 2770 return 0;
2714#else 2771#else
2715 return getuid () != geteuid () 2772 return getuid () != geteuid ()
2716 || getgid () != getegid (); 2773 || getgid () != getegid ();
2717#endif 2774#endif
2718} 2775}
2719 2776
2720unsigned int ecb_cold 2777ecb_cold
2778unsigned int
2721ev_supported_backends (void) EV_THROW 2779ev_supported_backends (void) EV_NOEXCEPT
2722{ 2780{
2723 unsigned int flags = 0; 2781 unsigned int flags = 0;
2724 2782
2725 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2783 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2726 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2784 if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE;
2727 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; 2785 if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL;
2786 if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO;
2728 if (EV_USE_POLL ) flags |= EVBACKEND_POLL; 2787 if (EV_USE_POLL ) flags |= EVBACKEND_POLL;
2729 if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; 2788 if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT;
2730 2789
2731 return flags; 2790 return flags;
2732} 2791}
2733 2792
2734unsigned int ecb_cold 2793ecb_cold
2794unsigned int
2735ev_recommended_backends (void) EV_THROW 2795ev_recommended_backends (void) EV_NOEXCEPT
2736{ 2796{
2737 unsigned int flags = ev_supported_backends (); 2797 unsigned int flags = ev_supported_backends ();
2738 2798
2739#ifndef __NetBSD__ 2799#ifndef __NetBSD__
2740 /* kqueue is borked on everything but netbsd apparently */ 2800 /* kqueue is borked on everything but netbsd apparently */
2748#endif 2808#endif
2749#ifdef __FreeBSD__ 2809#ifdef __FreeBSD__
2750 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ 2810 flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */
2751#endif 2811#endif
2752 2812
2813 /* TODO: linuxaio is very experimental */
2814#if !EV_RECOMMEND_LINUXAIO
2815 flags &= ~EVBACKEND_LINUXAIO;
2816#endif
2817
2753 return flags; 2818 return flags;
2754} 2819}
2755 2820
2756unsigned int ecb_cold 2821ecb_cold
2822unsigned int
2757ev_embeddable_backends (void) EV_THROW 2823ev_embeddable_backends (void) EV_NOEXCEPT
2758{ 2824{
2759 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2825 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2760 2826
2761 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2827 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2762 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2828 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2764 2830
2765 return flags; 2831 return flags;
2766} 2832}
2767 2833
2768unsigned int 2834unsigned int
2769ev_backend (EV_P) EV_THROW 2835ev_backend (EV_P) EV_NOEXCEPT
2770{ 2836{
2771 return backend; 2837 return backend;
2772} 2838}
2773 2839
2774#if EV_FEATURE_API 2840#if EV_FEATURE_API
2775unsigned int 2841unsigned int
2776ev_iteration (EV_P) EV_THROW 2842ev_iteration (EV_P) EV_NOEXCEPT
2777{ 2843{
2778 return loop_count; 2844 return loop_count;
2779} 2845}
2780 2846
2781unsigned int 2847unsigned int
2782ev_depth (EV_P) EV_THROW 2848ev_depth (EV_P) EV_NOEXCEPT
2783{ 2849{
2784 return loop_depth; 2850 return loop_depth;
2785} 2851}
2786 2852
2787void 2853void
2788ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2854ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2789{ 2855{
2790 io_blocktime = interval; 2856 io_blocktime = interval;
2791} 2857}
2792 2858
2793void 2859void
2794ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2860ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2795{ 2861{
2796 timeout_blocktime = interval; 2862 timeout_blocktime = interval;
2797} 2863}
2798 2864
2799void 2865void
2800ev_set_userdata (EV_P_ void *data) EV_THROW 2866ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT
2801{ 2867{
2802 userdata = data; 2868 userdata = data;
2803} 2869}
2804 2870
2805void * 2871void *
2806ev_userdata (EV_P) EV_THROW 2872ev_userdata (EV_P) EV_NOEXCEPT
2807{ 2873{
2808 return userdata; 2874 return userdata;
2809} 2875}
2810 2876
2811void 2877void
2812ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW 2878ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT
2813{ 2879{
2814 invoke_cb = invoke_pending_cb; 2880 invoke_cb = invoke_pending_cb;
2815} 2881}
2816 2882
2817void 2883void
2818ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW 2884ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT
2819{ 2885{
2820 release_cb = release; 2886 release_cb = release;
2821 acquire_cb = acquire; 2887 acquire_cb = acquire;
2822} 2888}
2823#endif 2889#endif
2824 2890
2825/* initialise a loop structure, must be zero-initialised */ 2891/* initialise a loop structure, must be zero-initialised */
2826static void noinline ecb_cold 2892noinline ecb_cold
2893static void
2827loop_init (EV_P_ unsigned int flags) EV_THROW 2894loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2828{ 2895{
2829 if (!backend) 2896 if (!backend)
2830 { 2897 {
2831 origflags = flags; 2898 origflags = flags;
2832 2899
2890 2957
2891 if (!(flags & EVBACKEND_MASK)) 2958 if (!(flags & EVBACKEND_MASK))
2892 flags |= ev_recommended_backends (); 2959 flags |= ev_recommended_backends ();
2893 2960
2894#if EV_USE_IOCP 2961#if EV_USE_IOCP
2895 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); 2962 if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags);
2896#endif 2963#endif
2897#if EV_USE_PORT 2964#if EV_USE_PORT
2898 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); 2965 if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags);
2899#endif 2966#endif
2900#if EV_USE_KQUEUE 2967#if EV_USE_KQUEUE
2901 if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); 2968 if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags);
2969#endif
2970#if EV_USE_LINUXAIO
2971 if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags);
2902#endif 2972#endif
2903#if EV_USE_EPOLL 2973#if EV_USE_EPOLL
2904 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); 2974 if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags);
2905#endif 2975#endif
2906#if EV_USE_POLL 2976#if EV_USE_POLL
2907 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); 2977 if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags);
2908#endif 2978#endif
2909#if EV_USE_SELECT 2979#if EV_USE_SELECT
2910 if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); 2980 if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags);
2911#endif 2981#endif
2912 2982
2913 ev_prepare_init (&pending_w, pendingcb); 2983 ev_prepare_init (&pending_w, pendingcb);
2914 2984
2915#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE 2985#if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE
2918#endif 2988#endif
2919 } 2989 }
2920} 2990}
2921 2991
2922/* free up a loop structure */ 2992/* free up a loop structure */
2923void ecb_cold 2993ecb_cold
2994void
2924ev_loop_destroy (EV_P) 2995ev_loop_destroy (EV_P)
2925{ 2996{
2926 int i; 2997 int i;
2927 2998
2928#if EV_MULTIPLICITY 2999#if EV_MULTIPLICITY
2969 3040
2970 if (backend_fd >= 0) 3041 if (backend_fd >= 0)
2971 close (backend_fd); 3042 close (backend_fd);
2972 3043
2973#if EV_USE_IOCP 3044#if EV_USE_IOCP
2974 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); 3045 if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A);
2975#endif 3046#endif
2976#if EV_USE_PORT 3047#if EV_USE_PORT
2977 if (backend == EVBACKEND_PORT ) port_destroy (EV_A); 3048 if (backend == EVBACKEND_PORT ) port_destroy (EV_A);
2978#endif 3049#endif
2979#if EV_USE_KQUEUE 3050#if EV_USE_KQUEUE
2980 if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); 3051 if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A);
3052#endif
3053#if EV_USE_LINUXAIO
3054 if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A);
2981#endif 3055#endif
2982#if EV_USE_EPOLL 3056#if EV_USE_EPOLL
2983 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); 3057 if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A);
2984#endif 3058#endif
2985#if EV_USE_POLL 3059#if EV_USE_POLL
2986 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); 3060 if (backend == EVBACKEND_POLL ) poll_destroy (EV_A);
2987#endif 3061#endif
2988#if EV_USE_SELECT 3062#if EV_USE_SELECT
2989 if (backend == EVBACKEND_SELECT) select_destroy (EV_A); 3063 if (backend == EVBACKEND_SELECT ) select_destroy (EV_A);
2990#endif 3064#endif
2991 3065
2992 for (i = NUMPRI; i--; ) 3066 for (i = NUMPRI; i--; )
2993 { 3067 {
2994 array_free (pending, [i]); 3068 array_free (pending, [i]);
3036 3110
3037inline_size void 3111inline_size void
3038loop_fork (EV_P) 3112loop_fork (EV_P)
3039{ 3113{
3040#if EV_USE_PORT 3114#if EV_USE_PORT
3041 if (backend == EVBACKEND_PORT ) port_fork (EV_A); 3115 if (backend == EVBACKEND_PORT ) port_fork (EV_A);
3042#endif 3116#endif
3043#if EV_USE_KQUEUE 3117#if EV_USE_KQUEUE
3044 if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); 3118 if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A);
3119#endif
3120#if EV_USE_LINUXAIO
3121 if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A);
3045#endif 3122#endif
3046#if EV_USE_EPOLL 3123#if EV_USE_EPOLL
3047 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); 3124 if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A);
3048#endif 3125#endif
3049#if EV_USE_INOTIFY 3126#if EV_USE_INOTIFY
3050 infy_fork (EV_A); 3127 infy_fork (EV_A);
3051#endif 3128#endif
3052 3129
3070 postfork = 0; 3147 postfork = 0;
3071} 3148}
3072 3149
3073#if EV_MULTIPLICITY 3150#if EV_MULTIPLICITY
3074 3151
3152ecb_cold
3075struct ev_loop * ecb_cold 3153struct ev_loop *
3076ev_loop_new (unsigned int flags) EV_THROW 3154ev_loop_new (unsigned int flags) EV_NOEXCEPT
3077{ 3155{
3078 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 3156 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
3079 3157
3080 memset (EV_A, 0, sizeof (struct ev_loop)); 3158 memset (EV_A, 0, sizeof (struct ev_loop));
3081 loop_init (EV_A_ flags); 3159 loop_init (EV_A_ flags);
3088} 3166}
3089 3167
3090#endif /* multiplicity */ 3168#endif /* multiplicity */
3091 3169
3092#if EV_VERIFY 3170#if EV_VERIFY
3093static void noinline ecb_cold 3171noinline ecb_cold
3172static void
3094verify_watcher (EV_P_ W w) 3173verify_watcher (EV_P_ W w)
3095{ 3174{
3096 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); 3175 assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI));
3097 3176
3098 if (w->pending) 3177 if (w->pending)
3099 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); 3178 assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w));
3100} 3179}
3101 3180
3102static void noinline ecb_cold 3181noinline ecb_cold
3182static void
3103verify_heap (EV_P_ ANHE *heap, int N) 3183verify_heap (EV_P_ ANHE *heap, int N)
3104{ 3184{
3105 int i; 3185 int i;
3106 3186
3107 for (i = HEAP0; i < N + HEAP0; ++i) 3187 for (i = HEAP0; i < N + HEAP0; ++i)
3112 3192
3113 verify_watcher (EV_A_ (W)ANHE_w (heap [i])); 3193 verify_watcher (EV_A_ (W)ANHE_w (heap [i]));
3114 } 3194 }
3115} 3195}
3116 3196
3117static void noinline ecb_cold 3197noinline ecb_cold
3198static void
3118array_verify (EV_P_ W *ws, int cnt) 3199array_verify (EV_P_ W *ws, int cnt)
3119{ 3200{
3120 while (cnt--) 3201 while (cnt--)
3121 { 3202 {
3122 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); 3203 assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1));
3125} 3206}
3126#endif 3207#endif
3127 3208
3128#if EV_FEATURE_API 3209#if EV_FEATURE_API
3129void ecb_cold 3210void ecb_cold
3130ev_verify (EV_P) EV_THROW 3211ev_verify (EV_P) EV_NOEXCEPT
3131{ 3212{
3132#if EV_VERIFY 3213#if EV_VERIFY
3133 int i; 3214 int i;
3134 WL w, w2; 3215 WL w, w2;
3135 3216
3211#endif 3292#endif
3212} 3293}
3213#endif 3294#endif
3214 3295
3215#if EV_MULTIPLICITY 3296#if EV_MULTIPLICITY
3297ecb_cold
3216struct ev_loop * ecb_cold 3298struct ev_loop *
3217#else 3299#else
3218int 3300int
3219#endif 3301#endif
3220ev_default_loop (unsigned int flags) EV_THROW 3302ev_default_loop (unsigned int flags) EV_NOEXCEPT
3221{ 3303{
3222 if (!ev_default_loop_ptr) 3304 if (!ev_default_loop_ptr)
3223 { 3305 {
3224#if EV_MULTIPLICITY 3306#if EV_MULTIPLICITY
3225 EV_P = ev_default_loop_ptr = &default_loop_struct; 3307 EV_P = ev_default_loop_ptr = &default_loop_struct;
3244 3326
3245 return ev_default_loop_ptr; 3327 return ev_default_loop_ptr;
3246} 3328}
3247 3329
3248void 3330void
3249ev_loop_fork (EV_P) EV_THROW 3331ev_loop_fork (EV_P) EV_NOEXCEPT
3250{ 3332{
3251 postfork = 1; 3333 postfork = 1;
3252} 3334}
3253 3335
3254/*****************************************************************************/ 3336/*****************************************************************************/
3258{ 3340{
3259 EV_CB_INVOKE ((W)w, revents); 3341 EV_CB_INVOKE ((W)w, revents);
3260} 3342}
3261 3343
3262unsigned int 3344unsigned int
3263ev_pending_count (EV_P) EV_THROW 3345ev_pending_count (EV_P) EV_NOEXCEPT
3264{ 3346{
3265 int pri; 3347 int pri;
3266 unsigned int count = 0; 3348 unsigned int count = 0;
3267 3349
3268 for (pri = NUMPRI; pri--; ) 3350 for (pri = NUMPRI; pri--; )
3269 count += pendingcnt [pri]; 3351 count += pendingcnt [pri];
3270 3352
3271 return count; 3353 return count;
3272} 3354}
3273 3355
3274void noinline 3356noinline
3357void
3275ev_invoke_pending (EV_P) 3358ev_invoke_pending (EV_P)
3276{ 3359{
3277 pendingpri = NUMPRI; 3360 pendingpri = NUMPRI;
3278 3361
3279 while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ 3362 do
3280 { 3363 {
3281 --pendingpri; 3364 --pendingpri;
3282 3365
3366 /* pendingpri possibly gets modified in the inner loop */
3283 while (pendingcnt [pendingpri]) 3367 while (pendingcnt [pendingpri])
3284 { 3368 {
3285 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; 3369 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
3286 3370
3287 p->w->pending = 0; 3371 p->w->pending = 0;
3288 EV_CB_INVOKE (p->w, p->events); 3372 EV_CB_INVOKE (p->w, p->events);
3289 EV_FREQUENT_CHECK; 3373 EV_FREQUENT_CHECK;
3290 } 3374 }
3291 } 3375 }
3376 while (pendingpri);
3292} 3377}
3293 3378
3294#if EV_IDLE_ENABLE 3379#if EV_IDLE_ENABLE
3295/* make idle watchers pending. this handles the "call-idle */ 3380/* make idle watchers pending. this handles the "call-idle */
3296/* only when higher priorities are idle" logic */ 3381/* only when higher priorities are idle" logic */
3354 } 3439 }
3355} 3440}
3356 3441
3357#if EV_PERIODIC_ENABLE 3442#if EV_PERIODIC_ENABLE
3358 3443
3359static void noinline 3444noinline
3445static void
3360periodic_recalc (EV_P_ ev_periodic *w) 3446periodic_recalc (EV_P_ ev_periodic *w)
3361{ 3447{
3362 ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; 3448 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); 3449 ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval);
3364 3450
3422 } 3508 }
3423} 3509}
3424 3510
3425/* simply recalculate all periodics */ 3511/* simply recalculate all periodics */
3426/* TODO: maybe ensure that at least one event happens when jumping forward? */ 3512/* TODO: maybe ensure that at least one event happens when jumping forward? */
3427static void noinline ecb_cold 3513noinline ecb_cold
3514static void
3428periodics_reschedule (EV_P) 3515periodics_reschedule (EV_P)
3429{ 3516{
3430 int i; 3517 int i;
3431 3518
3432 /* adjust periodics after time jump */ 3519 /* adjust periodics after time jump */
3445 reheap (periodics, periodiccnt); 3532 reheap (periodics, periodiccnt);
3446} 3533}
3447#endif 3534#endif
3448 3535
3449/* adjust all timers by a given offset */ 3536/* adjust all timers by a given offset */
3450static void noinline ecb_cold 3537noinline ecb_cold
3538static void
3451timers_reschedule (EV_P_ ev_tstamp adjust) 3539timers_reschedule (EV_P_ ev_tstamp adjust)
3452{ 3540{
3453 int i; 3541 int i;
3454 3542
3455 for (i = 0; i < timercnt; ++i) 3543 for (i = 0; i < timercnt; ++i)
3702 3790
3703 return activecnt; 3791 return activecnt;
3704} 3792}
3705 3793
3706void 3794void
3707ev_break (EV_P_ int how) EV_THROW 3795ev_break (EV_P_ int how) EV_NOEXCEPT
3708{ 3796{
3709 loop_done = how; 3797 loop_done = how;
3710} 3798}
3711 3799
3712void 3800void
3713ev_ref (EV_P) EV_THROW 3801ev_ref (EV_P) EV_NOEXCEPT
3714{ 3802{
3715 ++activecnt; 3803 ++activecnt;
3716} 3804}
3717 3805
3718void 3806void
3719ev_unref (EV_P) EV_THROW 3807ev_unref (EV_P) EV_NOEXCEPT
3720{ 3808{
3721 --activecnt; 3809 --activecnt;
3722} 3810}
3723 3811
3724void 3812void
3725ev_now_update (EV_P) EV_THROW 3813ev_now_update (EV_P) EV_NOEXCEPT
3726{ 3814{
3727 time_update (EV_A_ 1e100); 3815 time_update (EV_A_ 1e100);
3728} 3816}
3729 3817
3730void 3818void
3731ev_suspend (EV_P) EV_THROW 3819ev_suspend (EV_P) EV_NOEXCEPT
3732{ 3820{
3733 ev_now_update (EV_A); 3821 ev_now_update (EV_A);
3734} 3822}
3735 3823
3736void 3824void
3737ev_resume (EV_P) EV_THROW 3825ev_resume (EV_P) EV_NOEXCEPT
3738{ 3826{
3739 ev_tstamp mn_prev = mn_now; 3827 ev_tstamp mn_prev = mn_now;
3740 3828
3741 ev_now_update (EV_A); 3829 ev_now_update (EV_A);
3742 timers_reschedule (EV_A_ mn_now - mn_prev); 3830 timers_reschedule (EV_A_ mn_now - mn_prev);
3781 w->pending = 0; 3869 w->pending = 0;
3782 } 3870 }
3783} 3871}
3784 3872
3785int 3873int
3786ev_clear_pending (EV_P_ void *w) EV_THROW 3874ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3787{ 3875{
3788 W w_ = (W)w; 3876 W w_ = (W)w;
3789 int pending = w_->pending; 3877 int pending = w_->pending;
3790 3878
3791 if (expect_true (pending)) 3879 if (expect_true (pending))
3823 w->active = 0; 3911 w->active = 0;
3824} 3912}
3825 3913
3826/*****************************************************************************/ 3914/*****************************************************************************/
3827 3915
3828void noinline 3916noinline
3917void
3829ev_io_start (EV_P_ ev_io *w) EV_THROW 3918ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3830{ 3919{
3831 int fd = w->fd; 3920 int fd = w->fd;
3832 3921
3833 if (expect_false (ev_is_active (w))) 3922 if (expect_false (ev_is_active (w)))
3834 return; 3923 return;
3837 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3926 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3838 3927
3839 EV_FREQUENT_CHECK; 3928 EV_FREQUENT_CHECK;
3840 3929
3841 ev_start (EV_A_ (W)w, 1); 3930 ev_start (EV_A_ (W)w, 1);
3842 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3931 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3843 wlist_add (&anfds[fd].head, (WL)w); 3932 wlist_add (&anfds[fd].head, (WL)w);
3844 3933
3845 /* common bug, apparently */ 3934 /* common bug, apparently */
3846 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3935 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3847 3936
3849 w->events &= ~EV__IOFDSET; 3938 w->events &= ~EV__IOFDSET;
3850 3939
3851 EV_FREQUENT_CHECK; 3940 EV_FREQUENT_CHECK;
3852} 3941}
3853 3942
3854void noinline 3943noinline
3944void
3855ev_io_stop (EV_P_ ev_io *w) EV_THROW 3945ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3856{ 3946{
3857 clear_pending (EV_A_ (W)w); 3947 clear_pending (EV_A_ (W)w);
3858 if (expect_false (!ev_is_active (w))) 3948 if (expect_false (!ev_is_active (w)))
3859 return; 3949 return;
3860 3950
3868 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3958 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3869 3959
3870 EV_FREQUENT_CHECK; 3960 EV_FREQUENT_CHECK;
3871} 3961}
3872 3962
3873void noinline 3963noinline
3964void
3874ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3965ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3875{ 3966{
3876 if (expect_false (ev_is_active (w))) 3967 if (expect_false (ev_is_active (w)))
3877 return; 3968 return;
3878 3969
3879 ev_at (w) += mn_now; 3970 ev_at (w) += mn_now;
3882 3973
3883 EV_FREQUENT_CHECK; 3974 EV_FREQUENT_CHECK;
3884 3975
3885 ++timercnt; 3976 ++timercnt;
3886 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3977 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3887 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3978 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3888 ANHE_w (timers [ev_active (w)]) = (WT)w; 3979 ANHE_w (timers [ev_active (w)]) = (WT)w;
3889 ANHE_at_cache (timers [ev_active (w)]); 3980 ANHE_at_cache (timers [ev_active (w)]);
3890 upheap (timers, ev_active (w)); 3981 upheap (timers, ev_active (w));
3891 3982
3892 EV_FREQUENT_CHECK; 3983 EV_FREQUENT_CHECK;
3893 3984
3894 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3985 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3895} 3986}
3896 3987
3897void noinline 3988noinline
3989void
3898ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3990ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3899{ 3991{
3900 clear_pending (EV_A_ (W)w); 3992 clear_pending (EV_A_ (W)w);
3901 if (expect_false (!ev_is_active (w))) 3993 if (expect_false (!ev_is_active (w)))
3902 return; 3994 return;
3903 3995
3922 ev_stop (EV_A_ (W)w); 4014 ev_stop (EV_A_ (W)w);
3923 4015
3924 EV_FREQUENT_CHECK; 4016 EV_FREQUENT_CHECK;
3925} 4017}
3926 4018
3927void noinline 4019noinline
4020void
3928ev_timer_again (EV_P_ ev_timer *w) EV_THROW 4021ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3929{ 4022{
3930 EV_FREQUENT_CHECK; 4023 EV_FREQUENT_CHECK;
3931 4024
3932 clear_pending (EV_A_ (W)w); 4025 clear_pending (EV_A_ (W)w);
3933 4026
3950 4043
3951 EV_FREQUENT_CHECK; 4044 EV_FREQUENT_CHECK;
3952} 4045}
3953 4046
3954ev_tstamp 4047ev_tstamp
3955ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 4048ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3956{ 4049{
3957 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4050 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3958} 4051}
3959 4052
3960#if EV_PERIODIC_ENABLE 4053#if EV_PERIODIC_ENABLE
3961void noinline 4054noinline
4055void
3962ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4056ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
3963{ 4057{
3964 if (expect_false (ev_is_active (w))) 4058 if (expect_false (ev_is_active (w)))
3965 return; 4059 return;
3966 4060
3967 if (w->reschedule_cb) 4061 if (w->reschedule_cb)
3976 4070
3977 EV_FREQUENT_CHECK; 4071 EV_FREQUENT_CHECK;
3978 4072
3979 ++periodiccnt; 4073 ++periodiccnt;
3980 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4074 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
3981 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4075 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
3982 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4076 ANHE_w (periodics [ev_active (w)]) = (WT)w;
3983 ANHE_at_cache (periodics [ev_active (w)]); 4077 ANHE_at_cache (periodics [ev_active (w)]);
3984 upheap (periodics, ev_active (w)); 4078 upheap (periodics, ev_active (w));
3985 4079
3986 EV_FREQUENT_CHECK; 4080 EV_FREQUENT_CHECK;
3987 4081
3988 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4082 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3989} 4083}
3990 4084
3991void noinline 4085noinline
4086void
3992ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4087ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
3993{ 4088{
3994 clear_pending (EV_A_ (W)w); 4089 clear_pending (EV_A_ (W)w);
3995 if (expect_false (!ev_is_active (w))) 4090 if (expect_false (!ev_is_active (w)))
3996 return; 4091 return;
3997 4092
4014 ev_stop (EV_A_ (W)w); 4109 ev_stop (EV_A_ (W)w);
4015 4110
4016 EV_FREQUENT_CHECK; 4111 EV_FREQUENT_CHECK;
4017} 4112}
4018 4113
4019void noinline 4114noinline
4115void
4020ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4116ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4021{ 4117{
4022 /* TODO: use adjustheap and recalculation */ 4118 /* TODO: use adjustheap and recalculation */
4023 ev_periodic_stop (EV_A_ w); 4119 ev_periodic_stop (EV_A_ w);
4024 ev_periodic_start (EV_A_ w); 4120 ev_periodic_start (EV_A_ w);
4025} 4121}
4029# define SA_RESTART 0 4125# define SA_RESTART 0
4030#endif 4126#endif
4031 4127
4032#if EV_SIGNAL_ENABLE 4128#if EV_SIGNAL_ENABLE
4033 4129
4034void noinline 4130noinline
4131void
4035ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4132ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4036{ 4133{
4037 if (expect_false (ev_is_active (w))) 4134 if (expect_false (ev_is_active (w)))
4038 return; 4135 return;
4039 4136
4040 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4137 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4111 } 4208 }
4112 4209
4113 EV_FREQUENT_CHECK; 4210 EV_FREQUENT_CHECK;
4114} 4211}
4115 4212
4116void noinline 4213noinline
4214void
4117ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4215ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4118{ 4216{
4119 clear_pending (EV_A_ (W)w); 4217 clear_pending (EV_A_ (W)w);
4120 if (expect_false (!ev_is_active (w))) 4218 if (expect_false (!ev_is_active (w)))
4121 return; 4219 return;
4122 4220
4153#endif 4251#endif
4154 4252
4155#if EV_CHILD_ENABLE 4253#if EV_CHILD_ENABLE
4156 4254
4157void 4255void
4158ev_child_start (EV_P_ ev_child *w) EV_THROW 4256ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4159{ 4257{
4160#if EV_MULTIPLICITY 4258#if EV_MULTIPLICITY
4161 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4259 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4162#endif 4260#endif
4163 if (expect_false (ev_is_active (w))) 4261 if (expect_false (ev_is_active (w)))
4170 4268
4171 EV_FREQUENT_CHECK; 4269 EV_FREQUENT_CHECK;
4172} 4270}
4173 4271
4174void 4272void
4175ev_child_stop (EV_P_ ev_child *w) EV_THROW 4273ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4176{ 4274{
4177 clear_pending (EV_A_ (W)w); 4275 clear_pending (EV_A_ (W)w);
4178 if (expect_false (!ev_is_active (w))) 4276 if (expect_false (!ev_is_active (w)))
4179 return; 4277 return;
4180 4278
4197 4295
4198#define DEF_STAT_INTERVAL 5.0074891 4296#define DEF_STAT_INTERVAL 5.0074891
4199#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4297#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4200#define MIN_STAT_INTERVAL 0.1074891 4298#define MIN_STAT_INTERVAL 0.1074891
4201 4299
4202static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4300noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4203 4301
4204#if EV_USE_INOTIFY 4302#if EV_USE_INOTIFY
4205 4303
4206/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4304/* 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) 4305# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4208 4306
4209static void noinline 4307noinline
4308static void
4210infy_add (EV_P_ ev_stat *w) 4309infy_add (EV_P_ ev_stat *w)
4211{ 4310{
4212 w->wd = inotify_add_watch (fs_fd, w->path, 4311 w->wd = inotify_add_watch (fs_fd, w->path,
4213 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4312 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4214 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO 4313 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
4278 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4377 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4279 ev_timer_again (EV_A_ &w->timer); 4378 ev_timer_again (EV_A_ &w->timer);
4280 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4379 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4281} 4380}
4282 4381
4283static void noinline 4382noinline
4383static void
4284infy_del (EV_P_ ev_stat *w) 4384infy_del (EV_P_ ev_stat *w)
4285{ 4385{
4286 int slot; 4386 int slot;
4287 int wd = w->wd; 4387 int wd = w->wd;
4288 4388
4295 4395
4296 /* remove this watcher, if others are watching it, they will rearm */ 4396 /* remove this watcher, if others are watching it, they will rearm */
4297 inotify_rm_watch (fs_fd, wd); 4397 inotify_rm_watch (fs_fd, wd);
4298} 4398}
4299 4399
4300static void noinline 4400noinline
4401static void
4301infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4402infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4302{ 4403{
4303 if (slot < 0) 4404 if (slot < 0)
4304 /* overflow, need to check for all hash slots */ 4405 /* overflow, need to check for all hash slots */
4305 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) 4406 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
4341 infy_wd (EV_A_ ev->wd, ev->wd, ev); 4442 infy_wd (EV_A_ ev->wd, ev->wd, ev);
4342 ofs += sizeof (struct inotify_event) + ev->len; 4443 ofs += sizeof (struct inotify_event) + ev->len;
4343 } 4444 }
4344} 4445}
4345 4446
4346inline_size void ecb_cold 4447inline_size ecb_cold
4448void
4347ev_check_2625 (EV_P) 4449ev_check_2625 (EV_P)
4348{ 4450{
4349 /* kernels < 2.6.25 are borked 4451 /* kernels < 2.6.25 are borked
4350 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 4452 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
4351 */ 4453 */
4441#else 4543#else
4442# define EV_LSTAT(p,b) lstat (p, b) 4544# define EV_LSTAT(p,b) lstat (p, b)
4443#endif 4545#endif
4444 4546
4445void 4547void
4446ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4548ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4447{ 4549{
4448 if (lstat (w->path, &w->attr) < 0) 4550 if (lstat (w->path, &w->attr) < 0)
4449 w->attr.st_nlink = 0; 4551 w->attr.st_nlink = 0;
4450 else if (!w->attr.st_nlink) 4552 else if (!w->attr.st_nlink)
4451 w->attr.st_nlink = 1; 4553 w->attr.st_nlink = 1;
4452} 4554}
4453 4555
4454static void noinline 4556noinline
4557static void
4455stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4558stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4456{ 4559{
4457 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4560 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4458 4561
4459 ev_statdata prev = w->attr; 4562 ev_statdata prev = w->attr;
4490 ev_feed_event (EV_A_ w, EV_STAT); 4593 ev_feed_event (EV_A_ w, EV_STAT);
4491 } 4594 }
4492} 4595}
4493 4596
4494void 4597void
4495ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4598ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4496{ 4599{
4497 if (expect_false (ev_is_active (w))) 4600 if (expect_false (ev_is_active (w)))
4498 return; 4601 return;
4499 4602
4500 ev_stat_stat (EV_A_ w); 4603 ev_stat_stat (EV_A_ w);
4521 4624
4522 EV_FREQUENT_CHECK; 4625 EV_FREQUENT_CHECK;
4523} 4626}
4524 4627
4525void 4628void
4526ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4629ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4527{ 4630{
4528 clear_pending (EV_A_ (W)w); 4631 clear_pending (EV_A_ (W)w);
4529 if (expect_false (!ev_is_active (w))) 4632 if (expect_false (!ev_is_active (w)))
4530 return; 4633 return;
4531 4634
4547} 4650}
4548#endif 4651#endif
4549 4652
4550#if EV_IDLE_ENABLE 4653#if EV_IDLE_ENABLE
4551void 4654void
4552ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4655ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4553{ 4656{
4554 if (expect_false (ev_is_active (w))) 4657 if (expect_false (ev_is_active (w)))
4555 return; 4658 return;
4556 4659
4557 pri_adjust (EV_A_ (W)w); 4660 pri_adjust (EV_A_ (W)w);
4562 int active = ++idlecnt [ABSPRI (w)]; 4665 int active = ++idlecnt [ABSPRI (w)];
4563 4666
4564 ++idleall; 4667 ++idleall;
4565 ev_start (EV_A_ (W)w, active); 4668 ev_start (EV_A_ (W)w, active);
4566 4669
4567 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4670 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4568 idles [ABSPRI (w)][active - 1] = w; 4671 idles [ABSPRI (w)][active - 1] = w;
4569 } 4672 }
4570 4673
4571 EV_FREQUENT_CHECK; 4674 EV_FREQUENT_CHECK;
4572} 4675}
4573 4676
4574void 4677void
4575ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4678ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4576{ 4679{
4577 clear_pending (EV_A_ (W)w); 4680 clear_pending (EV_A_ (W)w);
4578 if (expect_false (!ev_is_active (w))) 4681 if (expect_false (!ev_is_active (w)))
4579 return; 4682 return;
4580 4683
4594} 4697}
4595#endif 4698#endif
4596 4699
4597#if EV_PREPARE_ENABLE 4700#if EV_PREPARE_ENABLE
4598void 4701void
4599ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4702ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4600{ 4703{
4601 if (expect_false (ev_is_active (w))) 4704 if (expect_false (ev_is_active (w)))
4602 return; 4705 return;
4603 4706
4604 EV_FREQUENT_CHECK; 4707 EV_FREQUENT_CHECK;
4605 4708
4606 ev_start (EV_A_ (W)w, ++preparecnt); 4709 ev_start (EV_A_ (W)w, ++preparecnt);
4607 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4710 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4608 prepares [preparecnt - 1] = w; 4711 prepares [preparecnt - 1] = w;
4609 4712
4610 EV_FREQUENT_CHECK; 4713 EV_FREQUENT_CHECK;
4611} 4714}
4612 4715
4613void 4716void
4614ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4717ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4615{ 4718{
4616 clear_pending (EV_A_ (W)w); 4719 clear_pending (EV_A_ (W)w);
4617 if (expect_false (!ev_is_active (w))) 4720 if (expect_false (!ev_is_active (w)))
4618 return; 4721 return;
4619 4722
4632} 4735}
4633#endif 4736#endif
4634 4737
4635#if EV_CHECK_ENABLE 4738#if EV_CHECK_ENABLE
4636void 4739void
4637ev_check_start (EV_P_ ev_check *w) EV_THROW 4740ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4638{ 4741{
4639 if (expect_false (ev_is_active (w))) 4742 if (expect_false (ev_is_active (w)))
4640 return; 4743 return;
4641 4744
4642 EV_FREQUENT_CHECK; 4745 EV_FREQUENT_CHECK;
4643 4746
4644 ev_start (EV_A_ (W)w, ++checkcnt); 4747 ev_start (EV_A_ (W)w, ++checkcnt);
4645 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4748 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4646 checks [checkcnt - 1] = w; 4749 checks [checkcnt - 1] = w;
4647 4750
4648 EV_FREQUENT_CHECK; 4751 EV_FREQUENT_CHECK;
4649} 4752}
4650 4753
4651void 4754void
4652ev_check_stop (EV_P_ ev_check *w) EV_THROW 4755ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4653{ 4756{
4654 clear_pending (EV_A_ (W)w); 4757 clear_pending (EV_A_ (W)w);
4655 if (expect_false (!ev_is_active (w))) 4758 if (expect_false (!ev_is_active (w)))
4656 return; 4759 return;
4657 4760
4669 EV_FREQUENT_CHECK; 4772 EV_FREQUENT_CHECK;
4670} 4773}
4671#endif 4774#endif
4672 4775
4673#if EV_EMBED_ENABLE 4776#if EV_EMBED_ENABLE
4674void noinline 4777noinline
4778void
4675ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4779ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4676{ 4780{
4677 ev_run (w->other, EVRUN_NOWAIT); 4781 ev_run (w->other, EVRUN_NOWAIT);
4678} 4782}
4679 4783
4680static void 4784static void
4728 ev_idle_stop (EV_A_ idle); 4832 ev_idle_stop (EV_A_ idle);
4729} 4833}
4730#endif 4834#endif
4731 4835
4732void 4836void
4733ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4837ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4734{ 4838{
4735 if (expect_false (ev_is_active (w))) 4839 if (expect_false (ev_is_active (w)))
4736 return; 4840 return;
4737 4841
4738 { 4842 {
4759 4863
4760 EV_FREQUENT_CHECK; 4864 EV_FREQUENT_CHECK;
4761} 4865}
4762 4866
4763void 4867void
4764ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4868ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4765{ 4869{
4766 clear_pending (EV_A_ (W)w); 4870 clear_pending (EV_A_ (W)w);
4767 if (expect_false (!ev_is_active (w))) 4871 if (expect_false (!ev_is_active (w)))
4768 return; 4872 return;
4769 4873
4779} 4883}
4780#endif 4884#endif
4781 4885
4782#if EV_FORK_ENABLE 4886#if EV_FORK_ENABLE
4783void 4887void
4784ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4888ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4785{ 4889{
4786 if (expect_false (ev_is_active (w))) 4890 if (expect_false (ev_is_active (w)))
4787 return; 4891 return;
4788 4892
4789 EV_FREQUENT_CHECK; 4893 EV_FREQUENT_CHECK;
4790 4894
4791 ev_start (EV_A_ (W)w, ++forkcnt); 4895 ev_start (EV_A_ (W)w, ++forkcnt);
4792 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4896 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4793 forks [forkcnt - 1] = w; 4897 forks [forkcnt - 1] = w;
4794 4898
4795 EV_FREQUENT_CHECK; 4899 EV_FREQUENT_CHECK;
4796} 4900}
4797 4901
4798void 4902void
4799ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4903ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4800{ 4904{
4801 clear_pending (EV_A_ (W)w); 4905 clear_pending (EV_A_ (W)w);
4802 if (expect_false (!ev_is_active (w))) 4906 if (expect_false (!ev_is_active (w)))
4803 return; 4907 return;
4804 4908
4817} 4921}
4818#endif 4922#endif
4819 4923
4820#if EV_CLEANUP_ENABLE 4924#if EV_CLEANUP_ENABLE
4821void 4925void
4822ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4926ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4823{ 4927{
4824 if (expect_false (ev_is_active (w))) 4928 if (expect_false (ev_is_active (w)))
4825 return; 4929 return;
4826 4930
4827 EV_FREQUENT_CHECK; 4931 EV_FREQUENT_CHECK;
4828 4932
4829 ev_start (EV_A_ (W)w, ++cleanupcnt); 4933 ev_start (EV_A_ (W)w, ++cleanupcnt);
4830 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4934 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4831 cleanups [cleanupcnt - 1] = w; 4935 cleanups [cleanupcnt - 1] = w;
4832 4936
4833 /* cleanup watchers should never keep a refcount on the loop */ 4937 /* cleanup watchers should never keep a refcount on the loop */
4834 ev_unref (EV_A); 4938 ev_unref (EV_A);
4835 EV_FREQUENT_CHECK; 4939 EV_FREQUENT_CHECK;
4836} 4940}
4837 4941
4838void 4942void
4839ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4943ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4840{ 4944{
4841 clear_pending (EV_A_ (W)w); 4945 clear_pending (EV_A_ (W)w);
4842 if (expect_false (!ev_is_active (w))) 4946 if (expect_false (!ev_is_active (w)))
4843 return; 4947 return;
4844 4948
4858} 4962}
4859#endif 4963#endif
4860 4964
4861#if EV_ASYNC_ENABLE 4965#if EV_ASYNC_ENABLE
4862void 4966void
4863ev_async_start (EV_P_ ev_async *w) EV_THROW 4967ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4864{ 4968{
4865 if (expect_false (ev_is_active (w))) 4969 if (expect_false (ev_is_active (w)))
4866 return; 4970 return;
4867 4971
4868 w->sent = 0; 4972 w->sent = 0;
4870 evpipe_init (EV_A); 4974 evpipe_init (EV_A);
4871 4975
4872 EV_FREQUENT_CHECK; 4976 EV_FREQUENT_CHECK;
4873 4977
4874 ev_start (EV_A_ (W)w, ++asynccnt); 4978 ev_start (EV_A_ (W)w, ++asynccnt);
4875 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4979 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4876 asyncs [asynccnt - 1] = w; 4980 asyncs [asynccnt - 1] = w;
4877 4981
4878 EV_FREQUENT_CHECK; 4982 EV_FREQUENT_CHECK;
4879} 4983}
4880 4984
4881void 4985void
4882ev_async_stop (EV_P_ ev_async *w) EV_THROW 4986ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4883{ 4987{
4884 clear_pending (EV_A_ (W)w); 4988 clear_pending (EV_A_ (W)w);
4885 if (expect_false (!ev_is_active (w))) 4989 if (expect_false (!ev_is_active (w)))
4886 return; 4990 return;
4887 4991
4898 5002
4899 EV_FREQUENT_CHECK; 5003 EV_FREQUENT_CHECK;
4900} 5004}
4901 5005
4902void 5006void
4903ev_async_send (EV_P_ ev_async *w) EV_THROW 5007ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4904{ 5008{
4905 w->sent = 1; 5009 w->sent = 1;
4906 evpipe_write (EV_A_ &async_pending); 5010 evpipe_write (EV_A_ &async_pending);
4907} 5011}
4908#endif 5012#endif
4945 5049
4946 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5050 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4947} 5051}
4948 5052
4949void 5053void
4950ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5054ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
4951{ 5055{
4952 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5056 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 5057
4960 once->cb = cb; 5058 once->cb = cb;
4961 once->arg = arg; 5059 once->arg = arg;
4962 5060
4963 ev_init (&once->io, once_cb_io); 5061 ev_init (&once->io, once_cb_io);
4976} 5074}
4977 5075
4978/*****************************************************************************/ 5076/*****************************************************************************/
4979 5077
4980#if EV_WALK_ENABLE 5078#if EV_WALK_ENABLE
4981void ecb_cold 5079ecb_cold
5080void
4982ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5081ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
4983{ 5082{
4984 int i, j; 5083 int i, j;
4985 ev_watcher_list *wl, *wn; 5084 ev_watcher_list *wl, *wn;
4986 5085
4987 if (types & (EV_IO | EV_EMBED)) 5086 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines