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

Comparing libev/ev.c (file contents):
Revision 1.402 by sf-exg, Tue Dec 20 10:34:10 2011 UTC vs.
Revision 1.424 by root, Tue May 1 22:01:40 2012 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 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012 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 *
59# endif 59# endif
60# ifndef EV_USE_MONOTONIC 60# ifndef EV_USE_MONOTONIC
61# define EV_USE_MONOTONIC 1 61# define EV_USE_MONOTONIC 1
62# endif 62# endif
63# endif 63# endif
64# elif !defined(EV_USE_CLOCK_SYSCALL) 64# elif !defined EV_USE_CLOCK_SYSCALL
65# define EV_USE_CLOCK_SYSCALL 0 65# define EV_USE_CLOCK_SYSCALL 0
66# endif 66# endif
67 67
68# if HAVE_CLOCK_GETTIME 68# if HAVE_CLOCK_GETTIME
69# ifndef EV_USE_MONOTONIC 69# ifndef EV_USE_MONOTONIC
183# include EV_H 183# include EV_H
184#else 184#else
185# include "ev.h" 185# include "ev.h"
186#endif 186#endif
187 187
188#if EV_NO_THREADS
189# undef EV_NO_SMP
190# define EV_NO_SMP 1
191# undef ECB_NO_THREADS
192# define ECB_NO_THREADS 1
193#endif
194#if EV_NO_SMP
195# undef EV_NO_SMP
196# define ECB_NO_SMP 1
197#endif
198
188#ifndef _WIN32 199#ifndef _WIN32
189# include <sys/time.h> 200# include <sys/time.h>
190# include <sys/wait.h> 201# include <sys/wait.h>
191# include <unistd.h> 202# include <unistd.h>
192#else 203#else
208#define _DARWIN_UNLIMITED_SELECT 1 219#define _DARWIN_UNLIMITED_SELECT 1
209 220
210/* this block tries to deduce configuration from header-defined symbols and defaults */ 221/* this block tries to deduce configuration from header-defined symbols and defaults */
211 222
212/* try to deduce the maximum number of signals on this platform */ 223/* try to deduce the maximum number of signals on this platform */
213#if defined (EV_NSIG) 224#if defined EV_NSIG
214/* use what's provided */ 225/* use what's provided */
215#elif defined (NSIG) 226#elif defined NSIG
216# define EV_NSIG (NSIG) 227# define EV_NSIG (NSIG)
217#elif defined(_NSIG) 228#elif defined _NSIG
218# define EV_NSIG (_NSIG) 229# define EV_NSIG (_NSIG)
219#elif defined (SIGMAX) 230#elif defined SIGMAX
220# define EV_NSIG (SIGMAX+1) 231# define EV_NSIG (SIGMAX+1)
221#elif defined (SIG_MAX) 232#elif defined SIG_MAX
222# define EV_NSIG (SIG_MAX+1) 233# define EV_NSIG (SIG_MAX+1)
223#elif defined (_SIG_MAX) 234#elif defined _SIG_MAX
224# define EV_NSIG (_SIG_MAX+1) 235# define EV_NSIG (_SIG_MAX+1)
225#elif defined (MAXSIG) 236#elif defined MAXSIG
226# define EV_NSIG (MAXSIG+1) 237# define EV_NSIG (MAXSIG+1)
227#elif defined (MAX_SIG) 238#elif defined MAX_SIG
228# define EV_NSIG (MAX_SIG+1) 239# define EV_NSIG (MAX_SIG+1)
229#elif defined (SIGARRAYSIZE) 240#elif defined SIGARRAYSIZE
230# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ 241# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */
231#elif defined (_sys_nsig) 242#elif defined _sys_nsig
232# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ 243# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
233#else 244#else
234# error "unable to find value for NSIG, please report" 245# error "unable to find value for NSIG, please report"
235/* to make it compile regardless, just remove the above line, */ 246/* to make it compile regardless, just remove the above line, */
236/* but consider reporting it, too! :) */ 247/* but consider reporting it, too! :) */
248# define EV_USE_CLOCK_SYSCALL 0 259# define EV_USE_CLOCK_SYSCALL 0
249# endif 260# endif
250#endif 261#endif
251 262
252#ifndef EV_USE_MONOTONIC 263#ifndef EV_USE_MONOTONIC
253# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 264# if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
254# define EV_USE_MONOTONIC EV_FEATURE_OS 265# define EV_USE_MONOTONIC EV_FEATURE_OS
255# else 266# else
256# define EV_USE_MONOTONIC 0 267# define EV_USE_MONOTONIC 0
257# endif 268# endif
258#endif 269#endif
348#endif 359#endif
349 360
350/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 361/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
351/* which makes programs even slower. might work on other unices, too. */ 362/* which makes programs even slower. might work on other unices, too. */
352#if EV_USE_CLOCK_SYSCALL 363#if EV_USE_CLOCK_SYSCALL
353# include <syscall.h> 364# include <sys/syscall.h>
354# ifdef SYS_clock_gettime 365# ifdef SYS_clock_gettime
355# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
356# undef EV_USE_MONOTONIC 367# undef EV_USE_MONOTONIC
357# define EV_USE_MONOTONIC 1 368# define EV_USE_MONOTONIC 1
358# else 369# else
384# define EV_USE_INOTIFY 0 395# define EV_USE_INOTIFY 0
385#endif 396#endif
386 397
387#if !EV_USE_NANOSLEEP 398#if !EV_USE_NANOSLEEP
388/* hp-ux has it in sys/time.h, which we unconditionally include above */ 399/* hp-ux has it in sys/time.h, which we unconditionally include above */
389# if !defined(_WIN32) && !defined(__hpux) 400# if !defined _WIN32 && !defined __hpux
390# include <sys/select.h> 401# include <sys/select.h>
391# endif 402# endif
392#endif 403#endif
393 404
394#if EV_USE_INOTIFY 405#if EV_USE_INOTIFY
467/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ 478/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */
468/* ECB.H BEGIN */ 479/* ECB.H BEGIN */
469/* 480/*
470 * libecb - http://software.schmorp.de/pkg/libecb 481 * libecb - http://software.schmorp.de/pkg/libecb
471 * 482 *
472 * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de> 483 * Copyright (©) 2009-2012 Marc Alexander Lehmann <libecb@schmorp.de>
473 * Copyright (©) 2011 Emanuele Giaquinta 484 * Copyright (©) 2011 Emanuele Giaquinta
474 * All rights reserved. 485 * All rights reserved.
475 * 486 *
476 * Redistribution and use in source and binary forms, with or without modifica- 487 * Redistribution and use in source and binary forms, with or without modifica-
477 * tion, are permitted provided that the following conditions are met: 488 * tion, are permitted provided that the following conditions are met:
522 * or so. 533 * or so.
523 * we try to detect these and simply assume they are not gcc - if they have 534 * we try to detect these and simply assume they are not gcc - if they have
524 * an issue with that they should have done it right in the first place. 535 * an issue with that they should have done it right in the first place.
525 */ 536 */
526#ifndef ECB_GCC_VERSION 537#ifndef ECB_GCC_VERSION
527 #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) 538 #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__
528 #define ECB_GCC_VERSION(major,minor) 0 539 #define ECB_GCC_VERSION(major,minor) 0
529 #else 540 #else
530 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 541 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
531 #endif 542 #endif
532#endif 543#endif
534/*****************************************************************************/ 545/*****************************************************************************/
535 546
536/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 547/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
537/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 548/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
538 549
550#if ECB_NO_THREADS
551# define ECB_NO_SMP 1
552#endif
553
539#if ECB_NO_THREADS || ECB_NO_SMP 554#if ECB_NO_THREADS || ECB_NO_SMP
540 #define ECB_MEMORY_FENCE do { } while (0) 555 #define ECB_MEMORY_FENCE do { } while (0)
541#endif 556#endif
542 557
543#ifndef ECB_MEMORY_FENCE 558#ifndef ECB_MEMORY_FENCE
544 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) 559 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
545 #if __i386__ 560 #if __i386 || __i386__
546 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 561 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
547 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 562 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
548 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 563 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
549 #elif __amd64 564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
550 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
551 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
552 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 567 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
553 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
555 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 570 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
556 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 571 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
557 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") 572 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
558 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 573 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
559 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 574 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
560 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
576 #elif __sparc || __sparc__
577 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory")
578 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
580 #elif defined __s390__ || defined __s390x__
581 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
582 #elif defined __mips__
583 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
584 #elif defined __alpha__
585 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
561 #endif 586 #endif
562 #endif 587 #endif
563#endif 588#endif
564 589
565#ifndef ECB_MEMORY_FENCE 590#ifndef ECB_MEMORY_FENCE
566 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) 591 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
567 #define ECB_MEMORY_FENCE __sync_synchronize () 592 #define ECB_MEMORY_FENCE __sync_synchronize ()
568 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ 593 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
569 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ 594 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
570 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 595 #elif _MSC_VER >= 1400 /* VC++ 2005 */
571 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 596 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
572 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 597 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
573 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ 598 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
574 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 599 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
575 #elif defined(_WIN32) 600 #elif defined _WIN32
576 #include <WinNT.h> 601 #include <WinNT.h>
577 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 602 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
603 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
604 #include <mbarrier.h>
605 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
606 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier ()
607 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier ()
608 #elif __xlC__
609 #define ECB_MEMORY_FENCE __sync ()
578 #endif 610 #endif
579#endif 611#endif
580 612
581#ifndef ECB_MEMORY_FENCE 613#ifndef ECB_MEMORY_FENCE
582 #if !ECB_AVOID_PTHREADS 614 #if !ECB_AVOID_PTHREADS
594 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; 626 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
595 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) 627 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
596 #endif 628 #endif
597#endif 629#endif
598 630
599#if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) 631#if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE
600 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 632 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
601#endif 633#endif
602 634
603#if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) 635#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
604 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 636 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
605#endif 637#endif
606 638
607/*****************************************************************************/ 639/*****************************************************************************/
608 640
757 789
758 return r + ecb_ld32 (x); 790 return r + ecb_ld32 (x);
759 } 791 }
760#endif 792#endif
761 793
794ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const;
795ecb_function_ uint8_t ecb_bitrev8 (uint8_t x)
796{
797 return ( (x * 0x0802U & 0x22110U)
798 | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16;
799}
800
801ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) ecb_const;
802ecb_function_ uint16_t ecb_bitrev16 (uint16_t x)
803{
804 x = ((x >> 1) & 0x5555) | ((x & 0x5555) << 1);
805 x = ((x >> 2) & 0x3333) | ((x & 0x3333) << 2);
806 x = ((x >> 4) & 0x0f0f) | ((x & 0x0f0f) << 4);
807 x = ( x >> 8 ) | ( x << 8);
808
809 return x;
810}
811
812ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) ecb_const;
813ecb_function_ uint32_t ecb_bitrev32 (uint32_t x)
814{
815 x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1);
816 x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2);
817 x = ((x >> 4) & 0x0f0f0f0f) | ((x & 0x0f0f0f0f) << 4);
818 x = ((x >> 8) & 0x00ff00ff) | ((x & 0x00ff00ff) << 8);
819 x = ( x >> 16 ) | ( x << 16);
820
821 return x;
822}
823
762/* popcount64 is only available on 64 bit cpus as gcc builtin */ 824/* popcount64 is only available on 64 bit cpus as gcc builtin */
763/* so for this version we are lazy */ 825/* so for this version we are lazy */
764ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; 826ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const;
765ecb_function_ int 827ecb_function_ int
766ecb_popcount64 (uint64_t x) 828ecb_popcount64 (uint64_t x)
815 877
816#if ECB_GCC_VERSION(4,5) 878#if ECB_GCC_VERSION(4,5)
817 #define ecb_unreachable() __builtin_unreachable () 879 #define ecb_unreachable() __builtin_unreachable ()
818#else 880#else
819 /* this seems to work fine, but gcc always emits a warning for it :/ */ 881 /* this seems to work fine, but gcc always emits a warning for it :/ */
820 ecb_function_ void ecb_unreachable (void) ecb_noreturn; 882 ecb_inline void ecb_unreachable (void) ecb_noreturn;
821 ecb_function_ void ecb_unreachable (void) { } 883 ecb_inline void ecb_unreachable (void) { }
822#endif 884#endif
823 885
824/* try to tell the compiler that some condition is definitely true */ 886/* try to tell the compiler that some condition is definitely true */
825#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) 887#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
826 888
827ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; 889ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const;
828ecb_function_ unsigned char 890ecb_inline unsigned char
829ecb_byteorder_helper (void) 891ecb_byteorder_helper (void)
830{ 892{
831 const uint32_t u = 0x11223344; 893 const uint32_t u = 0x11223344;
832 return *(unsigned char *)&u; 894 return *(unsigned char *)&u;
833} 895}
834 896
835ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; 897ecb_inline ecb_bool ecb_big_endian (void) ecb_const;
836ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } 898ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
837ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; 899ecb_inline ecb_bool ecb_little_endian (void) ecb_const;
838ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } 900ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }
839 901
840#if ECB_GCC_VERSION(3,0) || ECB_C99 902#if ECB_GCC_VERSION(3,0) || ECB_C99
841 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 903 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
842#else 904#else
843 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 905 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))
1043{ 1105{
1044 write (STDERR_FILENO, msg, strlen (msg)); 1106 write (STDERR_FILENO, msg, strlen (msg));
1045} 1107}
1046#endif 1108#endif
1047 1109
1048static void (*syserr_cb)(const char *msg); 1110static void (*syserr_cb)(const char *msg) EV_THROW;
1049 1111
1050void ecb_cold 1112void ecb_cold
1051ev_set_syserr_cb (void (*cb)(const char *msg)) 1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW
1052{ 1114{
1053 syserr_cb = cb; 1115 syserr_cb = cb;
1054} 1116}
1055 1117
1056static void noinline ecb_cold 1118static void noinline ecb_cold
1092 free (ptr); 1154 free (ptr);
1093 return 0; 1155 return 0;
1094#endif 1156#endif
1095} 1157}
1096 1158
1097static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1098 1160
1099void ecb_cold 1161void ecb_cold
1100ev_set_allocator (void *(*cb)(void *ptr, long size)) 1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW
1101{ 1163{
1102 alloc = cb; 1164 alloc = cb;
1103} 1165}
1104 1166
1105inline_speed void * 1167inline_speed void *
1222 1284
1223/*****************************************************************************/ 1285/*****************************************************************************/
1224 1286
1225#ifndef EV_HAVE_EV_TIME 1287#ifndef EV_HAVE_EV_TIME
1226ev_tstamp 1288ev_tstamp
1227ev_time (void) 1289ev_time (void) EV_THROW
1228{ 1290{
1229#if EV_USE_REALTIME 1291#if EV_USE_REALTIME
1230 if (expect_true (have_realtime)) 1292 if (expect_true (have_realtime))
1231 { 1293 {
1232 struct timespec ts; 1294 struct timespec ts;
1256 return ev_time (); 1318 return ev_time ();
1257} 1319}
1258 1320
1259#if EV_MULTIPLICITY 1321#if EV_MULTIPLICITY
1260ev_tstamp 1322ev_tstamp
1261ev_now (EV_P) 1323ev_now (EV_P) EV_THROW
1262{ 1324{
1263 return ev_rt_now; 1325 return ev_rt_now;
1264} 1326}
1265#endif 1327#endif
1266 1328
1267void 1329void
1268ev_sleep (ev_tstamp delay) 1330ev_sleep (ev_tstamp delay) EV_THROW
1269{ 1331{
1270 if (delay > 0.) 1332 if (delay > 0.)
1271 { 1333 {
1272#if EV_USE_NANOSLEEP 1334#if EV_USE_NANOSLEEP
1273 struct timespec ts; 1335 struct timespec ts;
1274 1336
1275 EV_TS_SET (ts, delay); 1337 EV_TS_SET (ts, delay);
1276 nanosleep (&ts, 0); 1338 nanosleep (&ts, 0);
1277#elif defined(_WIN32) 1339#elif defined _WIN32
1278 Sleep ((unsigned long)(delay * 1e3)); 1340 Sleep ((unsigned long)(delay * 1e3));
1279#else 1341#else
1280 struct timeval tv; 1342 struct timeval tv;
1281 1343
1282 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ 1344 /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */
1354pendingcb (EV_P_ ev_prepare *w, int revents) 1416pendingcb (EV_P_ ev_prepare *w, int revents)
1355{ 1417{
1356} 1418}
1357 1419
1358void noinline 1420void noinline
1359ev_feed_event (EV_P_ void *w, int revents) 1421ev_feed_event (EV_P_ void *w, int revents) EV_THROW
1360{ 1422{
1361 W w_ = (W)w; 1423 W w_ = (W)w;
1362 int pri = ABSPRI (w_); 1424 int pri = ABSPRI (w_);
1363 1425
1364 if (expect_false (w_->pending)) 1426 if (expect_false (w_->pending))
1423 if (expect_true (!anfd->reify)) 1485 if (expect_true (!anfd->reify))
1424 fd_event_nocheck (EV_A_ fd, revents); 1486 fd_event_nocheck (EV_A_ fd, revents);
1425} 1487}
1426 1488
1427void 1489void
1428ev_feed_fd_event (EV_P_ int fd, int revents) 1490ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1429{ 1491{
1430 if (fd >= 0 && fd < anfdmax) 1492 if (fd >= 0 && fd < anfdmax)
1431 fd_event_nocheck (EV_A_ fd, revents); 1493 fd_event_nocheck (EV_A_ fd, revents);
1432} 1494}
1433 1495
1782} 1844}
1783 1845
1784inline_speed void 1846inline_speed void
1785evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1847evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1786{ 1848{
1849 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1850
1787 if (expect_true (*flag)) 1851 if (expect_true (*flag))
1788 return; 1852 return;
1789 1853
1790 *flag = 1; 1854 *flag = 1;
1791 1855
1815 /* win32 people keep sending patches that change this write() to send() */ 1879 /* win32 people keep sending patches that change this write() to send() */
1816 /* and then run away. but send() is wrong, it wants a socket handle on win32 */ 1880 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1817 /* so when you think this write should be a send instead, please find out */ 1881 /* so when you think this write should be a send instead, please find out */
1818 /* where your send() is from - it's definitely not the microsoft send, and */ 1882 /* where your send() is from - it's definitely not the microsoft send, and */
1819 /* tell me. thank you. */ 1883 /* tell me. thank you. */
1884 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */
1885 /* check the ev documentation on how to use this flag */
1820 write (evpipe [1], &(evpipe [1]), 1); 1886 write (evpipe [1], &(evpipe [1]), 1);
1821 } 1887 }
1822 1888
1823 errno = old_errno; 1889 errno = old_errno;
1824 } 1890 }
1848 } 1914 }
1849 } 1915 }
1850 1916
1851 pipe_write_skipped = 0; 1917 pipe_write_skipped = 0;
1852 1918
1919 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1920
1853#if EV_SIGNAL_ENABLE 1921#if EV_SIGNAL_ENABLE
1854 if (sig_pending) 1922 if (sig_pending)
1855 { 1923 {
1856 sig_pending = 0; 1924 sig_pending = 0;
1925
1926 ECB_MEMORY_FENCE_RELEASE;
1857 1927
1858 for (i = EV_NSIG - 1; i--; ) 1928 for (i = EV_NSIG - 1; i--; )
1859 if (expect_false (signals [i].pending)) 1929 if (expect_false (signals [i].pending))
1860 ev_feed_signal_event (EV_A_ i + 1); 1930 ev_feed_signal_event (EV_A_ i + 1);
1861 } 1931 }
1863 1933
1864#if EV_ASYNC_ENABLE 1934#if EV_ASYNC_ENABLE
1865 if (async_pending) 1935 if (async_pending)
1866 { 1936 {
1867 async_pending = 0; 1937 async_pending = 0;
1938
1939 ECB_MEMORY_FENCE_RELEASE;
1868 1940
1869 for (i = asynccnt; i--; ) 1941 for (i = asynccnt; i--; )
1870 if (asyncs [i]->sent) 1942 if (asyncs [i]->sent)
1871 { 1943 {
1872 asyncs [i]->sent = 0; 1944 asyncs [i]->sent = 0;
1877} 1949}
1878 1950
1879/*****************************************************************************/ 1951/*****************************************************************************/
1880 1952
1881void 1953void
1882ev_feed_signal (int signum) 1954ev_feed_signal (int signum) EV_THROW
1883{ 1955{
1884#if EV_MULTIPLICITY 1956#if EV_MULTIPLICITY
1885 EV_P = signals [signum - 1].loop; 1957 EV_P = signals [signum - 1].loop;
1886 1958
1887 if (!EV_A) 1959 if (!EV_A)
1904 1976
1905 ev_feed_signal (signum); 1977 ev_feed_signal (signum);
1906} 1978}
1907 1979
1908void noinline 1980void noinline
1909ev_feed_signal_event (EV_P_ int signum) 1981ev_feed_signal_event (EV_P_ int signum) EV_THROW
1910{ 1982{
1911 WL w; 1983 WL w;
1912 1984
1913 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1985 if (expect_false (signum <= 0 || signum > EV_NSIG))
1914 return; 1986 return;
2030#if EV_USE_SELECT 2102#if EV_USE_SELECT
2031# include "ev_select.c" 2103# include "ev_select.c"
2032#endif 2104#endif
2033 2105
2034int ecb_cold 2106int ecb_cold
2035ev_version_major (void) 2107ev_version_major (void) EV_THROW
2036{ 2108{
2037 return EV_VERSION_MAJOR; 2109 return EV_VERSION_MAJOR;
2038} 2110}
2039 2111
2040int ecb_cold 2112int ecb_cold
2041ev_version_minor (void) 2113ev_version_minor (void) EV_THROW
2042{ 2114{
2043 return EV_VERSION_MINOR; 2115 return EV_VERSION_MINOR;
2044} 2116}
2045 2117
2046/* return true if we are running with elevated privileges and should ignore env variables */ 2118/* return true if we are running with elevated privileges and should ignore env variables */
2054 || getgid () != getegid (); 2126 || getgid () != getegid ();
2055#endif 2127#endif
2056} 2128}
2057 2129
2058unsigned int ecb_cold 2130unsigned int ecb_cold
2059ev_supported_backends (void) 2131ev_supported_backends (void) EV_THROW
2060{ 2132{
2061 unsigned int flags = 0; 2133 unsigned int flags = 0;
2062 2134
2063 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2135 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2064 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2136 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2068 2140
2069 return flags; 2141 return flags;
2070} 2142}
2071 2143
2072unsigned int ecb_cold 2144unsigned int ecb_cold
2073ev_recommended_backends (void) 2145ev_recommended_backends (void) EV_THROW
2074{ 2146{
2075 unsigned int flags = ev_supported_backends (); 2147 unsigned int flags = ev_supported_backends ();
2076 2148
2077#ifndef __NetBSD__ 2149#ifndef __NetBSD__
2078 /* kqueue is borked on everything but netbsd apparently */ 2150 /* kqueue is borked on everything but netbsd apparently */
2090 2162
2091 return flags; 2163 return flags;
2092} 2164}
2093 2165
2094unsigned int ecb_cold 2166unsigned int ecb_cold
2095ev_embeddable_backends (void) 2167ev_embeddable_backends (void) EV_THROW
2096{ 2168{
2097 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2169 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2098 2170
2099 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2171 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2100 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2172 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2102 2174
2103 return flags; 2175 return flags;
2104} 2176}
2105 2177
2106unsigned int 2178unsigned int
2107ev_backend (EV_P) 2179ev_backend (EV_P) EV_THROW
2108{ 2180{
2109 return backend; 2181 return backend;
2110} 2182}
2111 2183
2112#if EV_FEATURE_API 2184#if EV_FEATURE_API
2113unsigned int 2185unsigned int
2114ev_iteration (EV_P) 2186ev_iteration (EV_P) EV_THROW
2115{ 2187{
2116 return loop_count; 2188 return loop_count;
2117} 2189}
2118 2190
2119unsigned int 2191unsigned int
2120ev_depth (EV_P) 2192ev_depth (EV_P) EV_THROW
2121{ 2193{
2122 return loop_depth; 2194 return loop_depth;
2123} 2195}
2124 2196
2125void 2197void
2126ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2198ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2127{ 2199{
2128 io_blocktime = interval; 2200 io_blocktime = interval;
2129} 2201}
2130 2202
2131void 2203void
2132ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2204ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2133{ 2205{
2134 timeout_blocktime = interval; 2206 timeout_blocktime = interval;
2135} 2207}
2136 2208
2137void 2209void
2138ev_set_userdata (EV_P_ void *data) 2210ev_set_userdata (EV_P_ void *data) EV_THROW
2139{ 2211{
2140 userdata = data; 2212 userdata = data;
2141} 2213}
2142 2214
2143void * 2215void *
2144ev_userdata (EV_P) 2216ev_userdata (EV_P) EV_THROW
2145{ 2217{
2146 return userdata; 2218 return userdata;
2147} 2219}
2148 2220
2149void 2221void
2150ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 2222ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW
2151{ 2223{
2152 invoke_cb = invoke_pending_cb; 2224 invoke_cb = invoke_pending_cb;
2153} 2225}
2154 2226
2155void 2227void
2156ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 2228ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW
2157{ 2229{
2158 release_cb = release; 2230 release_cb = release;
2159 acquire_cb = acquire; 2231 acquire_cb = acquire;
2160} 2232}
2161#endif 2233#endif
2162 2234
2163/* initialise a loop structure, must be zero-initialised */ 2235/* initialise a loop structure, must be zero-initialised */
2164static void noinline ecb_cold 2236static void noinline ecb_cold
2165loop_init (EV_P_ unsigned int flags) 2237loop_init (EV_P_ unsigned int flags) EV_THROW
2166{ 2238{
2167 if (!backend) 2239 if (!backend)
2168 { 2240 {
2169 origflags = flags; 2241 origflags = flags;
2170 2242
2423} 2495}
2424 2496
2425#if EV_MULTIPLICITY 2497#if EV_MULTIPLICITY
2426 2498
2427struct ev_loop * ecb_cold 2499struct ev_loop * ecb_cold
2428ev_loop_new (unsigned int flags) 2500ev_loop_new (unsigned int flags) EV_THROW
2429{ 2501{
2430 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2502 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2431 2503
2432 memset (EV_A, 0, sizeof (struct ev_loop)); 2504 memset (EV_A, 0, sizeof (struct ev_loop));
2433 loop_init (EV_A_ flags); 2505 loop_init (EV_A_ flags);
2477} 2549}
2478#endif 2550#endif
2479 2551
2480#if EV_FEATURE_API 2552#if EV_FEATURE_API
2481void ecb_cold 2553void ecb_cold
2482ev_verify (EV_P) 2554ev_verify (EV_P) EV_THROW
2483{ 2555{
2484#if EV_VERIFY 2556#if EV_VERIFY
2485 int i; 2557 int i;
2486 WL w; 2558 WL w;
2487 2559
2556#if EV_MULTIPLICITY 2628#if EV_MULTIPLICITY
2557struct ev_loop * ecb_cold 2629struct ev_loop * ecb_cold
2558#else 2630#else
2559int 2631int
2560#endif 2632#endif
2561ev_default_loop (unsigned int flags) 2633ev_default_loop (unsigned int flags) EV_THROW
2562{ 2634{
2563 if (!ev_default_loop_ptr) 2635 if (!ev_default_loop_ptr)
2564 { 2636 {
2565#if EV_MULTIPLICITY 2637#if EV_MULTIPLICITY
2566 EV_P = ev_default_loop_ptr = &default_loop_struct; 2638 EV_P = ev_default_loop_ptr = &default_loop_struct;
2585 2657
2586 return ev_default_loop_ptr; 2658 return ev_default_loop_ptr;
2587} 2659}
2588 2660
2589void 2661void
2590ev_loop_fork (EV_P) 2662ev_loop_fork (EV_P) EV_THROW
2591{ 2663{
2592 postfork = 1; /* must be in line with ev_default_fork */ 2664 postfork = 1; /* must be in line with ev_default_fork */
2593} 2665}
2594 2666
2595/*****************************************************************************/ 2667/*****************************************************************************/
2599{ 2671{
2600 EV_CB_INVOKE ((W)w, revents); 2672 EV_CB_INVOKE ((W)w, revents);
2601} 2673}
2602 2674
2603unsigned int 2675unsigned int
2604ev_pending_count (EV_P) 2676ev_pending_count (EV_P) EV_THROW
2605{ 2677{
2606 int pri; 2678 int pri;
2607 unsigned int count = 0; 2679 unsigned int count = 0;
2608 2680
2609 for (pri = NUMPRI; pri--; ) 2681 for (pri = NUMPRI; pri--; )
2868 2940
2869 mn_now = ev_rt_now; 2941 mn_now = ev_rt_now;
2870 } 2942 }
2871} 2943}
2872 2944
2873void 2945int
2874ev_run (EV_P_ int flags) 2946ev_run (EV_P_ int flags)
2875{ 2947{
2876#if EV_FEATURE_API 2948#if EV_FEATURE_API
2877 ++loop_depth; 2949 ++loop_depth;
2878#endif 2950#endif
3035 loop_done = EVBREAK_CANCEL; 3107 loop_done = EVBREAK_CANCEL;
3036 3108
3037#if EV_FEATURE_API 3109#if EV_FEATURE_API
3038 --loop_depth; 3110 --loop_depth;
3039#endif 3111#endif
3112
3113 return activecnt;
3040} 3114}
3041 3115
3042void 3116void
3043ev_break (EV_P_ int how) 3117ev_break (EV_P_ int how) EV_THROW
3044{ 3118{
3045 loop_done = how; 3119 loop_done = how;
3046} 3120}
3047 3121
3048void 3122void
3049ev_ref (EV_P) 3123ev_ref (EV_P) EV_THROW
3050{ 3124{
3051 ++activecnt; 3125 ++activecnt;
3052} 3126}
3053 3127
3054void 3128void
3055ev_unref (EV_P) 3129ev_unref (EV_P) EV_THROW
3056{ 3130{
3057 --activecnt; 3131 --activecnt;
3058} 3132}
3059 3133
3060void 3134void
3061ev_now_update (EV_P) 3135ev_now_update (EV_P) EV_THROW
3062{ 3136{
3063 time_update (EV_A_ 1e100); 3137 time_update (EV_A_ 1e100);
3064} 3138}
3065 3139
3066void 3140void
3067ev_suspend (EV_P) 3141ev_suspend (EV_P) EV_THROW
3068{ 3142{
3069 ev_now_update (EV_A); 3143 ev_now_update (EV_A);
3070} 3144}
3071 3145
3072void 3146void
3073ev_resume (EV_P) 3147ev_resume (EV_P) EV_THROW
3074{ 3148{
3075 ev_tstamp mn_prev = mn_now; 3149 ev_tstamp mn_prev = mn_now;
3076 3150
3077 ev_now_update (EV_A); 3151 ev_now_update (EV_A);
3078 timers_reschedule (EV_A_ mn_now - mn_prev); 3152 timers_reschedule (EV_A_ mn_now - mn_prev);
3117 w->pending = 0; 3191 w->pending = 0;
3118 } 3192 }
3119} 3193}
3120 3194
3121int 3195int
3122ev_clear_pending (EV_P_ void *w) 3196ev_clear_pending (EV_P_ void *w) EV_THROW
3123{ 3197{
3124 W w_ = (W)w; 3198 W w_ = (W)w;
3125 int pending = w_->pending; 3199 int pending = w_->pending;
3126 3200
3127 if (expect_true (pending)) 3201 if (expect_true (pending))
3160} 3234}
3161 3235
3162/*****************************************************************************/ 3236/*****************************************************************************/
3163 3237
3164void noinline 3238void noinline
3165ev_io_start (EV_P_ ev_io *w) 3239ev_io_start (EV_P_ ev_io *w) EV_THROW
3166{ 3240{
3167 int fd = w->fd; 3241 int fd = w->fd;
3168 3242
3169 if (expect_false (ev_is_active (w))) 3243 if (expect_false (ev_is_active (w)))
3170 return; 3244 return;
3183 3257
3184 EV_FREQUENT_CHECK; 3258 EV_FREQUENT_CHECK;
3185} 3259}
3186 3260
3187void noinline 3261void noinline
3188ev_io_stop (EV_P_ ev_io *w) 3262ev_io_stop (EV_P_ ev_io *w) EV_THROW
3189{ 3263{
3190 clear_pending (EV_A_ (W)w); 3264 clear_pending (EV_A_ (W)w);
3191 if (expect_false (!ev_is_active (w))) 3265 if (expect_false (!ev_is_active (w)))
3192 return; 3266 return;
3193 3267
3202 3276
3203 EV_FREQUENT_CHECK; 3277 EV_FREQUENT_CHECK;
3204} 3278}
3205 3279
3206void noinline 3280void noinline
3207ev_timer_start (EV_P_ ev_timer *w) 3281ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3208{ 3282{
3209 if (expect_false (ev_is_active (w))) 3283 if (expect_false (ev_is_active (w)))
3210 return; 3284 return;
3211 3285
3212 ev_at (w) += mn_now; 3286 ev_at (w) += mn_now;
3226 3300
3227 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3301 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3228} 3302}
3229 3303
3230void noinline 3304void noinline
3231ev_timer_stop (EV_P_ ev_timer *w) 3305ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3232{ 3306{
3233 clear_pending (EV_A_ (W)w); 3307 clear_pending (EV_A_ (W)w);
3234 if (expect_false (!ev_is_active (w))) 3308 if (expect_false (!ev_is_active (w)))
3235 return; 3309 return;
3236 3310
3256 3330
3257 EV_FREQUENT_CHECK; 3331 EV_FREQUENT_CHECK;
3258} 3332}
3259 3333
3260void noinline 3334void noinline
3261ev_timer_again (EV_P_ ev_timer *w) 3335ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3262{ 3336{
3263 EV_FREQUENT_CHECK; 3337 EV_FREQUENT_CHECK;
3338
3339 clear_pending (EV_A_ (W)w);
3264 3340
3265 if (ev_is_active (w)) 3341 if (ev_is_active (w))
3266 { 3342 {
3267 if (w->repeat) 3343 if (w->repeat)
3268 { 3344 {
3281 3357
3282 EV_FREQUENT_CHECK; 3358 EV_FREQUENT_CHECK;
3283} 3359}
3284 3360
3285ev_tstamp 3361ev_tstamp
3286ev_timer_remaining (EV_P_ ev_timer *w) 3362ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3287{ 3363{
3288 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3364 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3289} 3365}
3290 3366
3291#if EV_PERIODIC_ENABLE 3367#if EV_PERIODIC_ENABLE
3292void noinline 3368void noinline
3293ev_periodic_start (EV_P_ ev_periodic *w) 3369ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3294{ 3370{
3295 if (expect_false (ev_is_active (w))) 3371 if (expect_false (ev_is_active (w)))
3296 return; 3372 return;
3297 3373
3298 if (w->reschedule_cb) 3374 if (w->reschedule_cb)
3318 3394
3319 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3395 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3320} 3396}
3321 3397
3322void noinline 3398void noinline
3323ev_periodic_stop (EV_P_ ev_periodic *w) 3399ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3324{ 3400{
3325 clear_pending (EV_A_ (W)w); 3401 clear_pending (EV_A_ (W)w);
3326 if (expect_false (!ev_is_active (w))) 3402 if (expect_false (!ev_is_active (w)))
3327 return; 3403 return;
3328 3404
3346 3422
3347 EV_FREQUENT_CHECK; 3423 EV_FREQUENT_CHECK;
3348} 3424}
3349 3425
3350void noinline 3426void noinline
3351ev_periodic_again (EV_P_ ev_periodic *w) 3427ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3352{ 3428{
3353 /* TODO: use adjustheap and recalculation */ 3429 /* TODO: use adjustheap and recalculation */
3354 ev_periodic_stop (EV_A_ w); 3430 ev_periodic_stop (EV_A_ w);
3355 ev_periodic_start (EV_A_ w); 3431 ev_periodic_start (EV_A_ w);
3356} 3432}
3361#endif 3437#endif
3362 3438
3363#if EV_SIGNAL_ENABLE 3439#if EV_SIGNAL_ENABLE
3364 3440
3365void noinline 3441void noinline
3366ev_signal_start (EV_P_ ev_signal *w) 3442ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3367{ 3443{
3368 if (expect_false (ev_is_active (w))) 3444 if (expect_false (ev_is_active (w)))
3369 return; 3445 return;
3370 3446
3371 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3447 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3442 3518
3443 EV_FREQUENT_CHECK; 3519 EV_FREQUENT_CHECK;
3444} 3520}
3445 3521
3446void noinline 3522void noinline
3447ev_signal_stop (EV_P_ ev_signal *w) 3523ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3448{ 3524{
3449 clear_pending (EV_A_ (W)w); 3525 clear_pending (EV_A_ (W)w);
3450 if (expect_false (!ev_is_active (w))) 3526 if (expect_false (!ev_is_active (w)))
3451 return; 3527 return;
3452 3528
3483#endif 3559#endif
3484 3560
3485#if EV_CHILD_ENABLE 3561#if EV_CHILD_ENABLE
3486 3562
3487void 3563void
3488ev_child_start (EV_P_ ev_child *w) 3564ev_child_start (EV_P_ ev_child *w) EV_THROW
3489{ 3565{
3490#if EV_MULTIPLICITY 3566#if EV_MULTIPLICITY
3491 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3567 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3492#endif 3568#endif
3493 if (expect_false (ev_is_active (w))) 3569 if (expect_false (ev_is_active (w)))
3500 3576
3501 EV_FREQUENT_CHECK; 3577 EV_FREQUENT_CHECK;
3502} 3578}
3503 3579
3504void 3580void
3505ev_child_stop (EV_P_ ev_child *w) 3581ev_child_stop (EV_P_ ev_child *w) EV_THROW
3506{ 3582{
3507 clear_pending (EV_A_ (W)w); 3583 clear_pending (EV_A_ (W)w);
3508 if (expect_false (!ev_is_active (w))) 3584 if (expect_false (!ev_is_active (w)))
3509 return; 3585 return;
3510 3586
3677} 3753}
3678 3754
3679inline_size int 3755inline_size int
3680infy_newfd (void) 3756infy_newfd (void)
3681{ 3757{
3682#if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) 3758#if defined IN_CLOEXEC && defined IN_NONBLOCK
3683 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); 3759 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK);
3684 if (fd >= 0) 3760 if (fd >= 0)
3685 return fd; 3761 return fd;
3686#endif 3762#endif
3687 return inotify_init (); 3763 return inotify_init ();
3762#else 3838#else
3763# define EV_LSTAT(p,b) lstat (p, b) 3839# define EV_LSTAT(p,b) lstat (p, b)
3764#endif 3840#endif
3765 3841
3766void 3842void
3767ev_stat_stat (EV_P_ ev_stat *w) 3843ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3768{ 3844{
3769 if (lstat (w->path, &w->attr) < 0) 3845 if (lstat (w->path, &w->attr) < 0)
3770 w->attr.st_nlink = 0; 3846 w->attr.st_nlink = 0;
3771 else if (!w->attr.st_nlink) 3847 else if (!w->attr.st_nlink)
3772 w->attr.st_nlink = 1; 3848 w->attr.st_nlink = 1;
3811 ev_feed_event (EV_A_ w, EV_STAT); 3887 ev_feed_event (EV_A_ w, EV_STAT);
3812 } 3888 }
3813} 3889}
3814 3890
3815void 3891void
3816ev_stat_start (EV_P_ ev_stat *w) 3892ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3817{ 3893{
3818 if (expect_false (ev_is_active (w))) 3894 if (expect_false (ev_is_active (w)))
3819 return; 3895 return;
3820 3896
3821 ev_stat_stat (EV_A_ w); 3897 ev_stat_stat (EV_A_ w);
3842 3918
3843 EV_FREQUENT_CHECK; 3919 EV_FREQUENT_CHECK;
3844} 3920}
3845 3921
3846void 3922void
3847ev_stat_stop (EV_P_ ev_stat *w) 3923ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3848{ 3924{
3849 clear_pending (EV_A_ (W)w); 3925 clear_pending (EV_A_ (W)w);
3850 if (expect_false (!ev_is_active (w))) 3926 if (expect_false (!ev_is_active (w)))
3851 return; 3927 return;
3852 3928
3868} 3944}
3869#endif 3945#endif
3870 3946
3871#if EV_IDLE_ENABLE 3947#if EV_IDLE_ENABLE
3872void 3948void
3873ev_idle_start (EV_P_ ev_idle *w) 3949ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3874{ 3950{
3875 if (expect_false (ev_is_active (w))) 3951 if (expect_false (ev_is_active (w)))
3876 return; 3952 return;
3877 3953
3878 pri_adjust (EV_A_ (W)w); 3954 pri_adjust (EV_A_ (W)w);
3891 3967
3892 EV_FREQUENT_CHECK; 3968 EV_FREQUENT_CHECK;
3893} 3969}
3894 3970
3895void 3971void
3896ev_idle_stop (EV_P_ ev_idle *w) 3972ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3897{ 3973{
3898 clear_pending (EV_A_ (W)w); 3974 clear_pending (EV_A_ (W)w);
3899 if (expect_false (!ev_is_active (w))) 3975 if (expect_false (!ev_is_active (w)))
3900 return; 3976 return;
3901 3977
3915} 3991}
3916#endif 3992#endif
3917 3993
3918#if EV_PREPARE_ENABLE 3994#if EV_PREPARE_ENABLE
3919void 3995void
3920ev_prepare_start (EV_P_ ev_prepare *w) 3996ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3921{ 3997{
3922 if (expect_false (ev_is_active (w))) 3998 if (expect_false (ev_is_active (w)))
3923 return; 3999 return;
3924 4000
3925 EV_FREQUENT_CHECK; 4001 EV_FREQUENT_CHECK;
3930 4006
3931 EV_FREQUENT_CHECK; 4007 EV_FREQUENT_CHECK;
3932} 4008}
3933 4009
3934void 4010void
3935ev_prepare_stop (EV_P_ ev_prepare *w) 4011ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
3936{ 4012{
3937 clear_pending (EV_A_ (W)w); 4013 clear_pending (EV_A_ (W)w);
3938 if (expect_false (!ev_is_active (w))) 4014 if (expect_false (!ev_is_active (w)))
3939 return; 4015 return;
3940 4016
3953} 4029}
3954#endif 4030#endif
3955 4031
3956#if EV_CHECK_ENABLE 4032#if EV_CHECK_ENABLE
3957void 4033void
3958ev_check_start (EV_P_ ev_check *w) 4034ev_check_start (EV_P_ ev_check *w) EV_THROW
3959{ 4035{
3960 if (expect_false (ev_is_active (w))) 4036 if (expect_false (ev_is_active (w)))
3961 return; 4037 return;
3962 4038
3963 EV_FREQUENT_CHECK; 4039 EV_FREQUENT_CHECK;
3968 4044
3969 EV_FREQUENT_CHECK; 4045 EV_FREQUENT_CHECK;
3970} 4046}
3971 4047
3972void 4048void
3973ev_check_stop (EV_P_ ev_check *w) 4049ev_check_stop (EV_P_ ev_check *w) EV_THROW
3974{ 4050{
3975 clear_pending (EV_A_ (W)w); 4051 clear_pending (EV_A_ (W)w);
3976 if (expect_false (!ev_is_active (w))) 4052 if (expect_false (!ev_is_active (w)))
3977 return; 4053 return;
3978 4054
3991} 4067}
3992#endif 4068#endif
3993 4069
3994#if EV_EMBED_ENABLE 4070#if EV_EMBED_ENABLE
3995void noinline 4071void noinline
3996ev_embed_sweep (EV_P_ ev_embed *w) 4072ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
3997{ 4073{
3998 ev_run (w->other, EVRUN_NOWAIT); 4074 ev_run (w->other, EVRUN_NOWAIT);
3999} 4075}
4000 4076
4001static void 4077static void
4049 ev_idle_stop (EV_A_ idle); 4125 ev_idle_stop (EV_A_ idle);
4050} 4126}
4051#endif 4127#endif
4052 4128
4053void 4129void
4054ev_embed_start (EV_P_ ev_embed *w) 4130ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4055{ 4131{
4056 if (expect_false (ev_is_active (w))) 4132 if (expect_false (ev_is_active (w)))
4057 return; 4133 return;
4058 4134
4059 { 4135 {
4080 4156
4081 EV_FREQUENT_CHECK; 4157 EV_FREQUENT_CHECK;
4082} 4158}
4083 4159
4084void 4160void
4085ev_embed_stop (EV_P_ ev_embed *w) 4161ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4086{ 4162{
4087 clear_pending (EV_A_ (W)w); 4163 clear_pending (EV_A_ (W)w);
4088 if (expect_false (!ev_is_active (w))) 4164 if (expect_false (!ev_is_active (w)))
4089 return; 4165 return;
4090 4166
4100} 4176}
4101#endif 4177#endif
4102 4178
4103#if EV_FORK_ENABLE 4179#if EV_FORK_ENABLE
4104void 4180void
4105ev_fork_start (EV_P_ ev_fork *w) 4181ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4106{ 4182{
4107 if (expect_false (ev_is_active (w))) 4183 if (expect_false (ev_is_active (w)))
4108 return; 4184 return;
4109 4185
4110 EV_FREQUENT_CHECK; 4186 EV_FREQUENT_CHECK;
4115 4191
4116 EV_FREQUENT_CHECK; 4192 EV_FREQUENT_CHECK;
4117} 4193}
4118 4194
4119void 4195void
4120ev_fork_stop (EV_P_ ev_fork *w) 4196ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4121{ 4197{
4122 clear_pending (EV_A_ (W)w); 4198 clear_pending (EV_A_ (W)w);
4123 if (expect_false (!ev_is_active (w))) 4199 if (expect_false (!ev_is_active (w)))
4124 return; 4200 return;
4125 4201
4138} 4214}
4139#endif 4215#endif
4140 4216
4141#if EV_CLEANUP_ENABLE 4217#if EV_CLEANUP_ENABLE
4142void 4218void
4143ev_cleanup_start (EV_P_ ev_cleanup *w) 4219ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4144{ 4220{
4145 if (expect_false (ev_is_active (w))) 4221 if (expect_false (ev_is_active (w)))
4146 return; 4222 return;
4147 4223
4148 EV_FREQUENT_CHECK; 4224 EV_FREQUENT_CHECK;
4155 ev_unref (EV_A); 4231 ev_unref (EV_A);
4156 EV_FREQUENT_CHECK; 4232 EV_FREQUENT_CHECK;
4157} 4233}
4158 4234
4159void 4235void
4160ev_cleanup_stop (EV_P_ ev_cleanup *w) 4236ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4161{ 4237{
4162 clear_pending (EV_A_ (W)w); 4238 clear_pending (EV_A_ (W)w);
4163 if (expect_false (!ev_is_active (w))) 4239 if (expect_false (!ev_is_active (w)))
4164 return; 4240 return;
4165 4241
4179} 4255}
4180#endif 4256#endif
4181 4257
4182#if EV_ASYNC_ENABLE 4258#if EV_ASYNC_ENABLE
4183void 4259void
4184ev_async_start (EV_P_ ev_async *w) 4260ev_async_start (EV_P_ ev_async *w) EV_THROW
4185{ 4261{
4186 if (expect_false (ev_is_active (w))) 4262 if (expect_false (ev_is_active (w)))
4187 return; 4263 return;
4188 4264
4189 w->sent = 0; 4265 w->sent = 0;
4198 4274
4199 EV_FREQUENT_CHECK; 4275 EV_FREQUENT_CHECK;
4200} 4276}
4201 4277
4202void 4278void
4203ev_async_stop (EV_P_ ev_async *w) 4279ev_async_stop (EV_P_ ev_async *w) EV_THROW
4204{ 4280{
4205 clear_pending (EV_A_ (W)w); 4281 clear_pending (EV_A_ (W)w);
4206 if (expect_false (!ev_is_active (w))) 4282 if (expect_false (!ev_is_active (w)))
4207 return; 4283 return;
4208 4284
4219 4295
4220 EV_FREQUENT_CHECK; 4296 EV_FREQUENT_CHECK;
4221} 4297}
4222 4298
4223void 4299void
4224ev_async_send (EV_P_ ev_async *w) 4300ev_async_send (EV_P_ ev_async *w) EV_THROW
4225{ 4301{
4226 w->sent = 1; 4302 w->sent = 1;
4227 evpipe_write (EV_A_ &async_pending); 4303 evpipe_write (EV_A_ &async_pending);
4228} 4304}
4229#endif 4305#endif
4266 4342
4267 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4343 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4268} 4344}
4269 4345
4270void 4346void
4271ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4347ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4272{ 4348{
4273 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4349 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4274 4350
4275 if (expect_false (!once)) 4351 if (expect_false (!once))
4276 { 4352 {
4298 4374
4299/*****************************************************************************/ 4375/*****************************************************************************/
4300 4376
4301#if EV_WALK_ENABLE 4377#if EV_WALK_ENABLE
4302void ecb_cold 4378void ecb_cold
4303ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4379ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4304{ 4380{
4305 int i, j; 4381 int i, j;
4306 ev_watcher_list *wl, *wn; 4382 ev_watcher_list *wl, *wn;
4307 4383
4308 if (types & (EV_IO | EV_EMBED)) 4384 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines