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.498 by root, Wed Jun 26 00:01:46 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)
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;
3835 3924
3836 assert (("libev: ev_io_start called with negative fd", fd >= 0)); 3925 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)))); 3926 assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE))));
3838 3927
3928#if EV_VERIFY >= 2
3929 assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd)));
3930#endif
3839 EV_FREQUENT_CHECK; 3931 EV_FREQUENT_CHECK;
3840 3932
3841 ev_start (EV_A_ (W)w, 1); 3933 ev_start (EV_A_ (W)w, 1);
3842 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3934 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill);
3843 wlist_add (&anfds[fd].head, (WL)w); 3935 wlist_add (&anfds[fd].head, (WL)w);
3844 3936
3845 /* common bug, apparently */ 3937 /* common bug, apparently */
3846 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); 3938 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3847 3939
3849 w->events &= ~EV__IOFDSET; 3941 w->events &= ~EV__IOFDSET;
3850 3942
3851 EV_FREQUENT_CHECK; 3943 EV_FREQUENT_CHECK;
3852} 3944}
3853 3945
3854void noinline 3946noinline
3947void
3855ev_io_stop (EV_P_ ev_io *w) EV_THROW 3948ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3856{ 3949{
3857 clear_pending (EV_A_ (W)w); 3950 clear_pending (EV_A_ (W)w);
3858 if (expect_false (!ev_is_active (w))) 3951 if (expect_false (!ev_is_active (w)))
3859 return; 3952 return;
3860 3953
3861 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); 3954 assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax));
3862 3955
3956#if EV_VERIFY >= 2
3957 assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd)));
3958#endif
3863 EV_FREQUENT_CHECK; 3959 EV_FREQUENT_CHECK;
3864 3960
3865 wlist_del (&anfds[w->fd].head, (WL)w); 3961 wlist_del (&anfds[w->fd].head, (WL)w);
3866 ev_stop (EV_A_ (W)w); 3962 ev_stop (EV_A_ (W)w);
3867 3963
3868 fd_change (EV_A_ w->fd, EV_ANFD_REIFY); 3964 fd_change (EV_A_ w->fd, EV_ANFD_REIFY);
3869 3965
3870 EV_FREQUENT_CHECK; 3966 EV_FREQUENT_CHECK;
3871} 3967}
3872 3968
3873void noinline 3969noinline
3970void
3874ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3971ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3875{ 3972{
3876 if (expect_false (ev_is_active (w))) 3973 if (expect_false (ev_is_active (w)))
3877 return; 3974 return;
3878 3975
3879 ev_at (w) += mn_now; 3976 ev_at (w) += mn_now;
3882 3979
3883 EV_FREQUENT_CHECK; 3980 EV_FREQUENT_CHECK;
3884 3981
3885 ++timercnt; 3982 ++timercnt;
3886 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); 3983 ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1);
3887 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); 3984 array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit);
3888 ANHE_w (timers [ev_active (w)]) = (WT)w; 3985 ANHE_w (timers [ev_active (w)]) = (WT)w;
3889 ANHE_at_cache (timers [ev_active (w)]); 3986 ANHE_at_cache (timers [ev_active (w)]);
3890 upheap (timers, ev_active (w)); 3987 upheap (timers, ev_active (w));
3891 3988
3892 EV_FREQUENT_CHECK; 3989 EV_FREQUENT_CHECK;
3893 3990
3894 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3991 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3895} 3992}
3896 3993
3897void noinline 3994noinline
3995void
3898ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3996ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3899{ 3997{
3900 clear_pending (EV_A_ (W)w); 3998 clear_pending (EV_A_ (W)w);
3901 if (expect_false (!ev_is_active (w))) 3999 if (expect_false (!ev_is_active (w)))
3902 return; 4000 return;
3903 4001
3922 ev_stop (EV_A_ (W)w); 4020 ev_stop (EV_A_ (W)w);
3923 4021
3924 EV_FREQUENT_CHECK; 4022 EV_FREQUENT_CHECK;
3925} 4023}
3926 4024
3927void noinline 4025noinline
4026void
3928ev_timer_again (EV_P_ ev_timer *w) EV_THROW 4027ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3929{ 4028{
3930 EV_FREQUENT_CHECK; 4029 EV_FREQUENT_CHECK;
3931 4030
3932 clear_pending (EV_A_ (W)w); 4031 clear_pending (EV_A_ (W)w);
3933 4032
3950 4049
3951 EV_FREQUENT_CHECK; 4050 EV_FREQUENT_CHECK;
3952} 4051}
3953 4052
3954ev_tstamp 4053ev_tstamp
3955ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 4054ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3956{ 4055{
3957 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4056 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3958} 4057}
3959 4058
3960#if EV_PERIODIC_ENABLE 4059#if EV_PERIODIC_ENABLE
3961void noinline 4060noinline
4061void
3962ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4062ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
3963{ 4063{
3964 if (expect_false (ev_is_active (w))) 4064 if (expect_false (ev_is_active (w)))
3965 return; 4065 return;
3966 4066
3967 if (w->reschedule_cb) 4067 if (w->reschedule_cb)
3976 4076
3977 EV_FREQUENT_CHECK; 4077 EV_FREQUENT_CHECK;
3978 4078
3979 ++periodiccnt; 4079 ++periodiccnt;
3980 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); 4080 ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1);
3981 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); 4081 array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit);
3982 ANHE_w (periodics [ev_active (w)]) = (WT)w; 4082 ANHE_w (periodics [ev_active (w)]) = (WT)w;
3983 ANHE_at_cache (periodics [ev_active (w)]); 4083 ANHE_at_cache (periodics [ev_active (w)]);
3984 upheap (periodics, ev_active (w)); 4084 upheap (periodics, ev_active (w));
3985 4085
3986 EV_FREQUENT_CHECK; 4086 EV_FREQUENT_CHECK;
3987 4087
3988 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4088 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3989} 4089}
3990 4090
3991void noinline 4091noinline
4092void
3992ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4093ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
3993{ 4094{
3994 clear_pending (EV_A_ (W)w); 4095 clear_pending (EV_A_ (W)w);
3995 if (expect_false (!ev_is_active (w))) 4096 if (expect_false (!ev_is_active (w)))
3996 return; 4097 return;
3997 4098
4014 ev_stop (EV_A_ (W)w); 4115 ev_stop (EV_A_ (W)w);
4015 4116
4016 EV_FREQUENT_CHECK; 4117 EV_FREQUENT_CHECK;
4017} 4118}
4018 4119
4019void noinline 4120noinline
4121void
4020ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4122ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4021{ 4123{
4022 /* TODO: use adjustheap and recalculation */ 4124 /* TODO: use adjustheap and recalculation */
4023 ev_periodic_stop (EV_A_ w); 4125 ev_periodic_stop (EV_A_ w);
4024 ev_periodic_start (EV_A_ w); 4126 ev_periodic_start (EV_A_ w);
4025} 4127}
4029# define SA_RESTART 0 4131# define SA_RESTART 0
4030#endif 4132#endif
4031 4133
4032#if EV_SIGNAL_ENABLE 4134#if EV_SIGNAL_ENABLE
4033 4135
4034void noinline 4136noinline
4137void
4035ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4138ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4036{ 4139{
4037 if (expect_false (ev_is_active (w))) 4140 if (expect_false (ev_is_active (w)))
4038 return; 4141 return;
4039 4142
4040 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4143 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4111 } 4214 }
4112 4215
4113 EV_FREQUENT_CHECK; 4216 EV_FREQUENT_CHECK;
4114} 4217}
4115 4218
4116void noinline 4219noinline
4220void
4117ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4221ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4118{ 4222{
4119 clear_pending (EV_A_ (W)w); 4223 clear_pending (EV_A_ (W)w);
4120 if (expect_false (!ev_is_active (w))) 4224 if (expect_false (!ev_is_active (w)))
4121 return; 4225 return;
4122 4226
4153#endif 4257#endif
4154 4258
4155#if EV_CHILD_ENABLE 4259#if EV_CHILD_ENABLE
4156 4260
4157void 4261void
4158ev_child_start (EV_P_ ev_child *w) EV_THROW 4262ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4159{ 4263{
4160#if EV_MULTIPLICITY 4264#if EV_MULTIPLICITY
4161 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4265 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4162#endif 4266#endif
4163 if (expect_false (ev_is_active (w))) 4267 if (expect_false (ev_is_active (w)))
4170 4274
4171 EV_FREQUENT_CHECK; 4275 EV_FREQUENT_CHECK;
4172} 4276}
4173 4277
4174void 4278void
4175ev_child_stop (EV_P_ ev_child *w) EV_THROW 4279ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4176{ 4280{
4177 clear_pending (EV_A_ (W)w); 4281 clear_pending (EV_A_ (W)w);
4178 if (expect_false (!ev_is_active (w))) 4282 if (expect_false (!ev_is_active (w)))
4179 return; 4283 return;
4180 4284
4197 4301
4198#define DEF_STAT_INTERVAL 5.0074891 4302#define DEF_STAT_INTERVAL 5.0074891
4199#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ 4303#define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */
4200#define MIN_STAT_INTERVAL 0.1074891 4304#define MIN_STAT_INTERVAL 0.1074891
4201 4305
4202static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); 4306noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents);
4203 4307
4204#if EV_USE_INOTIFY 4308#if EV_USE_INOTIFY
4205 4309
4206/* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ 4310/* 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) 4311# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
4208 4312
4209static void noinline 4313noinline
4314static void
4210infy_add (EV_P_ ev_stat *w) 4315infy_add (EV_P_ ev_stat *w)
4211{ 4316{
4212 w->wd = inotify_add_watch (fs_fd, w->path, 4317 w->wd = inotify_add_watch (fs_fd, w->path,
4213 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY 4318 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
4214 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO 4319 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
4278 if (ev_is_active (&w->timer)) ev_ref (EV_A); 4383 if (ev_is_active (&w->timer)) ev_ref (EV_A);
4279 ev_timer_again (EV_A_ &w->timer); 4384 ev_timer_again (EV_A_ &w->timer);
4280 if (ev_is_active (&w->timer)) ev_unref (EV_A); 4385 if (ev_is_active (&w->timer)) ev_unref (EV_A);
4281} 4386}
4282 4387
4283static void noinline 4388noinline
4389static void
4284infy_del (EV_P_ ev_stat *w) 4390infy_del (EV_P_ ev_stat *w)
4285{ 4391{
4286 int slot; 4392 int slot;
4287 int wd = w->wd; 4393 int wd = w->wd;
4288 4394
4295 4401
4296 /* remove this watcher, if others are watching it, they will rearm */ 4402 /* remove this watcher, if others are watching it, they will rearm */
4297 inotify_rm_watch (fs_fd, wd); 4403 inotify_rm_watch (fs_fd, wd);
4298} 4404}
4299 4405
4300static void noinline 4406noinline
4407static void
4301infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) 4408infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev)
4302{ 4409{
4303 if (slot < 0) 4410 if (slot < 0)
4304 /* overflow, need to check for all hash slots */ 4411 /* overflow, need to check for all hash slots */
4305 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) 4412 for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot)
4341 infy_wd (EV_A_ ev->wd, ev->wd, ev); 4448 infy_wd (EV_A_ ev->wd, ev->wd, ev);
4342 ofs += sizeof (struct inotify_event) + ev->len; 4449 ofs += sizeof (struct inotify_event) + ev->len;
4343 } 4450 }
4344} 4451}
4345 4452
4346inline_size void ecb_cold 4453inline_size ecb_cold
4454void
4347ev_check_2625 (EV_P) 4455ev_check_2625 (EV_P)
4348{ 4456{
4349 /* kernels < 2.6.25 are borked 4457 /* kernels < 2.6.25 are borked
4350 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html 4458 * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html
4351 */ 4459 */
4441#else 4549#else
4442# define EV_LSTAT(p,b) lstat (p, b) 4550# define EV_LSTAT(p,b) lstat (p, b)
4443#endif 4551#endif
4444 4552
4445void 4553void
4446ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4554ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4447{ 4555{
4448 if (lstat (w->path, &w->attr) < 0) 4556 if (lstat (w->path, &w->attr) < 0)
4449 w->attr.st_nlink = 0; 4557 w->attr.st_nlink = 0;
4450 else if (!w->attr.st_nlink) 4558 else if (!w->attr.st_nlink)
4451 w->attr.st_nlink = 1; 4559 w->attr.st_nlink = 1;
4452} 4560}
4453 4561
4454static void noinline 4562noinline
4563static void
4455stat_timer_cb (EV_P_ ev_timer *w_, int revents) 4564stat_timer_cb (EV_P_ ev_timer *w_, int revents)
4456{ 4565{
4457 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); 4566 ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer));
4458 4567
4459 ev_statdata prev = w->attr; 4568 ev_statdata prev = w->attr;
4490 ev_feed_event (EV_A_ w, EV_STAT); 4599 ev_feed_event (EV_A_ w, EV_STAT);
4491 } 4600 }
4492} 4601}
4493 4602
4494void 4603void
4495ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4604ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4496{ 4605{
4497 if (expect_false (ev_is_active (w))) 4606 if (expect_false (ev_is_active (w)))
4498 return; 4607 return;
4499 4608
4500 ev_stat_stat (EV_A_ w); 4609 ev_stat_stat (EV_A_ w);
4521 4630
4522 EV_FREQUENT_CHECK; 4631 EV_FREQUENT_CHECK;
4523} 4632}
4524 4633
4525void 4634void
4526ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4635ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4527{ 4636{
4528 clear_pending (EV_A_ (W)w); 4637 clear_pending (EV_A_ (W)w);
4529 if (expect_false (!ev_is_active (w))) 4638 if (expect_false (!ev_is_active (w)))
4530 return; 4639 return;
4531 4640
4547} 4656}
4548#endif 4657#endif
4549 4658
4550#if EV_IDLE_ENABLE 4659#if EV_IDLE_ENABLE
4551void 4660void
4552ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4661ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4553{ 4662{
4554 if (expect_false (ev_is_active (w))) 4663 if (expect_false (ev_is_active (w)))
4555 return; 4664 return;
4556 4665
4557 pri_adjust (EV_A_ (W)w); 4666 pri_adjust (EV_A_ (W)w);
4562 int active = ++idlecnt [ABSPRI (w)]; 4671 int active = ++idlecnt [ABSPRI (w)];
4563 4672
4564 ++idleall; 4673 ++idleall;
4565 ev_start (EV_A_ (W)w, active); 4674 ev_start (EV_A_ (W)w, active);
4566 4675
4567 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); 4676 array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit);
4568 idles [ABSPRI (w)][active - 1] = w; 4677 idles [ABSPRI (w)][active - 1] = w;
4569 } 4678 }
4570 4679
4571 EV_FREQUENT_CHECK; 4680 EV_FREQUENT_CHECK;
4572} 4681}
4573 4682
4574void 4683void
4575ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4684ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4576{ 4685{
4577 clear_pending (EV_A_ (W)w); 4686 clear_pending (EV_A_ (W)w);
4578 if (expect_false (!ev_is_active (w))) 4687 if (expect_false (!ev_is_active (w)))
4579 return; 4688 return;
4580 4689
4594} 4703}
4595#endif 4704#endif
4596 4705
4597#if EV_PREPARE_ENABLE 4706#if EV_PREPARE_ENABLE
4598void 4707void
4599ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4708ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4600{ 4709{
4601 if (expect_false (ev_is_active (w))) 4710 if (expect_false (ev_is_active (w)))
4602 return; 4711 return;
4603 4712
4604 EV_FREQUENT_CHECK; 4713 EV_FREQUENT_CHECK;
4605 4714
4606 ev_start (EV_A_ (W)w, ++preparecnt); 4715 ev_start (EV_A_ (W)w, ++preparecnt);
4607 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); 4716 array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit);
4608 prepares [preparecnt - 1] = w; 4717 prepares [preparecnt - 1] = w;
4609 4718
4610 EV_FREQUENT_CHECK; 4719 EV_FREQUENT_CHECK;
4611} 4720}
4612 4721
4613void 4722void
4614ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4723ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4615{ 4724{
4616 clear_pending (EV_A_ (W)w); 4725 clear_pending (EV_A_ (W)w);
4617 if (expect_false (!ev_is_active (w))) 4726 if (expect_false (!ev_is_active (w)))
4618 return; 4727 return;
4619 4728
4632} 4741}
4633#endif 4742#endif
4634 4743
4635#if EV_CHECK_ENABLE 4744#if EV_CHECK_ENABLE
4636void 4745void
4637ev_check_start (EV_P_ ev_check *w) EV_THROW 4746ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4638{ 4747{
4639 if (expect_false (ev_is_active (w))) 4748 if (expect_false (ev_is_active (w)))
4640 return; 4749 return;
4641 4750
4642 EV_FREQUENT_CHECK; 4751 EV_FREQUENT_CHECK;
4643 4752
4644 ev_start (EV_A_ (W)w, ++checkcnt); 4753 ev_start (EV_A_ (W)w, ++checkcnt);
4645 array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); 4754 array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit);
4646 checks [checkcnt - 1] = w; 4755 checks [checkcnt - 1] = w;
4647 4756
4648 EV_FREQUENT_CHECK; 4757 EV_FREQUENT_CHECK;
4649} 4758}
4650 4759
4651void 4760void
4652ev_check_stop (EV_P_ ev_check *w) EV_THROW 4761ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4653{ 4762{
4654 clear_pending (EV_A_ (W)w); 4763 clear_pending (EV_A_ (W)w);
4655 if (expect_false (!ev_is_active (w))) 4764 if (expect_false (!ev_is_active (w)))
4656 return; 4765 return;
4657 4766
4669 EV_FREQUENT_CHECK; 4778 EV_FREQUENT_CHECK;
4670} 4779}
4671#endif 4780#endif
4672 4781
4673#if EV_EMBED_ENABLE 4782#if EV_EMBED_ENABLE
4674void noinline 4783noinline
4784void
4675ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4785ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4676{ 4786{
4677 ev_run (w->other, EVRUN_NOWAIT); 4787 ev_run (w->other, EVRUN_NOWAIT);
4678} 4788}
4679 4789
4680static void 4790static void
4728 ev_idle_stop (EV_A_ idle); 4838 ev_idle_stop (EV_A_ idle);
4729} 4839}
4730#endif 4840#endif
4731 4841
4732void 4842void
4733ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4843ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4734{ 4844{
4735 if (expect_false (ev_is_active (w))) 4845 if (expect_false (ev_is_active (w)))
4736 return; 4846 return;
4737 4847
4738 { 4848 {
4759 4869
4760 EV_FREQUENT_CHECK; 4870 EV_FREQUENT_CHECK;
4761} 4871}
4762 4872
4763void 4873void
4764ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4874ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4765{ 4875{
4766 clear_pending (EV_A_ (W)w); 4876 clear_pending (EV_A_ (W)w);
4767 if (expect_false (!ev_is_active (w))) 4877 if (expect_false (!ev_is_active (w)))
4768 return; 4878 return;
4769 4879
4779} 4889}
4780#endif 4890#endif
4781 4891
4782#if EV_FORK_ENABLE 4892#if EV_FORK_ENABLE
4783void 4893void
4784ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4894ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4785{ 4895{
4786 if (expect_false (ev_is_active (w))) 4896 if (expect_false (ev_is_active (w)))
4787 return; 4897 return;
4788 4898
4789 EV_FREQUENT_CHECK; 4899 EV_FREQUENT_CHECK;
4790 4900
4791 ev_start (EV_A_ (W)w, ++forkcnt); 4901 ev_start (EV_A_ (W)w, ++forkcnt);
4792 array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); 4902 array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit);
4793 forks [forkcnt - 1] = w; 4903 forks [forkcnt - 1] = w;
4794 4904
4795 EV_FREQUENT_CHECK; 4905 EV_FREQUENT_CHECK;
4796} 4906}
4797 4907
4798void 4908void
4799ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4909ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4800{ 4910{
4801 clear_pending (EV_A_ (W)w); 4911 clear_pending (EV_A_ (W)w);
4802 if (expect_false (!ev_is_active (w))) 4912 if (expect_false (!ev_is_active (w)))
4803 return; 4913 return;
4804 4914
4817} 4927}
4818#endif 4928#endif
4819 4929
4820#if EV_CLEANUP_ENABLE 4930#if EV_CLEANUP_ENABLE
4821void 4931void
4822ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4932ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4823{ 4933{
4824 if (expect_false (ev_is_active (w))) 4934 if (expect_false (ev_is_active (w)))
4825 return; 4935 return;
4826 4936
4827 EV_FREQUENT_CHECK; 4937 EV_FREQUENT_CHECK;
4828 4938
4829 ev_start (EV_A_ (W)w, ++cleanupcnt); 4939 ev_start (EV_A_ (W)w, ++cleanupcnt);
4830 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); 4940 array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit);
4831 cleanups [cleanupcnt - 1] = w; 4941 cleanups [cleanupcnt - 1] = w;
4832 4942
4833 /* cleanup watchers should never keep a refcount on the loop */ 4943 /* cleanup watchers should never keep a refcount on the loop */
4834 ev_unref (EV_A); 4944 ev_unref (EV_A);
4835 EV_FREQUENT_CHECK; 4945 EV_FREQUENT_CHECK;
4836} 4946}
4837 4947
4838void 4948void
4839ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4949ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4840{ 4950{
4841 clear_pending (EV_A_ (W)w); 4951 clear_pending (EV_A_ (W)w);
4842 if (expect_false (!ev_is_active (w))) 4952 if (expect_false (!ev_is_active (w)))
4843 return; 4953 return;
4844 4954
4858} 4968}
4859#endif 4969#endif
4860 4970
4861#if EV_ASYNC_ENABLE 4971#if EV_ASYNC_ENABLE
4862void 4972void
4863ev_async_start (EV_P_ ev_async *w) EV_THROW 4973ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4864{ 4974{
4865 if (expect_false (ev_is_active (w))) 4975 if (expect_false (ev_is_active (w)))
4866 return; 4976 return;
4867 4977
4868 w->sent = 0; 4978 w->sent = 0;
4870 evpipe_init (EV_A); 4980 evpipe_init (EV_A);
4871 4981
4872 EV_FREQUENT_CHECK; 4982 EV_FREQUENT_CHECK;
4873 4983
4874 ev_start (EV_A_ (W)w, ++asynccnt); 4984 ev_start (EV_A_ (W)w, ++asynccnt);
4875 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); 4985 array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit);
4876 asyncs [asynccnt - 1] = w; 4986 asyncs [asynccnt - 1] = w;
4877 4987
4878 EV_FREQUENT_CHECK; 4988 EV_FREQUENT_CHECK;
4879} 4989}
4880 4990
4881void 4991void
4882ev_async_stop (EV_P_ ev_async *w) EV_THROW 4992ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4883{ 4993{
4884 clear_pending (EV_A_ (W)w); 4994 clear_pending (EV_A_ (W)w);
4885 if (expect_false (!ev_is_active (w))) 4995 if (expect_false (!ev_is_active (w)))
4886 return; 4996 return;
4887 4997
4898 5008
4899 EV_FREQUENT_CHECK; 5009 EV_FREQUENT_CHECK;
4900} 5010}
4901 5011
4902void 5012void
4903ev_async_send (EV_P_ ev_async *w) EV_THROW 5013ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4904{ 5014{
4905 w->sent = 1; 5015 w->sent = 1;
4906 evpipe_write (EV_A_ &async_pending); 5016 evpipe_write (EV_A_ &async_pending);
4907} 5017}
4908#endif 5018#endif
4945 5055
4946 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5056 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4947} 5057}
4948 5058
4949void 5059void
4950ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5060ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
4951{ 5061{
4952 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5062 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 5063
4960 once->cb = cb; 5064 once->cb = cb;
4961 once->arg = arg; 5065 once->arg = arg;
4962 5066
4963 ev_init (&once->io, once_cb_io); 5067 ev_init (&once->io, once_cb_io);
4976} 5080}
4977 5081
4978/*****************************************************************************/ 5082/*****************************************************************************/
4979 5083
4980#if EV_WALK_ENABLE 5084#if EV_WALK_ENABLE
4981void ecb_cold 5085ecb_cold
5086void
4982ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5087ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
4983{ 5088{
4984 int i, j; 5089 int i, j;
4985 ev_watcher_list *wl, *wn; 5090 ev_watcher_list *wl, *wn;
4986 5091
4987 if (types & (EV_IO | EV_EMBED)) 5092 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines