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

Comparing libev/ev.c (file contents):
Revision 1.484 by root, Tue Jul 31 05:40:58 2018 UTC vs.
Revision 1.488 by root, Fri Dec 21 06:57:09 2018 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-2018 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 *
609 #define ECB_CLANG_EXTENSION(x) 0 609 #define ECB_CLANG_EXTENSION(x) 0
610#endif 610#endif
611 611
612#define ECB_CPP (__cplusplus+0) 612#define ECB_CPP (__cplusplus+0)
613#define ECB_CPP11 (__cplusplus >= 201103L) 613#define ECB_CPP11 (__cplusplus >= 201103L)
614#define ECB_CPP14 (__cplusplus >= 201402L)
615#define ECB_CPP17 (__cplusplus >= 201703L)
614 616
615#if ECB_CPP 617#if ECB_CPP
616 #define ECB_C 0 618 #define ECB_C 0
617 #define ECB_STDC_VERSION 0 619 #define ECB_STDC_VERSION 0
618#else 620#else
620 #define ECB_STDC_VERSION __STDC_VERSION__ 622 #define ECB_STDC_VERSION __STDC_VERSION__
621#endif 623#endif
622 624
623#define ECB_C99 (ECB_STDC_VERSION >= 199901L) 625#define ECB_C99 (ECB_STDC_VERSION >= 199901L)
624#define ECB_C11 (ECB_STDC_VERSION >= 201112L) 626#define ECB_C11 (ECB_STDC_VERSION >= 201112L)
627#define ECB_C17 (ECB_STDC_VERSION >= 201710L)
625 628
626#if ECB_CPP 629#if ECB_CPP
627 #define ECB_EXTERN_C extern "C" 630 #define ECB_EXTERN_C extern "C"
628 #define ECB_EXTERN_C_BEG ECB_EXTERN_C { 631 #define ECB_EXTERN_C_BEG ECB_EXTERN_C {
629 #define ECB_EXTERN_C_END } 632 #define ECB_EXTERN_C_END }
658#ifndef ECB_MEMORY_FENCE 661#ifndef ECB_MEMORY_FENCE
659 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 662 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
660 #if __i386 || __i386__ 663 #if __i386 || __i386__
661 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 664 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
662 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 665 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
663 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 666 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
664 #elif ECB_GCC_AMD64 667 #elif ECB_GCC_AMD64
665 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 668 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
666 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") 669 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory")
667 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 670 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory")
668 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 671 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
669 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 672 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
670 #elif defined __ARM_ARCH_2__ \ 673 #elif defined __ARM_ARCH_2__ \
671 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ 674 || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \
672 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ 675 || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \
1677{ 1680{
1678 write (STDERR_FILENO, msg, strlen (msg)); 1681 write (STDERR_FILENO, msg, strlen (msg));
1679} 1682}
1680#endif 1683#endif
1681 1684
1682static void (*syserr_cb)(const char *msg) EV_THROW; 1685static void (*syserr_cb)(const char *msg) EV_NOEXCEPT;
1683 1686
1684ecb_cold 1687ecb_cold
1685void 1688void
1686ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW 1689ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT
1687{ 1690{
1688 syserr_cb = cb; 1691 syserr_cb = cb;
1689} 1692}
1690 1693
1691noinline ecb_cold 1694noinline ecb_cold
1710 abort (); 1713 abort ();
1711 } 1714 }
1712} 1715}
1713 1716
1714static void * 1717static void *
1715ev_realloc_emul (void *ptr, long size) EV_THROW 1718ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT
1716{ 1719{
1717 /* some systems, notably openbsd and darwin, fail to properly 1720 /* some systems, notably openbsd and darwin, fail to properly
1718 * implement realloc (x, 0) (as required by both ansi c-89 and 1721 * implement realloc (x, 0) (as required by both ansi c-89 and
1719 * the single unix specification, so work around them here. 1722 * the single unix specification, so work around them here.
1720 * recently, also (at least) fedora and debian started breaking it, 1723 * recently, also (at least) fedora and debian started breaking it,
1726 1729
1727 free (ptr); 1730 free (ptr);
1728 return 0; 1731 return 0;
1729} 1732}
1730 1733
1731static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; 1734static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul;
1732 1735
1733ecb_cold 1736ecb_cold
1734void 1737void
1735ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW 1738ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT
1736{ 1739{
1737 alloc = cb; 1740 alloc = cb;
1738} 1741}
1739 1742
1740inline_speed void * 1743inline_speed void *
1857 1860
1858/*****************************************************************************/ 1861/*****************************************************************************/
1859 1862
1860#ifndef EV_HAVE_EV_TIME 1863#ifndef EV_HAVE_EV_TIME
1861ev_tstamp 1864ev_tstamp
1862ev_time (void) EV_THROW 1865ev_time (void) EV_NOEXCEPT
1863{ 1866{
1864#if EV_USE_REALTIME 1867#if EV_USE_REALTIME
1865 if (expect_true (have_realtime)) 1868 if (expect_true (have_realtime))
1866 { 1869 {
1867 struct timespec ts; 1870 struct timespec ts;
1891 return ev_time (); 1894 return ev_time ();
1892} 1895}
1893 1896
1894#if EV_MULTIPLICITY 1897#if EV_MULTIPLICITY
1895ev_tstamp 1898ev_tstamp
1896ev_now (EV_P) EV_THROW 1899ev_now (EV_P) EV_NOEXCEPT
1897{ 1900{
1898 return ev_rt_now; 1901 return ev_rt_now;
1899} 1902}
1900#endif 1903#endif
1901 1904
1902void 1905void
1903ev_sleep (ev_tstamp delay) EV_THROW 1906ev_sleep (ev_tstamp delay) EV_NOEXCEPT
1904{ 1907{
1905 if (delay > 0.) 1908 if (delay > 0.)
1906 { 1909 {
1907#if EV_USE_NANOSLEEP 1910#if EV_USE_NANOSLEEP
1908 struct timespec ts; 1911 struct timespec ts;
1994{ 1997{
1995} 1998}
1996 1999
1997noinline 2000noinline
1998void 2001void
1999ev_feed_event (EV_P_ void *w, int revents) EV_THROW 2002ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT
2000{ 2003{
2001 W w_ = (W)w; 2004 W w_ = (W)w;
2002 int pri = ABSPRI (w_); 2005 int pri = ABSPRI (w_);
2003 2006
2004 if (expect_false (w_->pending)) 2007 if (expect_false (w_->pending))
2065 if (expect_true (!anfd->reify)) 2068 if (expect_true (!anfd->reify))
2066 fd_event_nocheck (EV_A_ fd, revents); 2069 fd_event_nocheck (EV_A_ fd, revents);
2067} 2070}
2068 2071
2069void 2072void
2070ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW 2073ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT
2071{ 2074{
2072 if (fd >= 0 && fd < anfdmax) 2075 if (fd >= 0 && fd < anfdmax)
2073 fd_event_nocheck (EV_A_ fd, revents); 2076 fd_event_nocheck (EV_A_ fd, revents);
2074} 2077}
2075 2078
2475#endif 2478#endif
2476 { 2479 {
2477#ifdef _WIN32 2480#ifdef _WIN32
2478 WSABUF buf; 2481 WSABUF buf;
2479 DWORD sent; 2482 DWORD sent;
2480 buf.buf = &buf; 2483 buf.buf = (char *)&buf;
2481 buf.len = 1; 2484 buf.len = 1;
2482 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); 2485 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
2483#else 2486#else
2484 write (evpipe [1], &(evpipe [1]), 1); 2487 write (evpipe [1], &(evpipe [1]), 1);
2485#endif 2488#endif
2557} 2560}
2558 2561
2559/*****************************************************************************/ 2562/*****************************************************************************/
2560 2563
2561void 2564void
2562ev_feed_signal (int signum) EV_THROW 2565ev_feed_signal (int signum) EV_NOEXCEPT
2563{ 2566{
2564#if EV_MULTIPLICITY 2567#if EV_MULTIPLICITY
2565 EV_P; 2568 EV_P;
2566 ECB_MEMORY_FENCE_ACQUIRE; 2569 ECB_MEMORY_FENCE_ACQUIRE;
2567 EV_A = signals [signum - 1].loop; 2570 EV_A = signals [signum - 1].loop;
2584 ev_feed_signal (signum); 2587 ev_feed_signal (signum);
2585} 2588}
2586 2589
2587noinline 2590noinline
2588void 2591void
2589ev_feed_signal_event (EV_P_ int signum) EV_THROW 2592ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT
2590{ 2593{
2591 WL w; 2594 WL w;
2592 2595
2593 if (expect_false (signum <= 0 || signum >= EV_NSIG)) 2596 if (expect_false (signum <= 0 || signum >= EV_NSIG))
2594 return; 2597 return;
2711#if EV_USE_SELECT 2714#if EV_USE_SELECT
2712# include "ev_select.c" 2715# include "ev_select.c"
2713#endif 2716#endif
2714 2717
2715ecb_cold int 2718ecb_cold int
2716ev_version_major (void) EV_THROW 2719ev_version_major (void) EV_NOEXCEPT
2717{ 2720{
2718 return EV_VERSION_MAJOR; 2721 return EV_VERSION_MAJOR;
2719} 2722}
2720 2723
2721ecb_cold int 2724ecb_cold int
2722ev_version_minor (void) EV_THROW 2725ev_version_minor (void) EV_NOEXCEPT
2723{ 2726{
2724 return EV_VERSION_MINOR; 2727 return EV_VERSION_MINOR;
2725} 2728}
2726 2729
2727/* return true if we are running with elevated privileges and should ignore env variables */ 2730/* return true if we are running with elevated privileges and should ignore env variables */
2736#endif 2739#endif
2737} 2740}
2738 2741
2739ecb_cold 2742ecb_cold
2740unsigned int 2743unsigned int
2741ev_supported_backends (void) EV_THROW 2744ev_supported_backends (void) EV_NOEXCEPT
2742{ 2745{
2743 unsigned int flags = 0; 2746 unsigned int flags = 0;
2744 2747
2745 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2748 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2746 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2749 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2751 return flags; 2754 return flags;
2752} 2755}
2753 2756
2754ecb_cold 2757ecb_cold
2755unsigned int 2758unsigned int
2756ev_recommended_backends (void) EV_THROW 2759ev_recommended_backends (void) EV_NOEXCEPT
2757{ 2760{
2758 unsigned int flags = ev_supported_backends (); 2761 unsigned int flags = ev_supported_backends ();
2759 2762
2760#ifndef __NetBSD__ 2763#ifndef __NetBSD__
2761 /* kqueue is borked on everything but netbsd apparently */ 2764 /* kqueue is borked on everything but netbsd apparently */
2774 return flags; 2777 return flags;
2775} 2778}
2776 2779
2777ecb_cold 2780ecb_cold
2778unsigned int 2781unsigned int
2779ev_embeddable_backends (void) EV_THROW 2782ev_embeddable_backends (void) EV_NOEXCEPT
2780{ 2783{
2781 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2784 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2782 2785
2783 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2786 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2784 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2787 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2786 2789
2787 return flags; 2790 return flags;
2788} 2791}
2789 2792
2790unsigned int 2793unsigned int
2791ev_backend (EV_P) EV_THROW 2794ev_backend (EV_P) EV_NOEXCEPT
2792{ 2795{
2793 return backend; 2796 return backend;
2794} 2797}
2795 2798
2796#if EV_FEATURE_API 2799#if EV_FEATURE_API
2797unsigned int 2800unsigned int
2798ev_iteration (EV_P) EV_THROW 2801ev_iteration (EV_P) EV_NOEXCEPT
2799{ 2802{
2800 return loop_count; 2803 return loop_count;
2801} 2804}
2802 2805
2803unsigned int 2806unsigned int
2804ev_depth (EV_P) EV_THROW 2807ev_depth (EV_P) EV_NOEXCEPT
2805{ 2808{
2806 return loop_depth; 2809 return loop_depth;
2807} 2810}
2808 2811
2809void 2812void
2810ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2813ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2811{ 2814{
2812 io_blocktime = interval; 2815 io_blocktime = interval;
2813} 2816}
2814 2817
2815void 2818void
2816ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW 2819ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT
2817{ 2820{
2818 timeout_blocktime = interval; 2821 timeout_blocktime = interval;
2819} 2822}
2820 2823
2821void 2824void
2822ev_set_userdata (EV_P_ void *data) EV_THROW 2825ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT
2823{ 2826{
2824 userdata = data; 2827 userdata = data;
2825} 2828}
2826 2829
2827void * 2830void *
2828ev_userdata (EV_P) EV_THROW 2831ev_userdata (EV_P) EV_NOEXCEPT
2829{ 2832{
2830 return userdata; 2833 return userdata;
2831} 2834}
2832 2835
2833void 2836void
2834ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW 2837ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT
2835{ 2838{
2836 invoke_cb = invoke_pending_cb; 2839 invoke_cb = invoke_pending_cb;
2837} 2840}
2838 2841
2839void 2842void
2840ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW 2843ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT
2841{ 2844{
2842 release_cb = release; 2845 release_cb = release;
2843 acquire_cb = acquire; 2846 acquire_cb = acquire;
2844} 2847}
2845#endif 2848#endif
2846 2849
2847/* initialise a loop structure, must be zero-initialised */ 2850/* initialise a loop structure, must be zero-initialised */
2848noinline ecb_cold 2851noinline ecb_cold
2849static void 2852static void
2850loop_init (EV_P_ unsigned int flags) EV_THROW 2853loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT
2851{ 2854{
2852 if (!backend) 2855 if (!backend)
2853 { 2856 {
2854 origflags = flags; 2857 origflags = flags;
2855 2858
3096 3099
3097#if EV_MULTIPLICITY 3100#if EV_MULTIPLICITY
3098 3101
3099ecb_cold 3102ecb_cold
3100struct ev_loop * 3103struct ev_loop *
3101ev_loop_new (unsigned int flags) EV_THROW 3104ev_loop_new (unsigned int flags) EV_NOEXCEPT
3102{ 3105{
3103 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 3106 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
3104 3107
3105 memset (EV_A, 0, sizeof (struct ev_loop)); 3108 memset (EV_A, 0, sizeof (struct ev_loop));
3106 loop_init (EV_A_ flags); 3109 loop_init (EV_A_ flags);
3153} 3156}
3154#endif 3157#endif
3155 3158
3156#if EV_FEATURE_API 3159#if EV_FEATURE_API
3157void ecb_cold 3160void ecb_cold
3158ev_verify (EV_P) EV_THROW 3161ev_verify (EV_P) EV_NOEXCEPT
3159{ 3162{
3160#if EV_VERIFY 3163#if EV_VERIFY
3161 int i; 3164 int i;
3162 WL w, w2; 3165 WL w, w2;
3163 3166
3244ecb_cold 3247ecb_cold
3245struct ev_loop * 3248struct ev_loop *
3246#else 3249#else
3247int 3250int
3248#endif 3251#endif
3249ev_default_loop (unsigned int flags) EV_THROW 3252ev_default_loop (unsigned int flags) EV_NOEXCEPT
3250{ 3253{
3251 if (!ev_default_loop_ptr) 3254 if (!ev_default_loop_ptr)
3252 { 3255 {
3253#if EV_MULTIPLICITY 3256#if EV_MULTIPLICITY
3254 EV_P = ev_default_loop_ptr = &default_loop_struct; 3257 EV_P = ev_default_loop_ptr = &default_loop_struct;
3273 3276
3274 return ev_default_loop_ptr; 3277 return ev_default_loop_ptr;
3275} 3278}
3276 3279
3277void 3280void
3278ev_loop_fork (EV_P) EV_THROW 3281ev_loop_fork (EV_P) EV_NOEXCEPT
3279{ 3282{
3280 postfork = 1; 3283 postfork = 1;
3281} 3284}
3282 3285
3283/*****************************************************************************/ 3286/*****************************************************************************/
3287{ 3290{
3288 EV_CB_INVOKE ((W)w, revents); 3291 EV_CB_INVOKE ((W)w, revents);
3289} 3292}
3290 3293
3291unsigned int 3294unsigned int
3292ev_pending_count (EV_P) EV_THROW 3295ev_pending_count (EV_P) EV_NOEXCEPT
3293{ 3296{
3294 int pri; 3297 int pri;
3295 unsigned int count = 0; 3298 unsigned int count = 0;
3296 3299
3297 for (pri = NUMPRI; pri--; ) 3300 for (pri = NUMPRI; pri--; )
3737 3740
3738 return activecnt; 3741 return activecnt;
3739} 3742}
3740 3743
3741void 3744void
3742ev_break (EV_P_ int how) EV_THROW 3745ev_break (EV_P_ int how) EV_NOEXCEPT
3743{ 3746{
3744 loop_done = how; 3747 loop_done = how;
3745} 3748}
3746 3749
3747void 3750void
3748ev_ref (EV_P) EV_THROW 3751ev_ref (EV_P) EV_NOEXCEPT
3749{ 3752{
3750 ++activecnt; 3753 ++activecnt;
3751} 3754}
3752 3755
3753void 3756void
3754ev_unref (EV_P) EV_THROW 3757ev_unref (EV_P) EV_NOEXCEPT
3755{ 3758{
3756 --activecnt; 3759 --activecnt;
3757} 3760}
3758 3761
3759void 3762void
3760ev_now_update (EV_P) EV_THROW 3763ev_now_update (EV_P) EV_NOEXCEPT
3761{ 3764{
3762 time_update (EV_A_ 1e100); 3765 time_update (EV_A_ 1e100);
3763} 3766}
3764 3767
3765void 3768void
3766ev_suspend (EV_P) EV_THROW 3769ev_suspend (EV_P) EV_NOEXCEPT
3767{ 3770{
3768 ev_now_update (EV_A); 3771 ev_now_update (EV_A);
3769} 3772}
3770 3773
3771void 3774void
3772ev_resume (EV_P) EV_THROW 3775ev_resume (EV_P) EV_NOEXCEPT
3773{ 3776{
3774 ev_tstamp mn_prev = mn_now; 3777 ev_tstamp mn_prev = mn_now;
3775 3778
3776 ev_now_update (EV_A); 3779 ev_now_update (EV_A);
3777 timers_reschedule (EV_A_ mn_now - mn_prev); 3780 timers_reschedule (EV_A_ mn_now - mn_prev);
3816 w->pending = 0; 3819 w->pending = 0;
3817 } 3820 }
3818} 3821}
3819 3822
3820int 3823int
3821ev_clear_pending (EV_P_ void *w) EV_THROW 3824ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT
3822{ 3825{
3823 W w_ = (W)w; 3826 W w_ = (W)w;
3824 int pending = w_->pending; 3827 int pending = w_->pending;
3825 3828
3826 if (expect_true (pending)) 3829 if (expect_true (pending))
3860 3863
3861/*****************************************************************************/ 3864/*****************************************************************************/
3862 3865
3863noinline 3866noinline
3864void 3867void
3865ev_io_start (EV_P_ ev_io *w) EV_THROW 3868ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT
3866{ 3869{
3867 int fd = w->fd; 3870 int fd = w->fd;
3868 3871
3869 if (expect_false (ev_is_active (w))) 3872 if (expect_false (ev_is_active (w)))
3870 return; 3873 return;
3887 EV_FREQUENT_CHECK; 3890 EV_FREQUENT_CHECK;
3888} 3891}
3889 3892
3890noinline 3893noinline
3891void 3894void
3892ev_io_stop (EV_P_ ev_io *w) EV_THROW 3895ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT
3893{ 3896{
3894 clear_pending (EV_A_ (W)w); 3897 clear_pending (EV_A_ (W)w);
3895 if (expect_false (!ev_is_active (w))) 3898 if (expect_false (!ev_is_active (w)))
3896 return; 3899 return;
3897 3900
3907 EV_FREQUENT_CHECK; 3910 EV_FREQUENT_CHECK;
3908} 3911}
3909 3912
3910noinline 3913noinline
3911void 3914void
3912ev_timer_start (EV_P_ ev_timer *w) EV_THROW 3915ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT
3913{ 3916{
3914 if (expect_false (ev_is_active (w))) 3917 if (expect_false (ev_is_active (w)))
3915 return; 3918 return;
3916 3919
3917 ev_at (w) += mn_now; 3920 ev_at (w) += mn_now;
3932 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3935 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3933} 3936}
3934 3937
3935noinline 3938noinline
3936void 3939void
3937ev_timer_stop (EV_P_ ev_timer *w) EV_THROW 3940ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT
3938{ 3941{
3939 clear_pending (EV_A_ (W)w); 3942 clear_pending (EV_A_ (W)w);
3940 if (expect_false (!ev_is_active (w))) 3943 if (expect_false (!ev_is_active (w)))
3941 return; 3944 return;
3942 3945
3963 EV_FREQUENT_CHECK; 3966 EV_FREQUENT_CHECK;
3964} 3967}
3965 3968
3966noinline 3969noinline
3967void 3970void
3968ev_timer_again (EV_P_ ev_timer *w) EV_THROW 3971ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT
3969{ 3972{
3970 EV_FREQUENT_CHECK; 3973 EV_FREQUENT_CHECK;
3971 3974
3972 clear_pending (EV_A_ (W)w); 3975 clear_pending (EV_A_ (W)w);
3973 3976
3990 3993
3991 EV_FREQUENT_CHECK; 3994 EV_FREQUENT_CHECK;
3992} 3995}
3993 3996
3994ev_tstamp 3997ev_tstamp
3995ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW 3998ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT
3996{ 3999{
3997 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 4000 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3998} 4001}
3999 4002
4000#if EV_PERIODIC_ENABLE 4003#if EV_PERIODIC_ENABLE
4001noinline 4004noinline
4002void 4005void
4003ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW 4006ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT
4004{ 4007{
4005 if (expect_false (ev_is_active (w))) 4008 if (expect_false (ev_is_active (w)))
4006 return; 4009 return;
4007 4010
4008 if (w->reschedule_cb) 4011 if (w->reschedule_cb)
4029 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 4032 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
4030} 4033}
4031 4034
4032noinline 4035noinline
4033void 4036void
4034ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW 4037ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT
4035{ 4038{
4036 clear_pending (EV_A_ (W)w); 4039 clear_pending (EV_A_ (W)w);
4037 if (expect_false (!ev_is_active (w))) 4040 if (expect_false (!ev_is_active (w)))
4038 return; 4041 return;
4039 4042
4058 EV_FREQUENT_CHECK; 4061 EV_FREQUENT_CHECK;
4059} 4062}
4060 4063
4061noinline 4064noinline
4062void 4065void
4063ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW 4066ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT
4064{ 4067{
4065 /* TODO: use adjustheap and recalculation */ 4068 /* TODO: use adjustheap and recalculation */
4066 ev_periodic_stop (EV_A_ w); 4069 ev_periodic_stop (EV_A_ w);
4067 ev_periodic_start (EV_A_ w); 4070 ev_periodic_start (EV_A_ w);
4068} 4071}
4074 4077
4075#if EV_SIGNAL_ENABLE 4078#if EV_SIGNAL_ENABLE
4076 4079
4077noinline 4080noinline
4078void 4081void
4079ev_signal_start (EV_P_ ev_signal *w) EV_THROW 4082ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT
4080{ 4083{
4081 if (expect_false (ev_is_active (w))) 4084 if (expect_false (ev_is_active (w)))
4082 return; 4085 return;
4083 4086
4084 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 4087 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
4157 EV_FREQUENT_CHECK; 4160 EV_FREQUENT_CHECK;
4158} 4161}
4159 4162
4160noinline 4163noinline
4161void 4164void
4162ev_signal_stop (EV_P_ ev_signal *w) EV_THROW 4165ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT
4163{ 4166{
4164 clear_pending (EV_A_ (W)w); 4167 clear_pending (EV_A_ (W)w);
4165 if (expect_false (!ev_is_active (w))) 4168 if (expect_false (!ev_is_active (w)))
4166 return; 4169 return;
4167 4170
4198#endif 4201#endif
4199 4202
4200#if EV_CHILD_ENABLE 4203#if EV_CHILD_ENABLE
4201 4204
4202void 4205void
4203ev_child_start (EV_P_ ev_child *w) EV_THROW 4206ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT
4204{ 4207{
4205#if EV_MULTIPLICITY 4208#if EV_MULTIPLICITY
4206 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 4209 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
4207#endif 4210#endif
4208 if (expect_false (ev_is_active (w))) 4211 if (expect_false (ev_is_active (w)))
4215 4218
4216 EV_FREQUENT_CHECK; 4219 EV_FREQUENT_CHECK;
4217} 4220}
4218 4221
4219void 4222void
4220ev_child_stop (EV_P_ ev_child *w) EV_THROW 4223ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT
4221{ 4224{
4222 clear_pending (EV_A_ (W)w); 4225 clear_pending (EV_A_ (W)w);
4223 if (expect_false (!ev_is_active (w))) 4226 if (expect_false (!ev_is_active (w)))
4224 return; 4227 return;
4225 4228
4490#else 4493#else
4491# define EV_LSTAT(p,b) lstat (p, b) 4494# define EV_LSTAT(p,b) lstat (p, b)
4492#endif 4495#endif
4493 4496
4494void 4497void
4495ev_stat_stat (EV_P_ ev_stat *w) EV_THROW 4498ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT
4496{ 4499{
4497 if (lstat (w->path, &w->attr) < 0) 4500 if (lstat (w->path, &w->attr) < 0)
4498 w->attr.st_nlink = 0; 4501 w->attr.st_nlink = 0;
4499 else if (!w->attr.st_nlink) 4502 else if (!w->attr.st_nlink)
4500 w->attr.st_nlink = 1; 4503 w->attr.st_nlink = 1;
4540 ev_feed_event (EV_A_ w, EV_STAT); 4543 ev_feed_event (EV_A_ w, EV_STAT);
4541 } 4544 }
4542} 4545}
4543 4546
4544void 4547void
4545ev_stat_start (EV_P_ ev_stat *w) EV_THROW 4548ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT
4546{ 4549{
4547 if (expect_false (ev_is_active (w))) 4550 if (expect_false (ev_is_active (w)))
4548 return; 4551 return;
4549 4552
4550 ev_stat_stat (EV_A_ w); 4553 ev_stat_stat (EV_A_ w);
4571 4574
4572 EV_FREQUENT_CHECK; 4575 EV_FREQUENT_CHECK;
4573} 4576}
4574 4577
4575void 4578void
4576ev_stat_stop (EV_P_ ev_stat *w) EV_THROW 4579ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT
4577{ 4580{
4578 clear_pending (EV_A_ (W)w); 4581 clear_pending (EV_A_ (W)w);
4579 if (expect_false (!ev_is_active (w))) 4582 if (expect_false (!ev_is_active (w)))
4580 return; 4583 return;
4581 4584
4597} 4600}
4598#endif 4601#endif
4599 4602
4600#if EV_IDLE_ENABLE 4603#if EV_IDLE_ENABLE
4601void 4604void
4602ev_idle_start (EV_P_ ev_idle *w) EV_THROW 4605ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT
4603{ 4606{
4604 if (expect_false (ev_is_active (w))) 4607 if (expect_false (ev_is_active (w)))
4605 return; 4608 return;
4606 4609
4607 pri_adjust (EV_A_ (W)w); 4610 pri_adjust (EV_A_ (W)w);
4620 4623
4621 EV_FREQUENT_CHECK; 4624 EV_FREQUENT_CHECK;
4622} 4625}
4623 4626
4624void 4627void
4625ev_idle_stop (EV_P_ ev_idle *w) EV_THROW 4628ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT
4626{ 4629{
4627 clear_pending (EV_A_ (W)w); 4630 clear_pending (EV_A_ (W)w);
4628 if (expect_false (!ev_is_active (w))) 4631 if (expect_false (!ev_is_active (w)))
4629 return; 4632 return;
4630 4633
4644} 4647}
4645#endif 4648#endif
4646 4649
4647#if EV_PREPARE_ENABLE 4650#if EV_PREPARE_ENABLE
4648void 4651void
4649ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW 4652ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT
4650{ 4653{
4651 if (expect_false (ev_is_active (w))) 4654 if (expect_false (ev_is_active (w)))
4652 return; 4655 return;
4653 4656
4654 EV_FREQUENT_CHECK; 4657 EV_FREQUENT_CHECK;
4659 4662
4660 EV_FREQUENT_CHECK; 4663 EV_FREQUENT_CHECK;
4661} 4664}
4662 4665
4663void 4666void
4664ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW 4667ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT
4665{ 4668{
4666 clear_pending (EV_A_ (W)w); 4669 clear_pending (EV_A_ (W)w);
4667 if (expect_false (!ev_is_active (w))) 4670 if (expect_false (!ev_is_active (w)))
4668 return; 4671 return;
4669 4672
4682} 4685}
4683#endif 4686#endif
4684 4687
4685#if EV_CHECK_ENABLE 4688#if EV_CHECK_ENABLE
4686void 4689void
4687ev_check_start (EV_P_ ev_check *w) EV_THROW 4690ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT
4688{ 4691{
4689 if (expect_false (ev_is_active (w))) 4692 if (expect_false (ev_is_active (w)))
4690 return; 4693 return;
4691 4694
4692 EV_FREQUENT_CHECK; 4695 EV_FREQUENT_CHECK;
4697 4700
4698 EV_FREQUENT_CHECK; 4701 EV_FREQUENT_CHECK;
4699} 4702}
4700 4703
4701void 4704void
4702ev_check_stop (EV_P_ ev_check *w) EV_THROW 4705ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT
4703{ 4706{
4704 clear_pending (EV_A_ (W)w); 4707 clear_pending (EV_A_ (W)w);
4705 if (expect_false (!ev_is_active (w))) 4708 if (expect_false (!ev_is_active (w)))
4706 return; 4709 return;
4707 4710
4721#endif 4724#endif
4722 4725
4723#if EV_EMBED_ENABLE 4726#if EV_EMBED_ENABLE
4724noinline 4727noinline
4725void 4728void
4726ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW 4729ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT
4727{ 4730{
4728 ev_run (w->other, EVRUN_NOWAIT); 4731 ev_run (w->other, EVRUN_NOWAIT);
4729} 4732}
4730 4733
4731static void 4734static void
4779 ev_idle_stop (EV_A_ idle); 4782 ev_idle_stop (EV_A_ idle);
4780} 4783}
4781#endif 4784#endif
4782 4785
4783void 4786void
4784ev_embed_start (EV_P_ ev_embed *w) EV_THROW 4787ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT
4785{ 4788{
4786 if (expect_false (ev_is_active (w))) 4789 if (expect_false (ev_is_active (w)))
4787 return; 4790 return;
4788 4791
4789 { 4792 {
4810 4813
4811 EV_FREQUENT_CHECK; 4814 EV_FREQUENT_CHECK;
4812} 4815}
4813 4816
4814void 4817void
4815ev_embed_stop (EV_P_ ev_embed *w) EV_THROW 4818ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT
4816{ 4819{
4817 clear_pending (EV_A_ (W)w); 4820 clear_pending (EV_A_ (W)w);
4818 if (expect_false (!ev_is_active (w))) 4821 if (expect_false (!ev_is_active (w)))
4819 return; 4822 return;
4820 4823
4830} 4833}
4831#endif 4834#endif
4832 4835
4833#if EV_FORK_ENABLE 4836#if EV_FORK_ENABLE
4834void 4837void
4835ev_fork_start (EV_P_ ev_fork *w) EV_THROW 4838ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT
4836{ 4839{
4837 if (expect_false (ev_is_active (w))) 4840 if (expect_false (ev_is_active (w)))
4838 return; 4841 return;
4839 4842
4840 EV_FREQUENT_CHECK; 4843 EV_FREQUENT_CHECK;
4845 4848
4846 EV_FREQUENT_CHECK; 4849 EV_FREQUENT_CHECK;
4847} 4850}
4848 4851
4849void 4852void
4850ev_fork_stop (EV_P_ ev_fork *w) EV_THROW 4853ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT
4851{ 4854{
4852 clear_pending (EV_A_ (W)w); 4855 clear_pending (EV_A_ (W)w);
4853 if (expect_false (!ev_is_active (w))) 4856 if (expect_false (!ev_is_active (w)))
4854 return; 4857 return;
4855 4858
4868} 4871}
4869#endif 4872#endif
4870 4873
4871#if EV_CLEANUP_ENABLE 4874#if EV_CLEANUP_ENABLE
4872void 4875void
4873ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW 4876ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4874{ 4877{
4875 if (expect_false (ev_is_active (w))) 4878 if (expect_false (ev_is_active (w)))
4876 return; 4879 return;
4877 4880
4878 EV_FREQUENT_CHECK; 4881 EV_FREQUENT_CHECK;
4885 ev_unref (EV_A); 4888 ev_unref (EV_A);
4886 EV_FREQUENT_CHECK; 4889 EV_FREQUENT_CHECK;
4887} 4890}
4888 4891
4889void 4892void
4890ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW 4893ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT
4891{ 4894{
4892 clear_pending (EV_A_ (W)w); 4895 clear_pending (EV_A_ (W)w);
4893 if (expect_false (!ev_is_active (w))) 4896 if (expect_false (!ev_is_active (w)))
4894 return; 4897 return;
4895 4898
4909} 4912}
4910#endif 4913#endif
4911 4914
4912#if EV_ASYNC_ENABLE 4915#if EV_ASYNC_ENABLE
4913void 4916void
4914ev_async_start (EV_P_ ev_async *w) EV_THROW 4917ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT
4915{ 4918{
4916 if (expect_false (ev_is_active (w))) 4919 if (expect_false (ev_is_active (w)))
4917 return; 4920 return;
4918 4921
4919 w->sent = 0; 4922 w->sent = 0;
4928 4931
4929 EV_FREQUENT_CHECK; 4932 EV_FREQUENT_CHECK;
4930} 4933}
4931 4934
4932void 4935void
4933ev_async_stop (EV_P_ ev_async *w) EV_THROW 4936ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT
4934{ 4937{
4935 clear_pending (EV_A_ (W)w); 4938 clear_pending (EV_A_ (W)w);
4936 if (expect_false (!ev_is_active (w))) 4939 if (expect_false (!ev_is_active (w)))
4937 return; 4940 return;
4938 4941
4949 4952
4950 EV_FREQUENT_CHECK; 4953 EV_FREQUENT_CHECK;
4951} 4954}
4952 4955
4953void 4956void
4954ev_async_send (EV_P_ ev_async *w) EV_THROW 4957ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT
4955{ 4958{
4956 w->sent = 1; 4959 w->sent = 1;
4957 evpipe_write (EV_A_ &async_pending); 4960 evpipe_write (EV_A_ &async_pending);
4958} 4961}
4959#endif 4962#endif
4996 4999
4997 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 5000 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4998} 5001}
4999 5002
5000void 5003void
5001ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW 5004ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT
5002{ 5005{
5003 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 5006 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
5004 5007
5005 if (expect_false (!once)) 5008 if (expect_false (!once))
5006 { 5009 {
5029/*****************************************************************************/ 5032/*****************************************************************************/
5030 5033
5031#if EV_WALK_ENABLE 5034#if EV_WALK_ENABLE
5032ecb_cold 5035ecb_cold
5033void 5036void
5034ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW 5037ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT
5035{ 5038{
5036 int i, j; 5039 int i, j;
5037 ev_watcher_list *wl, *wn; 5040 ev_watcher_list *wl, *wn;
5038 5041
5039 if (types & (EV_IO | EV_EMBED)) 5042 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines