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

Comparing libev/ev.c (file contents):
Revision 1.410 by root, Sat Feb 4 17:57:55 2012 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
219#define _DARWIN_UNLIMITED_SELECT 1 219#define _DARWIN_UNLIMITED_SELECT 1
220 220
221/* 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 */
222 222
223/* try to deduce the maximum number of signals on this platform */ 223/* try to deduce the maximum number of signals on this platform */
224#if defined (EV_NSIG) 224#if defined EV_NSIG
225/* use what's provided */ 225/* use what's provided */
226#elif defined (NSIG) 226#elif defined NSIG
227# define EV_NSIG (NSIG) 227# define EV_NSIG (NSIG)
228#elif defined(_NSIG) 228#elif defined _NSIG
229# define EV_NSIG (_NSIG) 229# define EV_NSIG (_NSIG)
230#elif defined (SIGMAX) 230#elif defined SIGMAX
231# define EV_NSIG (SIGMAX+1) 231# define EV_NSIG (SIGMAX+1)
232#elif defined (SIG_MAX) 232#elif defined SIG_MAX
233# define EV_NSIG (SIG_MAX+1) 233# define EV_NSIG (SIG_MAX+1)
234#elif defined (_SIG_MAX) 234#elif defined _SIG_MAX
235# define EV_NSIG (_SIG_MAX+1) 235# define EV_NSIG (_SIG_MAX+1)
236#elif defined (MAXSIG) 236#elif defined MAXSIG
237# define EV_NSIG (MAXSIG+1) 237# define EV_NSIG (MAXSIG+1)
238#elif defined (MAX_SIG) 238#elif defined MAX_SIG
239# define EV_NSIG (MAX_SIG+1) 239# define EV_NSIG (MAX_SIG+1)
240#elif defined (SIGARRAYSIZE) 240#elif defined SIGARRAYSIZE
241# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ 241# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */
242#elif defined (_sys_nsig) 242#elif defined _sys_nsig
243# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ 243# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
244#else 244#else
245# error "unable to find value for NSIG, please report" 245# error "unable to find value for NSIG, please report"
246/* to make it compile regardless, just remove the above line, */ 246/* to make it compile regardless, just remove the above line, */
247/* but consider reporting it, too! :) */ 247/* but consider reporting it, too! :) */
259# define EV_USE_CLOCK_SYSCALL 0 259# define EV_USE_CLOCK_SYSCALL 0
260# endif 260# endif
261#endif 261#endif
262 262
263#ifndef EV_USE_MONOTONIC 263#ifndef EV_USE_MONOTONIC
264# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 264# if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
265# define EV_USE_MONOTONIC EV_FEATURE_OS 265# define EV_USE_MONOTONIC EV_FEATURE_OS
266# else 266# else
267# define EV_USE_MONOTONIC 0 267# define EV_USE_MONOTONIC 0
268# endif 268# endif
269#endif 269#endif
359#endif 359#endif
360 360
361/* 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, */
362/* which makes programs even slower. might work on other unices, too. */ 362/* which makes programs even slower. might work on other unices, too. */
363#if EV_USE_CLOCK_SYSCALL 363#if EV_USE_CLOCK_SYSCALL
364# include <syscall.h> 364# include <sys/syscall.h>
365# ifdef SYS_clock_gettime 365# ifdef SYS_clock_gettime
366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
367# undef EV_USE_MONOTONIC 367# undef EV_USE_MONOTONIC
368# define EV_USE_MONOTONIC 1 368# define EV_USE_MONOTONIC 1
369# else 369# else
395# define EV_USE_INOTIFY 0 395# define EV_USE_INOTIFY 0
396#endif 396#endif
397 397
398#if !EV_USE_NANOSLEEP 398#if !EV_USE_NANOSLEEP
399/* 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 */
400# if !defined(_WIN32) && !defined(__hpux) 400# if !defined _WIN32 && !defined __hpux
401# include <sys/select.h> 401# include <sys/select.h>
402# endif 402# endif
403#endif 403#endif
404 404
405#if EV_USE_INOTIFY 405#if EV_USE_INOTIFY
533 * or so. 533 * or so.
534 * 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
535 * 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.
536 */ 536 */
537#ifndef ECB_GCC_VERSION 537#ifndef ECB_GCC_VERSION
538 #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__
539 #define ECB_GCC_VERSION(major,minor) 0 539 #define ECB_GCC_VERSION(major,minor) 0
540 #else 540 #else
541 #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)))
542 #endif 542 #endif
543#endif 543#endif
554#if ECB_NO_THREADS || ECB_NO_SMP 554#if ECB_NO_THREADS || ECB_NO_SMP
555 #define ECB_MEMORY_FENCE do { } while (0) 555 #define ECB_MEMORY_FENCE do { } while (0)
556#endif 556#endif
557 557
558#ifndef ECB_MEMORY_FENCE 558#ifndef ECB_MEMORY_FENCE
559 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 559 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
560 #if __i386 || __i386__ 560 #if __i386 || __i386__
561 #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")
562 #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 */
563 #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 */
564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
567 #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 */
568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
570 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 570 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
571 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 571 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
572 #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")
573 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 573 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
574 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 574 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
576 #elif __sparc || __sparc__ 576 #elif __sparc || __sparc__
577 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") 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") 578 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
580 #elif defined(__s390__) || defined(__s390x__) 580 #elif defined __s390__ || defined __s390x__
581 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 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")
582 #endif 586 #endif
583 #endif 587 #endif
584#endif 588#endif
585 589
586#ifndef ECB_MEMORY_FENCE 590#ifndef ECB_MEMORY_FENCE
587 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) 591 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
588 #define ECB_MEMORY_FENCE __sync_synchronize () 592 #define ECB_MEMORY_FENCE __sync_synchronize ()
589 /*#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); }) */
590 /*#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 ); }) */
591 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 595 #elif _MSC_VER >= 1400 /* VC++ 2005 */
592 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 596 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
593 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 597 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
594 #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 */
595 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 599 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
596 #elif defined(_WIN32) 600 #elif defined _WIN32
597 #include <WinNT.h> 601 #include <WinNT.h>
598 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 602 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
599 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 603 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
600 #include <mbarrier.h> 604 #include <mbarrier.h>
601 #define ECB_MEMORY_FENCE __machine_rw_barrier () 605 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
602 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 606 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier ()
603 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () 607 #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier ()
608 #elif __xlC__
609 #define ECB_MEMORY_FENCE __sync ()
604 #endif 610 #endif
605#endif 611#endif
606 612
607#ifndef ECB_MEMORY_FENCE 613#ifndef ECB_MEMORY_FENCE
608 #if !ECB_AVOID_PTHREADS 614 #if !ECB_AVOID_PTHREADS
620 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; 626 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
621 #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)
622 #endif 628 #endif
623#endif 629#endif
624 630
625#if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) 631#if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE
626 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 632 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
627#endif 633#endif
628 634
629#if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) 635#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
630 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 636 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
631#endif 637#endif
632 638
633/*****************************************************************************/ 639/*****************************************************************************/
634 640
1099{ 1105{
1100 write (STDERR_FILENO, msg, strlen (msg)); 1106 write (STDERR_FILENO, msg, strlen (msg));
1101} 1107}
1102#endif 1108#endif
1103 1109
1104static void (*syserr_cb)(const char *msg); 1110static void (*syserr_cb)(const char *msg) EV_THROW;
1105 1111
1106void ecb_cold 1112void ecb_cold
1107ev_set_syserr_cb (void (*cb)(const char *msg)) 1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW
1108{ 1114{
1109 syserr_cb = cb; 1115 syserr_cb = cb;
1110} 1116}
1111 1117
1112static void noinline ecb_cold 1118static void noinline ecb_cold
1148 free (ptr); 1154 free (ptr);
1149 return 0; 1155 return 0;
1150#endif 1156#endif
1151} 1157}
1152 1158
1153static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1154 1160
1155void ecb_cold 1161void ecb_cold
1156ev_set_allocator (void *(*cb)(void *ptr, long size)) 1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW
1157{ 1163{
1158 alloc = cb; 1164 alloc = cb;
1159} 1165}
1160 1166
1161inline_speed void * 1167inline_speed void *
1278 1284
1279/*****************************************************************************/ 1285/*****************************************************************************/
1280 1286
1281#ifndef EV_HAVE_EV_TIME 1287#ifndef EV_HAVE_EV_TIME
1282ev_tstamp 1288ev_tstamp
1283ev_time (void) 1289ev_time (void) EV_THROW
1284{ 1290{
1285#if EV_USE_REALTIME 1291#if EV_USE_REALTIME
1286 if (expect_true (have_realtime)) 1292 if (expect_true (have_realtime))
1287 { 1293 {
1288 struct timespec ts; 1294 struct timespec ts;
1312 return ev_time (); 1318 return ev_time ();
1313} 1319}
1314 1320
1315#if EV_MULTIPLICITY 1321#if EV_MULTIPLICITY
1316ev_tstamp 1322ev_tstamp
1317ev_now (EV_P) 1323ev_now (EV_P) EV_THROW
1318{ 1324{
1319 return ev_rt_now; 1325 return ev_rt_now;
1320} 1326}
1321#endif 1327#endif
1322 1328
1323void 1329void
1324ev_sleep (ev_tstamp delay) 1330ev_sleep (ev_tstamp delay) EV_THROW
1325{ 1331{
1326 if (delay > 0.) 1332 if (delay > 0.)
1327 { 1333 {
1328#if EV_USE_NANOSLEEP 1334#if EV_USE_NANOSLEEP
1329 struct timespec ts; 1335 struct timespec ts;
1330 1336
1331 EV_TS_SET (ts, delay); 1337 EV_TS_SET (ts, delay);
1332 nanosleep (&ts, 0); 1338 nanosleep (&ts, 0);
1333#elif defined(_WIN32) 1339#elif defined _WIN32
1334 Sleep ((unsigned long)(delay * 1e3)); 1340 Sleep ((unsigned long)(delay * 1e3));
1335#else 1341#else
1336 struct timeval tv; 1342 struct timeval tv;
1337 1343
1338 /* 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 */
1410pendingcb (EV_P_ ev_prepare *w, int revents) 1416pendingcb (EV_P_ ev_prepare *w, int revents)
1411{ 1417{
1412} 1418}
1413 1419
1414void noinline 1420void noinline
1415ev_feed_event (EV_P_ void *w, int revents) 1421ev_feed_event (EV_P_ void *w, int revents) EV_THROW
1416{ 1422{
1417 W w_ = (W)w; 1423 W w_ = (W)w;
1418 int pri = ABSPRI (w_); 1424 int pri = ABSPRI (w_);
1419 1425
1420 if (expect_false (w_->pending)) 1426 if (expect_false (w_->pending))
1479 if (expect_true (!anfd->reify)) 1485 if (expect_true (!anfd->reify))
1480 fd_event_nocheck (EV_A_ fd, revents); 1486 fd_event_nocheck (EV_A_ fd, revents);
1481} 1487}
1482 1488
1483void 1489void
1484ev_feed_fd_event (EV_P_ int fd, int revents) 1490ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1485{ 1491{
1486 if (fd >= 0 && fd < anfdmax) 1492 if (fd >= 0 && fd < anfdmax)
1487 fd_event_nocheck (EV_A_ fd, revents); 1493 fd_event_nocheck (EV_A_ fd, revents);
1488} 1494}
1489 1495
1838} 1844}
1839 1845
1840inline_speed void 1846inline_speed void
1841evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1847evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1842{ 1848{
1849 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1850
1843 if (expect_true (*flag)) 1851 if (expect_true (*flag))
1844 return; 1852 return;
1845 1853
1846 *flag = 1; 1854 *flag = 1;
1847 1855
1871 /* win32 people keep sending patches that change this write() to send() */ 1879 /* win32 people keep sending patches that change this write() to send() */
1872 /* 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 */
1873 /* 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 */
1874 /* 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 */
1875 /* 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 */
1876 write (evpipe [1], &(evpipe [1]), 1); 1886 write (evpipe [1], &(evpipe [1]), 1);
1877 } 1887 }
1878 1888
1879 errno = old_errno; 1889 errno = old_errno;
1880 } 1890 }
1904 } 1914 }
1905 } 1915 }
1906 1916
1907 pipe_write_skipped = 0; 1917 pipe_write_skipped = 0;
1908 1918
1919 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1920
1909#if EV_SIGNAL_ENABLE 1921#if EV_SIGNAL_ENABLE
1910 if (sig_pending) 1922 if (sig_pending)
1911 { 1923 {
1912 sig_pending = 0; 1924 sig_pending = 0;
1925
1926 ECB_MEMORY_FENCE_RELEASE;
1913 1927
1914 for (i = EV_NSIG - 1; i--; ) 1928 for (i = EV_NSIG - 1; i--; )
1915 if (expect_false (signals [i].pending)) 1929 if (expect_false (signals [i].pending))
1916 ev_feed_signal_event (EV_A_ i + 1); 1930 ev_feed_signal_event (EV_A_ i + 1);
1917 } 1931 }
1919 1933
1920#if EV_ASYNC_ENABLE 1934#if EV_ASYNC_ENABLE
1921 if (async_pending) 1935 if (async_pending)
1922 { 1936 {
1923 async_pending = 0; 1937 async_pending = 0;
1938
1939 ECB_MEMORY_FENCE_RELEASE;
1924 1940
1925 for (i = asynccnt; i--; ) 1941 for (i = asynccnt; i--; )
1926 if (asyncs [i]->sent) 1942 if (asyncs [i]->sent)
1927 { 1943 {
1928 asyncs [i]->sent = 0; 1944 asyncs [i]->sent = 0;
1933} 1949}
1934 1950
1935/*****************************************************************************/ 1951/*****************************************************************************/
1936 1952
1937void 1953void
1938ev_feed_signal (int signum) 1954ev_feed_signal (int signum) EV_THROW
1939{ 1955{
1940#if EV_MULTIPLICITY 1956#if EV_MULTIPLICITY
1941 EV_P = signals [signum - 1].loop; 1957 EV_P = signals [signum - 1].loop;
1942 1958
1943 if (!EV_A) 1959 if (!EV_A)
1960 1976
1961 ev_feed_signal (signum); 1977 ev_feed_signal (signum);
1962} 1978}
1963 1979
1964void noinline 1980void noinline
1965ev_feed_signal_event (EV_P_ int signum) 1981ev_feed_signal_event (EV_P_ int signum) EV_THROW
1966{ 1982{
1967 WL w; 1983 WL w;
1968 1984
1969 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1985 if (expect_false (signum <= 0 || signum > EV_NSIG))
1970 return; 1986 return;
2086#if EV_USE_SELECT 2102#if EV_USE_SELECT
2087# include "ev_select.c" 2103# include "ev_select.c"
2088#endif 2104#endif
2089 2105
2090int ecb_cold 2106int ecb_cold
2091ev_version_major (void) 2107ev_version_major (void) EV_THROW
2092{ 2108{
2093 return EV_VERSION_MAJOR; 2109 return EV_VERSION_MAJOR;
2094} 2110}
2095 2111
2096int ecb_cold 2112int ecb_cold
2097ev_version_minor (void) 2113ev_version_minor (void) EV_THROW
2098{ 2114{
2099 return EV_VERSION_MINOR; 2115 return EV_VERSION_MINOR;
2100} 2116}
2101 2117
2102/* 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 */
2110 || getgid () != getegid (); 2126 || getgid () != getegid ();
2111#endif 2127#endif
2112} 2128}
2113 2129
2114unsigned int ecb_cold 2130unsigned int ecb_cold
2115ev_supported_backends (void) 2131ev_supported_backends (void) EV_THROW
2116{ 2132{
2117 unsigned int flags = 0; 2133 unsigned int flags = 0;
2118 2134
2119 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2135 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2120 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2136 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2124 2140
2125 return flags; 2141 return flags;
2126} 2142}
2127 2143
2128unsigned int ecb_cold 2144unsigned int ecb_cold
2129ev_recommended_backends (void) 2145ev_recommended_backends (void) EV_THROW
2130{ 2146{
2131 unsigned int flags = ev_supported_backends (); 2147 unsigned int flags = ev_supported_backends ();
2132 2148
2133#ifndef __NetBSD__ 2149#ifndef __NetBSD__
2134 /* kqueue is borked on everything but netbsd apparently */ 2150 /* kqueue is borked on everything but netbsd apparently */
2146 2162
2147 return flags; 2163 return flags;
2148} 2164}
2149 2165
2150unsigned int ecb_cold 2166unsigned int ecb_cold
2151ev_embeddable_backends (void) 2167ev_embeddable_backends (void) EV_THROW
2152{ 2168{
2153 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2169 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2154 2170
2155 /* 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 */
2156 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 */
2158 2174
2159 return flags; 2175 return flags;
2160} 2176}
2161 2177
2162unsigned int 2178unsigned int
2163ev_backend (EV_P) 2179ev_backend (EV_P) EV_THROW
2164{ 2180{
2165 return backend; 2181 return backend;
2166} 2182}
2167 2183
2168#if EV_FEATURE_API 2184#if EV_FEATURE_API
2169unsigned int 2185unsigned int
2170ev_iteration (EV_P) 2186ev_iteration (EV_P) EV_THROW
2171{ 2187{
2172 return loop_count; 2188 return loop_count;
2173} 2189}
2174 2190
2175unsigned int 2191unsigned int
2176ev_depth (EV_P) 2192ev_depth (EV_P) EV_THROW
2177{ 2193{
2178 return loop_depth; 2194 return loop_depth;
2179} 2195}
2180 2196
2181void 2197void
2182ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2198ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2183{ 2199{
2184 io_blocktime = interval; 2200 io_blocktime = interval;
2185} 2201}
2186 2202
2187void 2203void
2188ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2204ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2189{ 2205{
2190 timeout_blocktime = interval; 2206 timeout_blocktime = interval;
2191} 2207}
2192 2208
2193void 2209void
2194ev_set_userdata (EV_P_ void *data) 2210ev_set_userdata (EV_P_ void *data) EV_THROW
2195{ 2211{
2196 userdata = data; 2212 userdata = data;
2197} 2213}
2198 2214
2199void * 2215void *
2200ev_userdata (EV_P) 2216ev_userdata (EV_P) EV_THROW
2201{ 2217{
2202 return userdata; 2218 return userdata;
2203} 2219}
2204 2220
2205void 2221void
2206ev_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
2207{ 2223{
2208 invoke_cb = invoke_pending_cb; 2224 invoke_cb = invoke_pending_cb;
2209} 2225}
2210 2226
2211void 2227void
2212ev_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
2213{ 2229{
2214 release_cb = release; 2230 release_cb = release;
2215 acquire_cb = acquire; 2231 acquire_cb = acquire;
2216} 2232}
2217#endif 2233#endif
2218 2234
2219/* initialise a loop structure, must be zero-initialised */ 2235/* initialise a loop structure, must be zero-initialised */
2220static void noinline ecb_cold 2236static void noinline ecb_cold
2221loop_init (EV_P_ unsigned int flags) 2237loop_init (EV_P_ unsigned int flags) EV_THROW
2222{ 2238{
2223 if (!backend) 2239 if (!backend)
2224 { 2240 {
2225 origflags = flags; 2241 origflags = flags;
2226 2242
2479} 2495}
2480 2496
2481#if EV_MULTIPLICITY 2497#if EV_MULTIPLICITY
2482 2498
2483struct ev_loop * ecb_cold 2499struct ev_loop * ecb_cold
2484ev_loop_new (unsigned int flags) 2500ev_loop_new (unsigned int flags) EV_THROW
2485{ 2501{
2486 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2502 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2487 2503
2488 memset (EV_A, 0, sizeof (struct ev_loop)); 2504 memset (EV_A, 0, sizeof (struct ev_loop));
2489 loop_init (EV_A_ flags); 2505 loop_init (EV_A_ flags);
2533} 2549}
2534#endif 2550#endif
2535 2551
2536#if EV_FEATURE_API 2552#if EV_FEATURE_API
2537void ecb_cold 2553void ecb_cold
2538ev_verify (EV_P) 2554ev_verify (EV_P) EV_THROW
2539{ 2555{
2540#if EV_VERIFY 2556#if EV_VERIFY
2541 int i; 2557 int i;
2542 WL w; 2558 WL w;
2543 2559
2612#if EV_MULTIPLICITY 2628#if EV_MULTIPLICITY
2613struct ev_loop * ecb_cold 2629struct ev_loop * ecb_cold
2614#else 2630#else
2615int 2631int
2616#endif 2632#endif
2617ev_default_loop (unsigned int flags) 2633ev_default_loop (unsigned int flags) EV_THROW
2618{ 2634{
2619 if (!ev_default_loop_ptr) 2635 if (!ev_default_loop_ptr)
2620 { 2636 {
2621#if EV_MULTIPLICITY 2637#if EV_MULTIPLICITY
2622 EV_P = ev_default_loop_ptr = &default_loop_struct; 2638 EV_P = ev_default_loop_ptr = &default_loop_struct;
2641 2657
2642 return ev_default_loop_ptr; 2658 return ev_default_loop_ptr;
2643} 2659}
2644 2660
2645void 2661void
2646ev_loop_fork (EV_P) 2662ev_loop_fork (EV_P) EV_THROW
2647{ 2663{
2648 postfork = 1; /* must be in line with ev_default_fork */ 2664 postfork = 1; /* must be in line with ev_default_fork */
2649} 2665}
2650 2666
2651/*****************************************************************************/ 2667/*****************************************************************************/
2655{ 2671{
2656 EV_CB_INVOKE ((W)w, revents); 2672 EV_CB_INVOKE ((W)w, revents);
2657} 2673}
2658 2674
2659unsigned int 2675unsigned int
2660ev_pending_count (EV_P) 2676ev_pending_count (EV_P) EV_THROW
2661{ 2677{
2662 int pri; 2678 int pri;
2663 unsigned int count = 0; 2679 unsigned int count = 0;
2664 2680
2665 for (pri = NUMPRI; pri--; ) 2681 for (pri = NUMPRI; pri--; )
2924 2940
2925 mn_now = ev_rt_now; 2941 mn_now = ev_rt_now;
2926 } 2942 }
2927} 2943}
2928 2944
2929void 2945int
2930ev_run (EV_P_ int flags) 2946ev_run (EV_P_ int flags)
2931{ 2947{
2932#if EV_FEATURE_API 2948#if EV_FEATURE_API
2933 ++loop_depth; 2949 ++loop_depth;
2934#endif 2950#endif
3091 loop_done = EVBREAK_CANCEL; 3107 loop_done = EVBREAK_CANCEL;
3092 3108
3093#if EV_FEATURE_API 3109#if EV_FEATURE_API
3094 --loop_depth; 3110 --loop_depth;
3095#endif 3111#endif
3112
3113 return activecnt;
3096} 3114}
3097 3115
3098void 3116void
3099ev_break (EV_P_ int how) 3117ev_break (EV_P_ int how) EV_THROW
3100{ 3118{
3101 loop_done = how; 3119 loop_done = how;
3102} 3120}
3103 3121
3104void 3122void
3105ev_ref (EV_P) 3123ev_ref (EV_P) EV_THROW
3106{ 3124{
3107 ++activecnt; 3125 ++activecnt;
3108} 3126}
3109 3127
3110void 3128void
3111ev_unref (EV_P) 3129ev_unref (EV_P) EV_THROW
3112{ 3130{
3113 --activecnt; 3131 --activecnt;
3114} 3132}
3115 3133
3116void 3134void
3117ev_now_update (EV_P) 3135ev_now_update (EV_P) EV_THROW
3118{ 3136{
3119 time_update (EV_A_ 1e100); 3137 time_update (EV_A_ 1e100);
3120} 3138}
3121 3139
3122void 3140void
3123ev_suspend (EV_P) 3141ev_suspend (EV_P) EV_THROW
3124{ 3142{
3125 ev_now_update (EV_A); 3143 ev_now_update (EV_A);
3126} 3144}
3127 3145
3128void 3146void
3129ev_resume (EV_P) 3147ev_resume (EV_P) EV_THROW
3130{ 3148{
3131 ev_tstamp mn_prev = mn_now; 3149 ev_tstamp mn_prev = mn_now;
3132 3150
3133 ev_now_update (EV_A); 3151 ev_now_update (EV_A);
3134 timers_reschedule (EV_A_ mn_now - mn_prev); 3152 timers_reschedule (EV_A_ mn_now - mn_prev);
3173 w->pending = 0; 3191 w->pending = 0;
3174 } 3192 }
3175} 3193}
3176 3194
3177int 3195int
3178ev_clear_pending (EV_P_ void *w) 3196ev_clear_pending (EV_P_ void *w) EV_THROW
3179{ 3197{
3180 W w_ = (W)w; 3198 W w_ = (W)w;
3181 int pending = w_->pending; 3199 int pending = w_->pending;
3182 3200
3183 if (expect_true (pending)) 3201 if (expect_true (pending))
3216} 3234}
3217 3235
3218/*****************************************************************************/ 3236/*****************************************************************************/
3219 3237
3220void noinline 3238void noinline
3221ev_io_start (EV_P_ ev_io *w) 3239ev_io_start (EV_P_ ev_io *w) EV_THROW
3222{ 3240{
3223 int fd = w->fd; 3241 int fd = w->fd;
3224 3242
3225 if (expect_false (ev_is_active (w))) 3243 if (expect_false (ev_is_active (w)))
3226 return; 3244 return;
3239 3257
3240 EV_FREQUENT_CHECK; 3258 EV_FREQUENT_CHECK;
3241} 3259}
3242 3260
3243void noinline 3261void noinline
3244ev_io_stop (EV_P_ ev_io *w) 3262ev_io_stop (EV_P_ ev_io *w) EV_THROW
3245{ 3263{
3246 clear_pending (EV_A_ (W)w); 3264 clear_pending (EV_A_ (W)w);
3247 if (expect_false (!ev_is_active (w))) 3265 if (expect_false (!ev_is_active (w)))
3248 return; 3266 return;
3249 3267
3258 3276
3259 EV_FREQUENT_CHECK; 3277 EV_FREQUENT_CHECK;
3260} 3278}
3261 3279
3262void noinline 3280void noinline
3263ev_timer_start (EV_P_ ev_timer *w) 3281ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3264{ 3282{
3265 if (expect_false (ev_is_active (w))) 3283 if (expect_false (ev_is_active (w)))
3266 return; 3284 return;
3267 3285
3268 ev_at (w) += mn_now; 3286 ev_at (w) += mn_now;
3282 3300
3283 /*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));*/
3284} 3302}
3285 3303
3286void noinline 3304void noinline
3287ev_timer_stop (EV_P_ ev_timer *w) 3305ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3288{ 3306{
3289 clear_pending (EV_A_ (W)w); 3307 clear_pending (EV_A_ (W)w);
3290 if (expect_false (!ev_is_active (w))) 3308 if (expect_false (!ev_is_active (w)))
3291 return; 3309 return;
3292 3310
3312 3330
3313 EV_FREQUENT_CHECK; 3331 EV_FREQUENT_CHECK;
3314} 3332}
3315 3333
3316void noinline 3334void noinline
3317ev_timer_again (EV_P_ ev_timer *w) 3335ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3318{ 3336{
3319 EV_FREQUENT_CHECK; 3337 EV_FREQUENT_CHECK;
3320 3338
3321 clear_pending (EV_A_ (W)w); 3339 clear_pending (EV_A_ (W)w);
3322 3340
3339 3357
3340 EV_FREQUENT_CHECK; 3358 EV_FREQUENT_CHECK;
3341} 3359}
3342 3360
3343ev_tstamp 3361ev_tstamp
3344ev_timer_remaining (EV_P_ ev_timer *w) 3362ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3345{ 3363{
3346 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3364 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3347} 3365}
3348 3366
3349#if EV_PERIODIC_ENABLE 3367#if EV_PERIODIC_ENABLE
3350void noinline 3368void noinline
3351ev_periodic_start (EV_P_ ev_periodic *w) 3369ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3352{ 3370{
3353 if (expect_false (ev_is_active (w))) 3371 if (expect_false (ev_is_active (w)))
3354 return; 3372 return;
3355 3373
3356 if (w->reschedule_cb) 3374 if (w->reschedule_cb)
3376 3394
3377 /*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));*/
3378} 3396}
3379 3397
3380void noinline 3398void noinline
3381ev_periodic_stop (EV_P_ ev_periodic *w) 3399ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3382{ 3400{
3383 clear_pending (EV_A_ (W)w); 3401 clear_pending (EV_A_ (W)w);
3384 if (expect_false (!ev_is_active (w))) 3402 if (expect_false (!ev_is_active (w)))
3385 return; 3403 return;
3386 3404
3404 3422
3405 EV_FREQUENT_CHECK; 3423 EV_FREQUENT_CHECK;
3406} 3424}
3407 3425
3408void noinline 3426void noinline
3409ev_periodic_again (EV_P_ ev_periodic *w) 3427ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3410{ 3428{
3411 /* TODO: use adjustheap and recalculation */ 3429 /* TODO: use adjustheap and recalculation */
3412 ev_periodic_stop (EV_A_ w); 3430 ev_periodic_stop (EV_A_ w);
3413 ev_periodic_start (EV_A_ w); 3431 ev_periodic_start (EV_A_ w);
3414} 3432}
3419#endif 3437#endif
3420 3438
3421#if EV_SIGNAL_ENABLE 3439#if EV_SIGNAL_ENABLE
3422 3440
3423void noinline 3441void noinline
3424ev_signal_start (EV_P_ ev_signal *w) 3442ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3425{ 3443{
3426 if (expect_false (ev_is_active (w))) 3444 if (expect_false (ev_is_active (w)))
3427 return; 3445 return;
3428 3446
3429 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));
3500 3518
3501 EV_FREQUENT_CHECK; 3519 EV_FREQUENT_CHECK;
3502} 3520}
3503 3521
3504void noinline 3522void noinline
3505ev_signal_stop (EV_P_ ev_signal *w) 3523ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3506{ 3524{
3507 clear_pending (EV_A_ (W)w); 3525 clear_pending (EV_A_ (W)w);
3508 if (expect_false (!ev_is_active (w))) 3526 if (expect_false (!ev_is_active (w)))
3509 return; 3527 return;
3510 3528
3541#endif 3559#endif
3542 3560
3543#if EV_CHILD_ENABLE 3561#if EV_CHILD_ENABLE
3544 3562
3545void 3563void
3546ev_child_start (EV_P_ ev_child *w) 3564ev_child_start (EV_P_ ev_child *w) EV_THROW
3547{ 3565{
3548#if EV_MULTIPLICITY 3566#if EV_MULTIPLICITY
3549 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));
3550#endif 3568#endif
3551 if (expect_false (ev_is_active (w))) 3569 if (expect_false (ev_is_active (w)))
3558 3576
3559 EV_FREQUENT_CHECK; 3577 EV_FREQUENT_CHECK;
3560} 3578}
3561 3579
3562void 3580void
3563ev_child_stop (EV_P_ ev_child *w) 3581ev_child_stop (EV_P_ ev_child *w) EV_THROW
3564{ 3582{
3565 clear_pending (EV_A_ (W)w); 3583 clear_pending (EV_A_ (W)w);
3566 if (expect_false (!ev_is_active (w))) 3584 if (expect_false (!ev_is_active (w)))
3567 return; 3585 return;
3568 3586
3735} 3753}
3736 3754
3737inline_size int 3755inline_size int
3738infy_newfd (void) 3756infy_newfd (void)
3739{ 3757{
3740#if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) 3758#if defined IN_CLOEXEC && defined IN_NONBLOCK
3741 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); 3759 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK);
3742 if (fd >= 0) 3760 if (fd >= 0)
3743 return fd; 3761 return fd;
3744#endif 3762#endif
3745 return inotify_init (); 3763 return inotify_init ();
3820#else 3838#else
3821# define EV_LSTAT(p,b) lstat (p, b) 3839# define EV_LSTAT(p,b) lstat (p, b)
3822#endif 3840#endif
3823 3841
3824void 3842void
3825ev_stat_stat (EV_P_ ev_stat *w) 3843ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3826{ 3844{
3827 if (lstat (w->path, &w->attr) < 0) 3845 if (lstat (w->path, &w->attr) < 0)
3828 w->attr.st_nlink = 0; 3846 w->attr.st_nlink = 0;
3829 else if (!w->attr.st_nlink) 3847 else if (!w->attr.st_nlink)
3830 w->attr.st_nlink = 1; 3848 w->attr.st_nlink = 1;
3869 ev_feed_event (EV_A_ w, EV_STAT); 3887 ev_feed_event (EV_A_ w, EV_STAT);
3870 } 3888 }
3871} 3889}
3872 3890
3873void 3891void
3874ev_stat_start (EV_P_ ev_stat *w) 3892ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3875{ 3893{
3876 if (expect_false (ev_is_active (w))) 3894 if (expect_false (ev_is_active (w)))
3877 return; 3895 return;
3878 3896
3879 ev_stat_stat (EV_A_ w); 3897 ev_stat_stat (EV_A_ w);
3900 3918
3901 EV_FREQUENT_CHECK; 3919 EV_FREQUENT_CHECK;
3902} 3920}
3903 3921
3904void 3922void
3905ev_stat_stop (EV_P_ ev_stat *w) 3923ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3906{ 3924{
3907 clear_pending (EV_A_ (W)w); 3925 clear_pending (EV_A_ (W)w);
3908 if (expect_false (!ev_is_active (w))) 3926 if (expect_false (!ev_is_active (w)))
3909 return; 3927 return;
3910 3928
3926} 3944}
3927#endif 3945#endif
3928 3946
3929#if EV_IDLE_ENABLE 3947#if EV_IDLE_ENABLE
3930void 3948void
3931ev_idle_start (EV_P_ ev_idle *w) 3949ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3932{ 3950{
3933 if (expect_false (ev_is_active (w))) 3951 if (expect_false (ev_is_active (w)))
3934 return; 3952 return;
3935 3953
3936 pri_adjust (EV_A_ (W)w); 3954 pri_adjust (EV_A_ (W)w);
3949 3967
3950 EV_FREQUENT_CHECK; 3968 EV_FREQUENT_CHECK;
3951} 3969}
3952 3970
3953void 3971void
3954ev_idle_stop (EV_P_ ev_idle *w) 3972ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3955{ 3973{
3956 clear_pending (EV_A_ (W)w); 3974 clear_pending (EV_A_ (W)w);
3957 if (expect_false (!ev_is_active (w))) 3975 if (expect_false (!ev_is_active (w)))
3958 return; 3976 return;
3959 3977
3973} 3991}
3974#endif 3992#endif
3975 3993
3976#if EV_PREPARE_ENABLE 3994#if EV_PREPARE_ENABLE
3977void 3995void
3978ev_prepare_start (EV_P_ ev_prepare *w) 3996ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3979{ 3997{
3980 if (expect_false (ev_is_active (w))) 3998 if (expect_false (ev_is_active (w)))
3981 return; 3999 return;
3982 4000
3983 EV_FREQUENT_CHECK; 4001 EV_FREQUENT_CHECK;
3988 4006
3989 EV_FREQUENT_CHECK; 4007 EV_FREQUENT_CHECK;
3990} 4008}
3991 4009
3992void 4010void
3993ev_prepare_stop (EV_P_ ev_prepare *w) 4011ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
3994{ 4012{
3995 clear_pending (EV_A_ (W)w); 4013 clear_pending (EV_A_ (W)w);
3996 if (expect_false (!ev_is_active (w))) 4014 if (expect_false (!ev_is_active (w)))
3997 return; 4015 return;
3998 4016
4011} 4029}
4012#endif 4030#endif
4013 4031
4014#if EV_CHECK_ENABLE 4032#if EV_CHECK_ENABLE
4015void 4033void
4016ev_check_start (EV_P_ ev_check *w) 4034ev_check_start (EV_P_ ev_check *w) EV_THROW
4017{ 4035{
4018 if (expect_false (ev_is_active (w))) 4036 if (expect_false (ev_is_active (w)))
4019 return; 4037 return;
4020 4038
4021 EV_FREQUENT_CHECK; 4039 EV_FREQUENT_CHECK;
4026 4044
4027 EV_FREQUENT_CHECK; 4045 EV_FREQUENT_CHECK;
4028} 4046}
4029 4047
4030void 4048void
4031ev_check_stop (EV_P_ ev_check *w) 4049ev_check_stop (EV_P_ ev_check *w) EV_THROW
4032{ 4050{
4033 clear_pending (EV_A_ (W)w); 4051 clear_pending (EV_A_ (W)w);
4034 if (expect_false (!ev_is_active (w))) 4052 if (expect_false (!ev_is_active (w)))
4035 return; 4053 return;
4036 4054
4049} 4067}
4050#endif 4068#endif
4051 4069
4052#if EV_EMBED_ENABLE 4070#if EV_EMBED_ENABLE
4053void noinline 4071void noinline
4054ev_embed_sweep (EV_P_ ev_embed *w) 4072ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4055{ 4073{
4056 ev_run (w->other, EVRUN_NOWAIT); 4074 ev_run (w->other, EVRUN_NOWAIT);
4057} 4075}
4058 4076
4059static void 4077static void
4107 ev_idle_stop (EV_A_ idle); 4125 ev_idle_stop (EV_A_ idle);
4108} 4126}
4109#endif 4127#endif
4110 4128
4111void 4129void
4112ev_embed_start (EV_P_ ev_embed *w) 4130ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4113{ 4131{
4114 if (expect_false (ev_is_active (w))) 4132 if (expect_false (ev_is_active (w)))
4115 return; 4133 return;
4116 4134
4117 { 4135 {
4138 4156
4139 EV_FREQUENT_CHECK; 4157 EV_FREQUENT_CHECK;
4140} 4158}
4141 4159
4142void 4160void
4143ev_embed_stop (EV_P_ ev_embed *w) 4161ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4144{ 4162{
4145 clear_pending (EV_A_ (W)w); 4163 clear_pending (EV_A_ (W)w);
4146 if (expect_false (!ev_is_active (w))) 4164 if (expect_false (!ev_is_active (w)))
4147 return; 4165 return;
4148 4166
4158} 4176}
4159#endif 4177#endif
4160 4178
4161#if EV_FORK_ENABLE 4179#if EV_FORK_ENABLE
4162void 4180void
4163ev_fork_start (EV_P_ ev_fork *w) 4181ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4164{ 4182{
4165 if (expect_false (ev_is_active (w))) 4183 if (expect_false (ev_is_active (w)))
4166 return; 4184 return;
4167 4185
4168 EV_FREQUENT_CHECK; 4186 EV_FREQUENT_CHECK;
4173 4191
4174 EV_FREQUENT_CHECK; 4192 EV_FREQUENT_CHECK;
4175} 4193}
4176 4194
4177void 4195void
4178ev_fork_stop (EV_P_ ev_fork *w) 4196ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4179{ 4197{
4180 clear_pending (EV_A_ (W)w); 4198 clear_pending (EV_A_ (W)w);
4181 if (expect_false (!ev_is_active (w))) 4199 if (expect_false (!ev_is_active (w)))
4182 return; 4200 return;
4183 4201
4196} 4214}
4197#endif 4215#endif
4198 4216
4199#if EV_CLEANUP_ENABLE 4217#if EV_CLEANUP_ENABLE
4200void 4218void
4201ev_cleanup_start (EV_P_ ev_cleanup *w) 4219ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4202{ 4220{
4203 if (expect_false (ev_is_active (w))) 4221 if (expect_false (ev_is_active (w)))
4204 return; 4222 return;
4205 4223
4206 EV_FREQUENT_CHECK; 4224 EV_FREQUENT_CHECK;
4213 ev_unref (EV_A); 4231 ev_unref (EV_A);
4214 EV_FREQUENT_CHECK; 4232 EV_FREQUENT_CHECK;
4215} 4233}
4216 4234
4217void 4235void
4218ev_cleanup_stop (EV_P_ ev_cleanup *w) 4236ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4219{ 4237{
4220 clear_pending (EV_A_ (W)w); 4238 clear_pending (EV_A_ (W)w);
4221 if (expect_false (!ev_is_active (w))) 4239 if (expect_false (!ev_is_active (w)))
4222 return; 4240 return;
4223 4241
4237} 4255}
4238#endif 4256#endif
4239 4257
4240#if EV_ASYNC_ENABLE 4258#if EV_ASYNC_ENABLE
4241void 4259void
4242ev_async_start (EV_P_ ev_async *w) 4260ev_async_start (EV_P_ ev_async *w) EV_THROW
4243{ 4261{
4244 if (expect_false (ev_is_active (w))) 4262 if (expect_false (ev_is_active (w)))
4245 return; 4263 return;
4246 4264
4247 w->sent = 0; 4265 w->sent = 0;
4256 4274
4257 EV_FREQUENT_CHECK; 4275 EV_FREQUENT_CHECK;
4258} 4276}
4259 4277
4260void 4278void
4261ev_async_stop (EV_P_ ev_async *w) 4279ev_async_stop (EV_P_ ev_async *w) EV_THROW
4262{ 4280{
4263 clear_pending (EV_A_ (W)w); 4281 clear_pending (EV_A_ (W)w);
4264 if (expect_false (!ev_is_active (w))) 4282 if (expect_false (!ev_is_active (w)))
4265 return; 4283 return;
4266 4284
4277 4295
4278 EV_FREQUENT_CHECK; 4296 EV_FREQUENT_CHECK;
4279} 4297}
4280 4298
4281void 4299void
4282ev_async_send (EV_P_ ev_async *w) 4300ev_async_send (EV_P_ ev_async *w) EV_THROW
4283{ 4301{
4284 w->sent = 1; 4302 w->sent = 1;
4285 evpipe_write (EV_A_ &async_pending); 4303 evpipe_write (EV_A_ &async_pending);
4286} 4304}
4287#endif 4305#endif
4324 4342
4325 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));
4326} 4344}
4327 4345
4328void 4346void
4329ev_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
4330{ 4348{
4331 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));
4332 4350
4333 if (expect_false (!once)) 4351 if (expect_false (!once))
4334 { 4352 {
4356 4374
4357/*****************************************************************************/ 4375/*****************************************************************************/
4358 4376
4359#if EV_WALK_ENABLE 4377#if EV_WALK_ENABLE
4360void ecb_cold 4378void ecb_cold
4361ev_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
4362{ 4380{
4363 int i, j; 4381 int i, j;
4364 ev_watcher_list *wl, *wn; 4382 ev_watcher_list *wl, *wn;
4365 4383
4366 if (types & (EV_IO | EV_EMBED)) 4384 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines