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.499 by root, Wed Jun 26 07:50:27 2019 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
115# else 115# else
116# undef EV_USE_EPOLL 116# undef EV_USE_EPOLL
117# define EV_USE_EPOLL 0 117# define EV_USE_EPOLL 0
118# endif 118# endif
119 119
120# if HAVE_LINUX_AIO_ABI_H
121# ifndef EV_USE_LINUXAIO
122# define EV_USE_LINUXAIO EV_FEATURE_BACKENDS
123# endif
124# else
125# undef EV_USE_LINUXAIO
126# define EV_USE_LINUXAIO 0
127# endif
128
120# if HAVE_KQUEUE && HAVE_SYS_EVENT_H 129# if HAVE_KQUEUE && HAVE_SYS_EVENT_H
121# ifndef EV_USE_KQUEUE 130# ifndef EV_USE_KQUEUE
122# define EV_USE_KQUEUE EV_FEATURE_BACKENDS 131# define EV_USE_KQUEUE EV_FEATURE_BACKENDS
123# endif 132# endif
124# else 133# else
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
2099 ev_io *w; 2147 ev_io *w;
2100 2148
2101 unsigned char o_events = anfd->events; 2149 unsigned char o_events = anfd->events;
2102 unsigned char o_reify = anfd->reify; 2150 unsigned char o_reify = anfd->reify;
2103 2151
2104 anfd->reify = 0; 2152 anfd->reify = 0;
2105 2153
2106 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ 2154 /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */
2107 { 2155 {
2108 anfd->events = 0; 2156 anfd->events = 0;
2109 2157
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)
3661 { 3749 {
3662 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 3750 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
3663 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3751 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3664 } 3752 }
3665 3753
3666
3667 /* update ev_rt_now, do magic */ 3754 /* update ev_rt_now, do magic */
3668 time_update (EV_A_ waittime + sleeptime); 3755 time_update (EV_A_ waittime + sleeptime);
3669 } 3756 }
3670 3757
3671 /* queue pending timers and reschedule them */ 3758 /* queue pending timers and reschedule them */
3702 3789
3703 return activecnt; 3790 return activecnt;
3704} 3791}
3705 3792
3706void 3793void
3707ev_break (EV_P_ int how) EV_THROW 3794ev_break (EV_P_ int how) EV_NOEXCEPT
3708{ 3795{
3709 loop_done = how; 3796 loop_done = how;
3710} 3797}
3711 3798
3712void 3799void
3713ev_ref (EV_P) EV_THROW 3800ev_ref (EV_P) EV_NOEXCEPT
3714{ 3801{
3715 ++activecnt; 3802 ++activecnt;
3716} 3803}
3717 3804
3718void 3805void
3719ev_unref (EV_P) EV_THROW 3806ev_unref (EV_P) EV_NOEXCEPT
3720{ 3807{
3721 --activecnt; 3808 --activecnt;
3722} 3809}
3723 3810
3724void 3811void
3725ev_now_update (EV_P) EV_THROW 3812ev_now_update (EV_P) EV_NOEXCEPT
3726{ 3813{
3727 time_update (EV_A_ 1e100); 3814 time_update (EV_A_ 1e100);
3728} 3815}
3729 3816
3730void 3817void
3731ev_suspend (EV_P) EV_THROW 3818ev_suspend (EV_P) EV_NOEXCEPT
3732{ 3819{
3733 ev_now_update (EV_A); 3820 ev_now_update (EV_A);
3734} 3821}
3735 3822
3736void 3823void
3737ev_resume (EV_P) EV_THROW 3824ev_resume (EV_P) EV_NOEXCEPT
3738{ 3825{
3739 ev_tstamp mn_prev = mn_now; 3826 ev_tstamp mn_prev = mn_now;
3740 3827
3741 ev_now_update (EV_A); 3828 ev_now_update (EV_A);
3742 timers_reschedule (EV_A_ mn_now - mn_prev); 3829 timers_reschedule (EV_A_ mn_now - mn_prev);
3781 w->pending = 0; 3868 w->pending = 0;
3782 } 3869 }
3783} 3870}
3784 3871
3785int 3872int
3786ev_clear_pending (EV_P_ void *w) EV_THROW 3873ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3787{ 3874{
3788 W w_ = (W)w; 3875 W w_ = (W)w;
3789 int pending = w_->pending; 3876 int pending = w_->pending;
3790 3877
3791 if (expect_true (pending)) 3878 if (expect_true (pending))
3823 w->active = 0; 3910 w->active = 0;
3824} 3911}
3825 3912
3826/*****************************************************************************/ 3913/*****************************************************************************/
3827 3914
3828void noinline 3915noinline
3916void
3829ev_io_start (EV_P_ ev_io *w) EV_THROW 3917ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3830{ 3918{
3831 int fd = w->fd; 3919 int fd = w->fd;
3832 3920
3833 if (expect_false (ev_is_active (w))) 3921 if (expect_false (ev_is_active (w)))
3834 return; 3922 return;
3835 3923
3836 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3924 assert (("libev: ev_io_start called with negative fd", fd >= 0));
3837 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); 3925 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3838 3926
3927#if EV_VERIFY >= 2
3928 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3929#endif
3839 EV_FREQUENT_CHECK; 3930 EV_FREQUENT_CHECK;
3840 3931
3841 ev_start (EV_A_ (W)w, 1); 3932 ev_start (EV_A_ (W)w, 1);
3842 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3933 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3843 wlist_add (&anfds[fd].head, (WL)w); 3934 wlist_add (&anfds[fd].head, (WL)w);
3844 3935
3845 /* common bug, apparently */ 3936 /* common bug, apparently */
3846 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3937 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3847 3938
3849 w->events &= ~EV__IOFDSET; 3940 w->events &= ~EV__IOFDSET;
3850 3941
3851 EV_FREQUENT_CHECK; 3942 EV_FREQUENT_CHECK;
3852} 3943}
3853 3944
3854void noinline 3945noinline
3946void
3855ev_io_stop (EV_P_ ev_io *w) EV_THROW 3947ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3856{ 3948{
3857 clear_pending (EV_A_ (W)w); 3949 clear_pending (EV_A_ (W)w);
3858 if (expect_false (!ev_is_active (w))) 3950 if (expect_false (!ev_is_active (w)))
3859 return; 3951 return;
3860 3952
3861 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 3953 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
3862 3954
3955#if EV_VERIFY >= 2
3956 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3957#endif
3863 EV_FREQUENT_CHECK; 3958 EV_FREQUENT_CHECK;
3864 3959
3865 wlist_del (&anfds[w->fd].head, (WL)w); 3960 wlist_del (&anfds[w->fd].head, (WL)w);
3866 ev_stop (EV_A_ (W)w); 3961 ev_stop (EV_A_ (W)w);
3867 3962
3868 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3963 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3869 3964
3870 EV_FREQUENT_CHECK; 3965 EV_FREQUENT_CHECK;
3871} 3966}
3872 3967
3873void noinline 3968noinline
3969void
3874ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3970ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3875{ 3971{
3876 if (expect_false (ev_is_active (w))) 3972 if (expect_false (ev_is_active (w)))
3877 return; 3973 return;
3878 3974
3879 ev_at (w) += mn_now; 3975 ev_at (w) += mn_now;
3882 3978
3883 EV_FREQUENT_CHECK; 3979 EV_FREQUENT_CHECK;
3884 3980
3885 ++timercnt; 3981 ++timercnt;
3886 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3982 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3887 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3983 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3888 ANHE_w (timers [ev_active (w)]) = (WT)w; 3984 ANHE_w (timers [ev_active (w)]) = (WT)w;
3889 ANHE_at_cache (timers [ev_active (w)]); 3985 ANHE_at_cache (timers [ev_active (w)]);
3890 upheap (timers, ev_active (w)); 3986 upheap (timers, ev_active (w));
3891 3987
3892 EV_FREQUENT_CHECK; 3988 EV_FREQUENT_CHECK;
3893 3989
3894 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3990 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3895} 3991}
3896 3992
3897void noinline 3993noinline
3994void
3898ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3995ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3899{ 3996{
3900 clear_pending (EV_A_ (W)w); 3997 clear_pending (EV_A_ (W)w);
3901 if (expect_false (!ev_is_active (w))) 3998 if (expect_false (!ev_is_active (w)))
3902 return; 3999 return;
3903 4000
3922 ev_stop (EV_A_ (W)w); 4019 ev_stop (EV_A_ (W)w);
3923 4020
3924 EV_FREQUENT_CHECK; 4021 EV_FREQUENT_CHECK;
3925} 4022}
3926 4023
3927void noinline 4024noinline
4025void
3928ev_timer_again (EV_P_ ev_timer *w) EV_THROW 4026ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3929{ 4027{
3930 EV_FREQUENT_CHECK; 4028 EV_FREQUENT_CHECK;
3931 4029
3932 clear_pending (EV_A_ (W)w); 4030 clear_pending (EV_A_ (W)w);
3933 4031
3950 4048
3951 EV_FREQUENT_CHECK; 4049 EV_FREQUENT_CHECK;
3952} 4050}
3953 4051
3954ev_tstamp 4052ev_tstamp
3955ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 4053ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3956{ 4054{
3957 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4055 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3958} 4056}
3959 4057
3960#if EV_PERIODIC_ENABLE 4058#if EV_PERIODIC_ENABLE
3961void noinline 4059noinline
4060void
3962ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4061ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
3963{ 4062{
3964 if (expect_false (ev_is_active (w))) 4063 if (expect_false (ev_is_active (w)))
3965 return; 4064 return;
3966 4065
3967 if (w->reschedule_cb) 4066 if (w->reschedule_cb)
3976 4075
3977 EV_FREQUENT_CHECK; 4076 EV_FREQUENT_CHECK;
3978 4077
3979 ++periodiccnt; 4078 ++periodiccnt;
3980 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4079 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
3981 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4080 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
3982 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4081 ANHE_w (periodics [ev_active (w)]) = (WT)w;
3983 ANHE_at_cache (periodics [ev_active (w)]); 4082 ANHE_at_cache (periodics [ev_active (w)]);
3984 upheap (periodics, ev_active (w)); 4083 upheap (periodics, ev_active (w));
3985 4084
3986 EV_FREQUENT_CHECK; 4085 EV_FREQUENT_CHECK;
3987 4086
3988 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4087 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3989} 4088}
3990 4089
3991void noinline 4090noinline
4091void
3992ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4092ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
3993{ 4093{
3994 clear_pending (EV_A_ (W)w); 4094 clear_pending (EV_A_ (W)w);
3995 if (expect_false (!ev_is_active (w))) 4095 if (expect_false (!ev_is_active (w)))
3996 return; 4096 return;
3997 4097
4014 ev_stop (EV_A_ (W)w); 4114 ev_stop (EV_A_ (W)w);
4015 4115
4016 EV_FREQUENT_CHECK; 4116 EV_FREQUENT_CHECK;
4017} 4117}
4018 4118
4019void noinline 4119noinline
4120void
4020ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4121ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4021{ 4122{
4022 /* TODO: use adjustheap and recalculation */ 4123 /* TODO: use adjustheap and recalculation */
4023 ev_periodic_stop (EV_A_ w); 4124 ev_periodic_stop (EV_A_ w);
4024 ev_periodic_start (EV_A_ w); 4125 ev_periodic_start (EV_A_ w);
4025} 4126}
4029# define SA_RESTART 0 4130# define SA_RESTART 0
4030#endif 4131#endif
4031 4132
4032#if EV_SIGNAL_ENABLE 4133#if EV_SIGNAL_ENABLE
4033 4134
4034void noinline 4135noinline
4136void
4035ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4137ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4036{ 4138{
4037 if (expect_false (ev_is_active (w))) 4139 if (expect_false (ev_is_active (w)))
4038 return; 4140 return;
4039 4141
4040 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4142 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4111 } 4213 }
4112 4214
4113 EV_FREQUENT_CHECK; 4215 EV_FREQUENT_CHECK;
4114} 4216}
4115 4217
4116void noinline 4218noinline
4219void
4117ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4220ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4118{ 4221{
4119 clear_pending (EV_A_ (W)w); 4222 clear_pending (EV_A_ (W)w);
4120 if (expect_false (!ev_is_active (w))) 4223 if (expect_false (!ev_is_active (w)))
4121 return; 4224 return;
4122 4225
4153#endif 4256#endif
4154 4257
4155#if EV_CHILD_ENABLE 4258#if EV_CHILD_ENABLE
4156 4259
4157void 4260void
4158ev_child_start (EV_P_ ev_child *w) EV_THROW 4261ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4159{ 4262{
4160#if EV_MULTIPLICITY 4263#if EV_MULTIPLICITY
4161 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4264 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4162#endif 4265#endif
4163 if (expect_false (ev_is_active (w))) 4266 if (expect_false (ev_is_active (w)))
4170 4273
4171 EV_FREQUENT_CHECK; 4274 EV_FREQUENT_CHECK;
4172} 4275}
4173 4276
4174void 4277void
4175ev_child_stop (EV_P_ ev_child *w) EV_THROW 4278ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4176{ 4279{
4177 clear_pending (EV_A_ (W)w); 4280 clear_pending (EV_A_ (W)w);
4178 if (expect_false (!ev_is_active (w))) 4281 if (expect_false (!ev_is_active (w)))
4179 return; 4282 return;
4180 4283
4197 4300
4198#define DEF_STAT_INTERVAL 5.0074891 4301#define DEF_STAT_INTERVAL 5.0074891
4199#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4302#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4200#define MIN_STAT_INTERVAL 0.1074891 4303#define MIN_STAT_INTERVAL 0.1074891
4201 4304
4202static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4305noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4203 4306
4204#if EV_USE_INOTIFY 4307#if EV_USE_INOTIFY
4205 4308
4206/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4309/* 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) 4310# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4208 4311
4209static void noinline 4312noinline
4313static void
4210infy_add (EV_P_ ev_stat *w) 4314infy_add (EV_P_ ev_stat *w)
4211{ 4315{
4212 w->wd = inotify_add_watch (fs_fd, w->path, 4316 w->wd = inotify_add_watch (fs_fd, w->path,
4213 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4317 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4214 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO 4318 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
4278 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4382 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4279 ev_timer_again (EV_A_ &w->timer); 4383 ev_timer_again (EV_A_ &w->timer);
4280 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4384 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4281} 4385}
4282 4386
4283static void noinline 4387noinline
4388static void
4284infy_del (EV_P_ ev_stat *w) 4389infy_del (EV_P_ ev_stat *w)
4285{ 4390{
4286 int slot; 4391 int slot;
4287 int wd = w->wd; 4392 int wd = w->wd;
4288 4393
4295 4400
4296 /* remove this watcher, if others are watching it, they will rearm */ 4401 /* remove this watcher, if others are watching it, they will rearm */
4297 inotify_rm_watch (fs_fd, wd); 4402 inotify_rm_watch (fs_fd, wd);
4298} 4403}
4299 4404
4300static void noinline 4405noinline
4406static void
4301infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4407infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4302{ 4408{
4303 if (slot < 0) 4409 if (slot < 0)
4304 /* overflow, need to check for all hash slots */ 4410 /* overflow, need to check for all hash slots */
4305 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) 4411 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
4341 infy_wd (EV_A_ ev->wd, ev->wd, ev); 4447 infy_wd (EV_A_ ev->wd, ev->wd, ev);
4342 ofs += sizeof (struct inotify_event) + ev->len; 4448 ofs += sizeof (struct inotify_event) + ev->len;
4343 } 4449 }
4344} 4450}
4345 4451
4346inline_size void ecb_cold 4452inline_size ecb_cold
4453void
4347ev_check_2625 (EV_P) 4454ev_check_2625 (EV_P)
4348{ 4455{
4349 /* kernels < 2.6.25 are borked 4456 /* kernels < 2.6.25 are borked
4350 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 4457 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
4351 */ 4458 */
4441#else 4548#else
4442# define EV_LSTAT(p,b) lstat (p, b) 4549# define EV_LSTAT(p,b) lstat (p, b)
4443#endif 4550#endif
4444 4551
4445void 4552void
4446ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4553ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4447{ 4554{
4448 if (lstat (w->path, &w->attr) < 0) 4555 if (lstat (w->path, &w->attr) < 0)
4449 w->attr.st_nlink = 0; 4556 w->attr.st_nlink = 0;
4450 else if (!w->attr.st_nlink) 4557 else if (!w->attr.st_nlink)
4451 w->attr.st_nlink = 1; 4558 w->attr.st_nlink = 1;
4452} 4559}
4453 4560
4454static void noinline 4561noinline
4562static void
4455stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4563stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4456{ 4564{
4457 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4565 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4458 4566
4459 ev_statdata prev = w->attr; 4567 ev_statdata prev = w->attr;
4490 ev_feed_event (EV_A_ w, EV_STAT); 4598 ev_feed_event (EV_A_ w, EV_STAT);
4491 } 4599 }
4492} 4600}
4493 4601
4494void 4602void
4495ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4603ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4496{ 4604{
4497 if (expect_false (ev_is_active (w))) 4605 if (expect_false (ev_is_active (w)))
4498 return; 4606 return;
4499 4607
4500 ev_stat_stat (EV_A_ w); 4608 ev_stat_stat (EV_A_ w);
4521 4629
4522 EV_FREQUENT_CHECK; 4630 EV_FREQUENT_CHECK;
4523} 4631}
4524 4632
4525void 4633void
4526ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4634ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4527{ 4635{
4528 clear_pending (EV_A_ (W)w); 4636 clear_pending (EV_A_ (W)w);
4529 if (expect_false (!ev_is_active (w))) 4637 if (expect_false (!ev_is_active (w)))
4530 return; 4638 return;
4531 4639
4547} 4655}
4548#endif 4656#endif
4549 4657
4550#if EV_IDLE_ENABLE 4658#if EV_IDLE_ENABLE
4551void 4659void
4552ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4660ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4553{ 4661{
4554 if (expect_false (ev_is_active (w))) 4662 if (expect_false (ev_is_active (w)))
4555 return; 4663 return;
4556 4664
4557 pri_adjust (EV_A_ (W)w); 4665 pri_adjust (EV_A_ (W)w);
4562 int active = ++idlecnt [ABSPRI (w)]; 4670 int active = ++idlecnt [ABSPRI (w)];
4563 4671
4564 ++idleall; 4672 ++idleall;
4565 ev_start (EV_A_ (W)w, active); 4673 ev_start (EV_A_ (W)w, active);
4566 4674
4567 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4675 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4568 idles [ABSPRI (w)][active - 1] = w; 4676 idles [ABSPRI (w)][active - 1] = w;
4569 } 4677 }
4570 4678
4571 EV_FREQUENT_CHECK; 4679 EV_FREQUENT_CHECK;
4572} 4680}
4573 4681
4574void 4682void
4575ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4683ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4576{ 4684{
4577 clear_pending (EV_A_ (W)w); 4685 clear_pending (EV_A_ (W)w);
4578 if (expect_false (!ev_is_active (w))) 4686 if (expect_false (!ev_is_active (w)))
4579 return; 4687 return;
4580 4688
4594} 4702}
4595#endif 4703#endif
4596 4704
4597#if EV_PREPARE_ENABLE 4705#if EV_PREPARE_ENABLE
4598void 4706void
4599ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4707ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4600{ 4708{
4601 if (expect_false (ev_is_active (w))) 4709 if (expect_false (ev_is_active (w)))
4602 return; 4710 return;
4603 4711
4604 EV_FREQUENT_CHECK; 4712 EV_FREQUENT_CHECK;
4605 4713
4606 ev_start (EV_A_ (W)w, ++preparecnt); 4714 ev_start (EV_A_ (W)w, ++preparecnt);
4607 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4715 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4608 prepares [preparecnt - 1] = w; 4716 prepares [preparecnt - 1] = w;
4609 4717
4610 EV_FREQUENT_CHECK; 4718 EV_FREQUENT_CHECK;
4611} 4719}
4612 4720
4613void 4721void
4614ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4722ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4615{ 4723{
4616 clear_pending (EV_A_ (W)w); 4724 clear_pending (EV_A_ (W)w);
4617 if (expect_false (!ev_is_active (w))) 4725 if (expect_false (!ev_is_active (w)))
4618 return; 4726 return;
4619 4727
4632} 4740}
4633#endif 4741#endif
4634 4742
4635#if EV_CHECK_ENABLE 4743#if EV_CHECK_ENABLE
4636void 4744void
4637ev_check_start (EV_P_ ev_check *w) EV_THROW 4745ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4638{ 4746{
4639 if (expect_false (ev_is_active (w))) 4747 if (expect_false (ev_is_active (w)))
4640 return; 4748 return;
4641 4749
4642 EV_FREQUENT_CHECK; 4750 EV_FREQUENT_CHECK;
4643 4751
4644 ev_start (EV_A_ (W)w, ++checkcnt); 4752 ev_start (EV_A_ (W)w, ++checkcnt);
4645 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4753 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4646 checks [checkcnt - 1] = w; 4754 checks [checkcnt - 1] = w;
4647 4755
4648 EV_FREQUENT_CHECK; 4756 EV_FREQUENT_CHECK;
4649} 4757}
4650 4758
4651void 4759void
4652ev_check_stop (EV_P_ ev_check *w) EV_THROW 4760ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4653{ 4761{
4654 clear_pending (EV_A_ (W)w); 4762 clear_pending (EV_A_ (W)w);
4655 if (expect_false (!ev_is_active (w))) 4763 if (expect_false (!ev_is_active (w)))
4656 return; 4764 return;
4657 4765
4669 EV_FREQUENT_CHECK; 4777 EV_FREQUENT_CHECK;
4670} 4778}
4671#endif 4779#endif
4672 4780
4673#if EV_EMBED_ENABLE 4781#if EV_EMBED_ENABLE
4674void noinline 4782noinline
4783void
4675ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4784ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4676{ 4785{
4677 ev_run (w->other, EVRUN_NOWAIT); 4786 ev_run (w->other, EVRUN_NOWAIT);
4678} 4787}
4679 4788
4680static void 4789static void
4728 ev_idle_stop (EV_A_ idle); 4837 ev_idle_stop (EV_A_ idle);
4729} 4838}
4730#endif 4839#endif
4731 4840
4732void 4841void
4733ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4842ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4734{ 4843{
4735 if (expect_false (ev_is_active (w))) 4844 if (expect_false (ev_is_active (w)))
4736 return; 4845 return;
4737 4846
4738 { 4847 {
4759 4868
4760 EV_FREQUENT_CHECK; 4869 EV_FREQUENT_CHECK;
4761} 4870}
4762 4871
4763void 4872void
4764ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4873ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4765{ 4874{
4766 clear_pending (EV_A_ (W)w); 4875 clear_pending (EV_A_ (W)w);
4767 if (expect_false (!ev_is_active (w))) 4876 if (expect_false (!ev_is_active (w)))
4768 return; 4877 return;
4769 4878
4779} 4888}
4780#endif 4889#endif
4781 4890
4782#if EV_FORK_ENABLE 4891#if EV_FORK_ENABLE
4783void 4892void
4784ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4893ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4785{ 4894{
4786 if (expect_false (ev_is_active (w))) 4895 if (expect_false (ev_is_active (w)))
4787 return; 4896 return;
4788 4897
4789 EV_FREQUENT_CHECK; 4898 EV_FREQUENT_CHECK;
4790 4899
4791 ev_start (EV_A_ (W)w, ++forkcnt); 4900 ev_start (EV_A_ (W)w, ++forkcnt);
4792 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4901 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4793 forks [forkcnt - 1] = w; 4902 forks [forkcnt - 1] = w;
4794 4903
4795 EV_FREQUENT_CHECK; 4904 EV_FREQUENT_CHECK;
4796} 4905}
4797 4906
4798void 4907void
4799ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4908ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4800{ 4909{
4801 clear_pending (EV_A_ (W)w); 4910 clear_pending (EV_A_ (W)w);
4802 if (expect_false (!ev_is_active (w))) 4911 if (expect_false (!ev_is_active (w)))
4803 return; 4912 return;
4804 4913
4817} 4926}
4818#endif 4927#endif
4819 4928
4820#if EV_CLEANUP_ENABLE 4929#if EV_CLEANUP_ENABLE
4821void 4930void
4822ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4931ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4823{ 4932{
4824 if (expect_false (ev_is_active (w))) 4933 if (expect_false (ev_is_active (w)))
4825 return; 4934 return;
4826 4935
4827 EV_FREQUENT_CHECK; 4936 EV_FREQUENT_CHECK;
4828 4937
4829 ev_start (EV_A_ (W)w, ++cleanupcnt); 4938 ev_start (EV_A_ (W)w, ++cleanupcnt);
4830 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4939 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4831 cleanups [cleanupcnt - 1] = w; 4940 cleanups [cleanupcnt - 1] = w;
4832 4941
4833 /* cleanup watchers should never keep a refcount on the loop */ 4942 /* cleanup watchers should never keep a refcount on the loop */
4834 ev_unref (EV_A); 4943 ev_unref (EV_A);
4835 EV_FREQUENT_CHECK; 4944 EV_FREQUENT_CHECK;
4836} 4945}
4837 4946
4838void 4947void
4839ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4948ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4840{ 4949{
4841 clear_pending (EV_A_ (W)w); 4950 clear_pending (EV_A_ (W)w);
4842 if (expect_false (!ev_is_active (w))) 4951 if (expect_false (!ev_is_active (w)))
4843 return; 4952 return;
4844 4953
4858} 4967}
4859#endif 4968#endif
4860 4969
4861#if EV_ASYNC_ENABLE 4970#if EV_ASYNC_ENABLE
4862void 4971void
4863ev_async_start (EV_P_ ev_async *w) EV_THROW 4972ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4864{ 4973{
4865 if (expect_false (ev_is_active (w))) 4974 if (expect_false (ev_is_active (w)))
4866 return; 4975 return;
4867 4976
4868 w->sent = 0; 4977 w->sent = 0;
4870 evpipe_init (EV_A); 4979 evpipe_init (EV_A);
4871 4980
4872 EV_FREQUENT_CHECK; 4981 EV_FREQUENT_CHECK;
4873 4982
4874 ev_start (EV_A_ (W)w, ++asynccnt); 4983 ev_start (EV_A_ (W)w, ++asynccnt);
4875 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4984 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4876 asyncs [asynccnt - 1] = w; 4985 asyncs [asynccnt - 1] = w;
4877 4986
4878 EV_FREQUENT_CHECK; 4987 EV_FREQUENT_CHECK;
4879} 4988}
4880 4989
4881void 4990void
4882ev_async_stop (EV_P_ ev_async *w) EV_THROW 4991ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4883{ 4992{
4884 clear_pending (EV_A_ (W)w); 4993 clear_pending (EV_A_ (W)w);
4885 if (expect_false (!ev_is_active (w))) 4994 if (expect_false (!ev_is_active (w)))
4886 return; 4995 return;
4887 4996
4898 5007
4899 EV_FREQUENT_CHECK; 5008 EV_FREQUENT_CHECK;
4900} 5009}
4901 5010
4902void 5011void
4903ev_async_send (EV_P_ ev_async *w) EV_THROW 5012ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4904{ 5013{
4905 w->sent = 1; 5014 w->sent = 1;
4906 evpipe_write (EV_A_ &async_pending); 5015 evpipe_write (EV_A_ &async_pending);
4907} 5016}
4908#endif 5017#endif
4945 5054
4946 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5055 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4947} 5056}
4948 5057
4949void 5058void
4950ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5059ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
4951{ 5060{
4952 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5061 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4953
4954 if (expect_false (!once))
4955 {
4956 cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg);
4957 return;
4958 }
4959 5062
4960 once->cb = cb; 5063 once->cb = cb;
4961 once->arg = arg; 5064 once->arg = arg;
4962 5065
4963 ev_init (&once->io, once_cb_io); 5066 ev_init (&once->io, once_cb_io);
4976} 5079}
4977 5080
4978/*****************************************************************************/ 5081/*****************************************************************************/
4979 5082
4980#if EV_WALK_ENABLE 5083#if EV_WALK_ENABLE
4981void ecb_cold 5084ecb_cold
5085void
4982ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5086ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
4983{ 5087{
4984 int i, j; 5088 int i, j;
4985 ev_watcher_list *wl, *wn; 5089 ev_watcher_list *wl, *wn;
4986 5090
4987 if (types & (EV_IO | EV_EMBED)) 5091 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines