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

Comparing libev/ev.c (file contents):
Revision 1.411 by root, Tue Feb 21 04:34:02 2012 UTC vs.
Revision 1.426 by root, Sun May 6 13:42:10 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))
1424 w_->pending = ++pendingcnt [pri]; 1430 w_->pending = ++pendingcnt [pri];
1425 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 1431 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2);
1426 pendings [pri][w_->pending - 1].w = w_; 1432 pendings [pri][w_->pending - 1].w = w_;
1427 pendings [pri][w_->pending - 1].events = revents; 1433 pendings [pri][w_->pending - 1].events = revents;
1428 } 1434 }
1435
1436 pendingpri = NUMPRI - 1;
1429} 1437}
1430 1438
1431inline_speed void 1439inline_speed void
1432feed_reverse (EV_P_ W w) 1440feed_reverse (EV_P_ W w)
1433{ 1441{
1479 if (expect_true (!anfd->reify)) 1487 if (expect_true (!anfd->reify))
1480 fd_event_nocheck (EV_A_ fd, revents); 1488 fd_event_nocheck (EV_A_ fd, revents);
1481} 1489}
1482 1490
1483void 1491void
1484ev_feed_fd_event (EV_P_ int fd, int revents) 1492ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1485{ 1493{
1486 if (fd >= 0 && fd < anfdmax) 1494 if (fd >= 0 && fd < anfdmax)
1487 fd_event_nocheck (EV_A_ fd, revents); 1495 fd_event_nocheck (EV_A_ fd, revents);
1488} 1496}
1489 1497
1838} 1846}
1839 1847
1840inline_speed void 1848inline_speed void
1841evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1849evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1842{ 1850{
1851 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1852
1843 if (expect_true (*flag)) 1853 if (expect_true (*flag))
1844 return; 1854 return;
1845 1855
1846 *flag = 1; 1856 *flag = 1;
1847 1857
1906 } 1916 }
1907 } 1917 }
1908 1918
1909 pipe_write_skipped = 0; 1919 pipe_write_skipped = 0;
1910 1920
1921 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1922
1911#if EV_SIGNAL_ENABLE 1923#if EV_SIGNAL_ENABLE
1912 if (sig_pending) 1924 if (sig_pending)
1913 { 1925 {
1914 sig_pending = 0; 1926 sig_pending = 0;
1927
1928 ECB_MEMORY_FENCE_RELEASE;
1915 1929
1916 for (i = EV_NSIG - 1; i--; ) 1930 for (i = EV_NSIG - 1; i--; )
1917 if (expect_false (signals [i].pending)) 1931 if (expect_false (signals [i].pending))
1918 ev_feed_signal_event (EV_A_ i + 1); 1932 ev_feed_signal_event (EV_A_ i + 1);
1919 } 1933 }
1921 1935
1922#if EV_ASYNC_ENABLE 1936#if EV_ASYNC_ENABLE
1923 if (async_pending) 1937 if (async_pending)
1924 { 1938 {
1925 async_pending = 0; 1939 async_pending = 0;
1940
1941 ECB_MEMORY_FENCE_RELEASE;
1926 1942
1927 for (i = asynccnt; i--; ) 1943 for (i = asynccnt; i--; )
1928 if (asyncs [i]->sent) 1944 if (asyncs [i]->sent)
1929 { 1945 {
1930 asyncs [i]->sent = 0; 1946 asyncs [i]->sent = 0;
1935} 1951}
1936 1952
1937/*****************************************************************************/ 1953/*****************************************************************************/
1938 1954
1939void 1955void
1940ev_feed_signal (int signum) 1956ev_feed_signal (int signum) EV_THROW
1941{ 1957{
1942#if EV_MULTIPLICITY 1958#if EV_MULTIPLICITY
1943 EV_P = signals [signum - 1].loop; 1959 EV_P = signals [signum - 1].loop;
1944 1960
1945 if (!EV_A) 1961 if (!EV_A)
1962 1978
1963 ev_feed_signal (signum); 1979 ev_feed_signal (signum);
1964} 1980}
1965 1981
1966void noinline 1982void noinline
1967ev_feed_signal_event (EV_P_ int signum) 1983ev_feed_signal_event (EV_P_ int signum) EV_THROW
1968{ 1984{
1969 WL w; 1985 WL w;
1970 1986
1971 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1987 if (expect_false (signum <= 0 || signum > EV_NSIG))
1972 return; 1988 return;
2088#if EV_USE_SELECT 2104#if EV_USE_SELECT
2089# include "ev_select.c" 2105# include "ev_select.c"
2090#endif 2106#endif
2091 2107
2092int ecb_cold 2108int ecb_cold
2093ev_version_major (void) 2109ev_version_major (void) EV_THROW
2094{ 2110{
2095 return EV_VERSION_MAJOR; 2111 return EV_VERSION_MAJOR;
2096} 2112}
2097 2113
2098int ecb_cold 2114int ecb_cold
2099ev_version_minor (void) 2115ev_version_minor (void) EV_THROW
2100{ 2116{
2101 return EV_VERSION_MINOR; 2117 return EV_VERSION_MINOR;
2102} 2118}
2103 2119
2104/* return true if we are running with elevated privileges and should ignore env variables */ 2120/* return true if we are running with elevated privileges and should ignore env variables */
2112 || getgid () != getegid (); 2128 || getgid () != getegid ();
2113#endif 2129#endif
2114} 2130}
2115 2131
2116unsigned int ecb_cold 2132unsigned int ecb_cold
2117ev_supported_backends (void) 2133ev_supported_backends (void) EV_THROW
2118{ 2134{
2119 unsigned int flags = 0; 2135 unsigned int flags = 0;
2120 2136
2121 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2137 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2122 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2138 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2126 2142
2127 return flags; 2143 return flags;
2128} 2144}
2129 2145
2130unsigned int ecb_cold 2146unsigned int ecb_cold
2131ev_recommended_backends (void) 2147ev_recommended_backends (void) EV_THROW
2132{ 2148{
2133 unsigned int flags = ev_supported_backends (); 2149 unsigned int flags = ev_supported_backends ();
2134 2150
2135#ifndef __NetBSD__ 2151#ifndef __NetBSD__
2136 /* kqueue is borked on everything but netbsd apparently */ 2152 /* kqueue is borked on everything but netbsd apparently */
2148 2164
2149 return flags; 2165 return flags;
2150} 2166}
2151 2167
2152unsigned int ecb_cold 2168unsigned int ecb_cold
2153ev_embeddable_backends (void) 2169ev_embeddable_backends (void) EV_THROW
2154{ 2170{
2155 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2171 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2156 2172
2157 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2173 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2158 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2174 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2160 2176
2161 return flags; 2177 return flags;
2162} 2178}
2163 2179
2164unsigned int 2180unsigned int
2165ev_backend (EV_P) 2181ev_backend (EV_P) EV_THROW
2166{ 2182{
2167 return backend; 2183 return backend;
2168} 2184}
2169 2185
2170#if EV_FEATURE_API 2186#if EV_FEATURE_API
2171unsigned int 2187unsigned int
2172ev_iteration (EV_P) 2188ev_iteration (EV_P) EV_THROW
2173{ 2189{
2174 return loop_count; 2190 return loop_count;
2175} 2191}
2176 2192
2177unsigned int 2193unsigned int
2178ev_depth (EV_P) 2194ev_depth (EV_P) EV_THROW
2179{ 2195{
2180 return loop_depth; 2196 return loop_depth;
2181} 2197}
2182 2198
2183void 2199void
2184ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2200ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2185{ 2201{
2186 io_blocktime = interval; 2202 io_blocktime = interval;
2187} 2203}
2188 2204
2189void 2205void
2190ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2206ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2191{ 2207{
2192 timeout_blocktime = interval; 2208 timeout_blocktime = interval;
2193} 2209}
2194 2210
2195void 2211void
2196ev_set_userdata (EV_P_ void *data) 2212ev_set_userdata (EV_P_ void *data) EV_THROW
2197{ 2213{
2198 userdata = data; 2214 userdata = data;
2199} 2215}
2200 2216
2201void * 2217void *
2202ev_userdata (EV_P) 2218ev_userdata (EV_P) EV_THROW
2203{ 2219{
2204 return userdata; 2220 return userdata;
2205} 2221}
2206 2222
2207void 2223void
2208ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 2224ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW
2209{ 2225{
2210 invoke_cb = invoke_pending_cb; 2226 invoke_cb = invoke_pending_cb;
2211} 2227}
2212 2228
2213void 2229void
2214ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 2230ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW
2215{ 2231{
2216 release_cb = release; 2232 release_cb = release;
2217 acquire_cb = acquire; 2233 acquire_cb = acquire;
2218} 2234}
2219#endif 2235#endif
2220 2236
2221/* initialise a loop structure, must be zero-initialised */ 2237/* initialise a loop structure, must be zero-initialised */
2222static void noinline ecb_cold 2238static void noinline ecb_cold
2223loop_init (EV_P_ unsigned int flags) 2239loop_init (EV_P_ unsigned int flags) EV_THROW
2224{ 2240{
2225 if (!backend) 2241 if (!backend)
2226 { 2242 {
2227 origflags = flags; 2243 origflags = flags;
2228 2244
2481} 2497}
2482 2498
2483#if EV_MULTIPLICITY 2499#if EV_MULTIPLICITY
2484 2500
2485struct ev_loop * ecb_cold 2501struct ev_loop * ecb_cold
2486ev_loop_new (unsigned int flags) 2502ev_loop_new (unsigned int flags) EV_THROW
2487{ 2503{
2488 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2504 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2489 2505
2490 memset (EV_A, 0, sizeof (struct ev_loop)); 2506 memset (EV_A, 0, sizeof (struct ev_loop));
2491 loop_init (EV_A_ flags); 2507 loop_init (EV_A_ flags);
2535} 2551}
2536#endif 2552#endif
2537 2553
2538#if EV_FEATURE_API 2554#if EV_FEATURE_API
2539void ecb_cold 2555void ecb_cold
2540ev_verify (EV_P) 2556ev_verify (EV_P) EV_THROW
2541{ 2557{
2542#if EV_VERIFY 2558#if EV_VERIFY
2543 int i; 2559 int i, j;
2544 WL w; 2560 WL w, w2;
2545 2561
2546 assert (activecnt >= -1); 2562 assert (activecnt >= -1);
2547 2563
2548 assert (fdchangemax >= fdchangecnt); 2564 assert (fdchangemax >= fdchangecnt);
2549 for (i = 0; i < fdchangecnt; ++i) 2565 for (i = 0; i < fdchangecnt; ++i)
2550 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2566 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2551 2567
2552 assert (anfdmax >= 0); 2568 assert (anfdmax >= 0);
2553 for (i = 0; i < anfdmax; ++i) 2569 for (i = j = 0; i < anfdmax; ++i)
2554 for (w = anfds [i].head; w; w = w->next) 2570 for (w = w2 = anfds [i].head; w; w = w->next)
2555 { 2571 {
2556 verify_watcher (EV_A_ (W)w); 2572 verify_watcher (EV_A_ (W)w);
2573
2574 if (++j & 1)
2575 w2 = w2->next;
2576
2577 assert (("libev: io watcher list contains a loop", w != w2));
2557 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2578 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2558 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2579 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2559 } 2580 }
2560 2581
2561 assert (timermax >= timercnt); 2582 assert (timermax >= timercnt);
2614#if EV_MULTIPLICITY 2635#if EV_MULTIPLICITY
2615struct ev_loop * ecb_cold 2636struct ev_loop * ecb_cold
2616#else 2637#else
2617int 2638int
2618#endif 2639#endif
2619ev_default_loop (unsigned int flags) 2640ev_default_loop (unsigned int flags) EV_THROW
2620{ 2641{
2621 if (!ev_default_loop_ptr) 2642 if (!ev_default_loop_ptr)
2622 { 2643 {
2623#if EV_MULTIPLICITY 2644#if EV_MULTIPLICITY
2624 EV_P = ev_default_loop_ptr = &default_loop_struct; 2645 EV_P = ev_default_loop_ptr = &default_loop_struct;
2643 2664
2644 return ev_default_loop_ptr; 2665 return ev_default_loop_ptr;
2645} 2666}
2646 2667
2647void 2668void
2648ev_loop_fork (EV_P) 2669ev_loop_fork (EV_P) EV_THROW
2649{ 2670{
2650 postfork = 1; /* must be in line with ev_default_fork */ 2671 postfork = 1; /* must be in line with ev_default_fork */
2651} 2672}
2652 2673
2653/*****************************************************************************/ 2674/*****************************************************************************/
2657{ 2678{
2658 EV_CB_INVOKE ((W)w, revents); 2679 EV_CB_INVOKE ((W)w, revents);
2659} 2680}
2660 2681
2661unsigned int 2682unsigned int
2662ev_pending_count (EV_P) 2683ev_pending_count (EV_P) EV_THROW
2663{ 2684{
2664 int pri; 2685 int pri;
2665 unsigned int count = 0; 2686 unsigned int count = 0;
2666 2687
2667 for (pri = NUMPRI; pri--; ) 2688 for (pri = NUMPRI; pri--; )
2671} 2692}
2672 2693
2673void noinline 2694void noinline
2674ev_invoke_pending (EV_P) 2695ev_invoke_pending (EV_P)
2675{ 2696{
2676 int pri; 2697 for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */
2677
2678 for (pri = NUMPRI; pri--; )
2679 while (pendingcnt [pri]) 2698 while (pendingcnt [pendingpri])
2680 { 2699 {
2681 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2700 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
2682 2701
2683 p->w->pending = 0; 2702 p->w->pending = 0;
2684 EV_CB_INVOKE (p->w, p->events); 2703 EV_CB_INVOKE (p->w, p->events);
2685 EV_FREQUENT_CHECK; 2704 EV_FREQUENT_CHECK;
2686 } 2705 }
2926 2945
2927 mn_now = ev_rt_now; 2946 mn_now = ev_rt_now;
2928 } 2947 }
2929} 2948}
2930 2949
2931void 2950int
2932ev_run (EV_P_ int flags) 2951ev_run (EV_P_ int flags)
2933{ 2952{
2934#if EV_FEATURE_API 2953#if EV_FEATURE_API
2935 ++loop_depth; 2954 ++loop_depth;
2936#endif 2955#endif
3093 loop_done = EVBREAK_CANCEL; 3112 loop_done = EVBREAK_CANCEL;
3094 3113
3095#if EV_FEATURE_API 3114#if EV_FEATURE_API
3096 --loop_depth; 3115 --loop_depth;
3097#endif 3116#endif
3117
3118 return activecnt;
3098} 3119}
3099 3120
3100void 3121void
3101ev_break (EV_P_ int how) 3122ev_break (EV_P_ int how) EV_THROW
3102{ 3123{
3103 loop_done = how; 3124 loop_done = how;
3104} 3125}
3105 3126
3106void 3127void
3107ev_ref (EV_P) 3128ev_ref (EV_P) EV_THROW
3108{ 3129{
3109 ++activecnt; 3130 ++activecnt;
3110} 3131}
3111 3132
3112void 3133void
3113ev_unref (EV_P) 3134ev_unref (EV_P) EV_THROW
3114{ 3135{
3115 --activecnt; 3136 --activecnt;
3116} 3137}
3117 3138
3118void 3139void
3119ev_now_update (EV_P) 3140ev_now_update (EV_P) EV_THROW
3120{ 3141{
3121 time_update (EV_A_ 1e100); 3142 time_update (EV_A_ 1e100);
3122} 3143}
3123 3144
3124void 3145void
3125ev_suspend (EV_P) 3146ev_suspend (EV_P) EV_THROW
3126{ 3147{
3127 ev_now_update (EV_A); 3148 ev_now_update (EV_A);
3128} 3149}
3129 3150
3130void 3151void
3131ev_resume (EV_P) 3152ev_resume (EV_P) EV_THROW
3132{ 3153{
3133 ev_tstamp mn_prev = mn_now; 3154 ev_tstamp mn_prev = mn_now;
3134 3155
3135 ev_now_update (EV_A); 3156 ev_now_update (EV_A);
3136 timers_reschedule (EV_A_ mn_now - mn_prev); 3157 timers_reschedule (EV_A_ mn_now - mn_prev);
3175 w->pending = 0; 3196 w->pending = 0;
3176 } 3197 }
3177} 3198}
3178 3199
3179int 3200int
3180ev_clear_pending (EV_P_ void *w) 3201ev_clear_pending (EV_P_ void *w) EV_THROW
3181{ 3202{
3182 W w_ = (W)w; 3203 W w_ = (W)w;
3183 int pending = w_->pending; 3204 int pending = w_->pending;
3184 3205
3185 if (expect_true (pending)) 3206 if (expect_true (pending))
3218} 3239}
3219 3240
3220/*****************************************************************************/ 3241/*****************************************************************************/
3221 3242
3222void noinline 3243void noinline
3223ev_io_start (EV_P_ ev_io *w) 3244ev_io_start (EV_P_ ev_io *w) EV_THROW
3224{ 3245{
3225 int fd = w->fd; 3246 int fd = w->fd;
3226 3247
3227 if (expect_false (ev_is_active (w))) 3248 if (expect_false (ev_is_active (w)))
3228 return; 3249 return;
3234 3255
3235 ev_start (EV_A_ (W)w, 1); 3256 ev_start (EV_A_ (W)w, 1);
3236 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3257 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
3237 wlist_add (&anfds[fd].head, (WL)w); 3258 wlist_add (&anfds[fd].head, (WL)w);
3238 3259
3260 /* common bug, apparently */
3261 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3262
3239 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); 3263 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY);
3240 w->events &= ~EV__IOFDSET; 3264 w->events &= ~EV__IOFDSET;
3241 3265
3242 EV_FREQUENT_CHECK; 3266 EV_FREQUENT_CHECK;
3243} 3267}
3244 3268
3245void noinline 3269void noinline
3246ev_io_stop (EV_P_ ev_io *w) 3270ev_io_stop (EV_P_ ev_io *w) EV_THROW
3247{ 3271{
3248 clear_pending (EV_A_ (W)w); 3272 clear_pending (EV_A_ (W)w);
3249 if (expect_false (!ev_is_active (w))) 3273 if (expect_false (!ev_is_active (w)))
3250 return; 3274 return;
3251 3275
3260 3284
3261 EV_FREQUENT_CHECK; 3285 EV_FREQUENT_CHECK;
3262} 3286}
3263 3287
3264void noinline 3288void noinline
3265ev_timer_start (EV_P_ ev_timer *w) 3289ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3266{ 3290{
3267 if (expect_false (ev_is_active (w))) 3291 if (expect_false (ev_is_active (w)))
3268 return; 3292 return;
3269 3293
3270 ev_at (w) += mn_now; 3294 ev_at (w) += mn_now;
3284 3308
3285 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3309 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3286} 3310}
3287 3311
3288void noinline 3312void noinline
3289ev_timer_stop (EV_P_ ev_timer *w) 3313ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3290{ 3314{
3291 clear_pending (EV_A_ (W)w); 3315 clear_pending (EV_A_ (W)w);
3292 if (expect_false (!ev_is_active (w))) 3316 if (expect_false (!ev_is_active (w)))
3293 return; 3317 return;
3294 3318
3314 3338
3315 EV_FREQUENT_CHECK; 3339 EV_FREQUENT_CHECK;
3316} 3340}
3317 3341
3318void noinline 3342void noinline
3319ev_timer_again (EV_P_ ev_timer *w) 3343ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3320{ 3344{
3321 EV_FREQUENT_CHECK; 3345 EV_FREQUENT_CHECK;
3322 3346
3323 clear_pending (EV_A_ (W)w); 3347 clear_pending (EV_A_ (W)w);
3324 3348
3341 3365
3342 EV_FREQUENT_CHECK; 3366 EV_FREQUENT_CHECK;
3343} 3367}
3344 3368
3345ev_tstamp 3369ev_tstamp
3346ev_timer_remaining (EV_P_ ev_timer *w) 3370ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3347{ 3371{
3348 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3372 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3349} 3373}
3350 3374
3351#if EV_PERIODIC_ENABLE 3375#if EV_PERIODIC_ENABLE
3352void noinline 3376void noinline
3353ev_periodic_start (EV_P_ ev_periodic *w) 3377ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3354{ 3378{
3355 if (expect_false (ev_is_active (w))) 3379 if (expect_false (ev_is_active (w)))
3356 return; 3380 return;
3357 3381
3358 if (w->reschedule_cb) 3382 if (w->reschedule_cb)
3378 3402
3379 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3403 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3380} 3404}
3381 3405
3382void noinline 3406void noinline
3383ev_periodic_stop (EV_P_ ev_periodic *w) 3407ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3384{ 3408{
3385 clear_pending (EV_A_ (W)w); 3409 clear_pending (EV_A_ (W)w);
3386 if (expect_false (!ev_is_active (w))) 3410 if (expect_false (!ev_is_active (w)))
3387 return; 3411 return;
3388 3412
3406 3430
3407 EV_FREQUENT_CHECK; 3431 EV_FREQUENT_CHECK;
3408} 3432}
3409 3433
3410void noinline 3434void noinline
3411ev_periodic_again (EV_P_ ev_periodic *w) 3435ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3412{ 3436{
3413 /* TODO: use adjustheap and recalculation */ 3437 /* TODO: use adjustheap and recalculation */
3414 ev_periodic_stop (EV_A_ w); 3438 ev_periodic_stop (EV_A_ w);
3415 ev_periodic_start (EV_A_ w); 3439 ev_periodic_start (EV_A_ w);
3416} 3440}
3421#endif 3445#endif
3422 3446
3423#if EV_SIGNAL_ENABLE 3447#if EV_SIGNAL_ENABLE
3424 3448
3425void noinline 3449void noinline
3426ev_signal_start (EV_P_ ev_signal *w) 3450ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3427{ 3451{
3428 if (expect_false (ev_is_active (w))) 3452 if (expect_false (ev_is_active (w)))
3429 return; 3453 return;
3430 3454
3431 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3455 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3502 3526
3503 EV_FREQUENT_CHECK; 3527 EV_FREQUENT_CHECK;
3504} 3528}
3505 3529
3506void noinline 3530void noinline
3507ev_signal_stop (EV_P_ ev_signal *w) 3531ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3508{ 3532{
3509 clear_pending (EV_A_ (W)w); 3533 clear_pending (EV_A_ (W)w);
3510 if (expect_false (!ev_is_active (w))) 3534 if (expect_false (!ev_is_active (w)))
3511 return; 3535 return;
3512 3536
3543#endif 3567#endif
3544 3568
3545#if EV_CHILD_ENABLE 3569#if EV_CHILD_ENABLE
3546 3570
3547void 3571void
3548ev_child_start (EV_P_ ev_child *w) 3572ev_child_start (EV_P_ ev_child *w) EV_THROW
3549{ 3573{
3550#if EV_MULTIPLICITY 3574#if EV_MULTIPLICITY
3551 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3575 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3552#endif 3576#endif
3553 if (expect_false (ev_is_active (w))) 3577 if (expect_false (ev_is_active (w)))
3560 3584
3561 EV_FREQUENT_CHECK; 3585 EV_FREQUENT_CHECK;
3562} 3586}
3563 3587
3564void 3588void
3565ev_child_stop (EV_P_ ev_child *w) 3589ev_child_stop (EV_P_ ev_child *w) EV_THROW
3566{ 3590{
3567 clear_pending (EV_A_ (W)w); 3591 clear_pending (EV_A_ (W)w);
3568 if (expect_false (!ev_is_active (w))) 3592 if (expect_false (!ev_is_active (w)))
3569 return; 3593 return;
3570 3594
3737} 3761}
3738 3762
3739inline_size int 3763inline_size int
3740infy_newfd (void) 3764infy_newfd (void)
3741{ 3765{
3742#if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) 3766#if defined IN_CLOEXEC && defined IN_NONBLOCK
3743 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); 3767 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK);
3744 if (fd >= 0) 3768 if (fd >= 0)
3745 return fd; 3769 return fd;
3746#endif 3770#endif
3747 return inotify_init (); 3771 return inotify_init ();
3822#else 3846#else
3823# define EV_LSTAT(p,b) lstat (p, b) 3847# define EV_LSTAT(p,b) lstat (p, b)
3824#endif 3848#endif
3825 3849
3826void 3850void
3827ev_stat_stat (EV_P_ ev_stat *w) 3851ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3828{ 3852{
3829 if (lstat (w->path, &w->attr) < 0) 3853 if (lstat (w->path, &w->attr) < 0)
3830 w->attr.st_nlink = 0; 3854 w->attr.st_nlink = 0;
3831 else if (!w->attr.st_nlink) 3855 else if (!w->attr.st_nlink)
3832 w->attr.st_nlink = 1; 3856 w->attr.st_nlink = 1;
3871 ev_feed_event (EV_A_ w, EV_STAT); 3895 ev_feed_event (EV_A_ w, EV_STAT);
3872 } 3896 }
3873} 3897}
3874 3898
3875void 3899void
3876ev_stat_start (EV_P_ ev_stat *w) 3900ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3877{ 3901{
3878 if (expect_false (ev_is_active (w))) 3902 if (expect_false (ev_is_active (w)))
3879 return; 3903 return;
3880 3904
3881 ev_stat_stat (EV_A_ w); 3905 ev_stat_stat (EV_A_ w);
3902 3926
3903 EV_FREQUENT_CHECK; 3927 EV_FREQUENT_CHECK;
3904} 3928}
3905 3929
3906void 3930void
3907ev_stat_stop (EV_P_ ev_stat *w) 3931ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3908{ 3932{
3909 clear_pending (EV_A_ (W)w); 3933 clear_pending (EV_A_ (W)w);
3910 if (expect_false (!ev_is_active (w))) 3934 if (expect_false (!ev_is_active (w)))
3911 return; 3935 return;
3912 3936
3928} 3952}
3929#endif 3953#endif
3930 3954
3931#if EV_IDLE_ENABLE 3955#if EV_IDLE_ENABLE
3932void 3956void
3933ev_idle_start (EV_P_ ev_idle *w) 3957ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3934{ 3958{
3935 if (expect_false (ev_is_active (w))) 3959 if (expect_false (ev_is_active (w)))
3936 return; 3960 return;
3937 3961
3938 pri_adjust (EV_A_ (W)w); 3962 pri_adjust (EV_A_ (W)w);
3951 3975
3952 EV_FREQUENT_CHECK; 3976 EV_FREQUENT_CHECK;
3953} 3977}
3954 3978
3955void 3979void
3956ev_idle_stop (EV_P_ ev_idle *w) 3980ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3957{ 3981{
3958 clear_pending (EV_A_ (W)w); 3982 clear_pending (EV_A_ (W)w);
3959 if (expect_false (!ev_is_active (w))) 3983 if (expect_false (!ev_is_active (w)))
3960 return; 3984 return;
3961 3985
3975} 3999}
3976#endif 4000#endif
3977 4001
3978#if EV_PREPARE_ENABLE 4002#if EV_PREPARE_ENABLE
3979void 4003void
3980ev_prepare_start (EV_P_ ev_prepare *w) 4004ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3981{ 4005{
3982 if (expect_false (ev_is_active (w))) 4006 if (expect_false (ev_is_active (w)))
3983 return; 4007 return;
3984 4008
3985 EV_FREQUENT_CHECK; 4009 EV_FREQUENT_CHECK;
3990 4014
3991 EV_FREQUENT_CHECK; 4015 EV_FREQUENT_CHECK;
3992} 4016}
3993 4017
3994void 4018void
3995ev_prepare_stop (EV_P_ ev_prepare *w) 4019ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
3996{ 4020{
3997 clear_pending (EV_A_ (W)w); 4021 clear_pending (EV_A_ (W)w);
3998 if (expect_false (!ev_is_active (w))) 4022 if (expect_false (!ev_is_active (w)))
3999 return; 4023 return;
4000 4024
4013} 4037}
4014#endif 4038#endif
4015 4039
4016#if EV_CHECK_ENABLE 4040#if EV_CHECK_ENABLE
4017void 4041void
4018ev_check_start (EV_P_ ev_check *w) 4042ev_check_start (EV_P_ ev_check *w) EV_THROW
4019{ 4043{
4020 if (expect_false (ev_is_active (w))) 4044 if (expect_false (ev_is_active (w)))
4021 return; 4045 return;
4022 4046
4023 EV_FREQUENT_CHECK; 4047 EV_FREQUENT_CHECK;
4028 4052
4029 EV_FREQUENT_CHECK; 4053 EV_FREQUENT_CHECK;
4030} 4054}
4031 4055
4032void 4056void
4033ev_check_stop (EV_P_ ev_check *w) 4057ev_check_stop (EV_P_ ev_check *w) EV_THROW
4034{ 4058{
4035 clear_pending (EV_A_ (W)w); 4059 clear_pending (EV_A_ (W)w);
4036 if (expect_false (!ev_is_active (w))) 4060 if (expect_false (!ev_is_active (w)))
4037 return; 4061 return;
4038 4062
4051} 4075}
4052#endif 4076#endif
4053 4077
4054#if EV_EMBED_ENABLE 4078#if EV_EMBED_ENABLE
4055void noinline 4079void noinline
4056ev_embed_sweep (EV_P_ ev_embed *w) 4080ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4057{ 4081{
4058 ev_run (w->other, EVRUN_NOWAIT); 4082 ev_run (w->other, EVRUN_NOWAIT);
4059} 4083}
4060 4084
4061static void 4085static void
4109 ev_idle_stop (EV_A_ idle); 4133 ev_idle_stop (EV_A_ idle);
4110} 4134}
4111#endif 4135#endif
4112 4136
4113void 4137void
4114ev_embed_start (EV_P_ ev_embed *w) 4138ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4115{ 4139{
4116 if (expect_false (ev_is_active (w))) 4140 if (expect_false (ev_is_active (w)))
4117 return; 4141 return;
4118 4142
4119 { 4143 {
4140 4164
4141 EV_FREQUENT_CHECK; 4165 EV_FREQUENT_CHECK;
4142} 4166}
4143 4167
4144void 4168void
4145ev_embed_stop (EV_P_ ev_embed *w) 4169ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4146{ 4170{
4147 clear_pending (EV_A_ (W)w); 4171 clear_pending (EV_A_ (W)w);
4148 if (expect_false (!ev_is_active (w))) 4172 if (expect_false (!ev_is_active (w)))
4149 return; 4173 return;
4150 4174
4160} 4184}
4161#endif 4185#endif
4162 4186
4163#if EV_FORK_ENABLE 4187#if EV_FORK_ENABLE
4164void 4188void
4165ev_fork_start (EV_P_ ev_fork *w) 4189ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4166{ 4190{
4167 if (expect_false (ev_is_active (w))) 4191 if (expect_false (ev_is_active (w)))
4168 return; 4192 return;
4169 4193
4170 EV_FREQUENT_CHECK; 4194 EV_FREQUENT_CHECK;
4175 4199
4176 EV_FREQUENT_CHECK; 4200 EV_FREQUENT_CHECK;
4177} 4201}
4178 4202
4179void 4203void
4180ev_fork_stop (EV_P_ ev_fork *w) 4204ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4181{ 4205{
4182 clear_pending (EV_A_ (W)w); 4206 clear_pending (EV_A_ (W)w);
4183 if (expect_false (!ev_is_active (w))) 4207 if (expect_false (!ev_is_active (w)))
4184 return; 4208 return;
4185 4209
4198} 4222}
4199#endif 4223#endif
4200 4224
4201#if EV_CLEANUP_ENABLE 4225#if EV_CLEANUP_ENABLE
4202void 4226void
4203ev_cleanup_start (EV_P_ ev_cleanup *w) 4227ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4204{ 4228{
4205 if (expect_false (ev_is_active (w))) 4229 if (expect_false (ev_is_active (w)))
4206 return; 4230 return;
4207 4231
4208 EV_FREQUENT_CHECK; 4232 EV_FREQUENT_CHECK;
4215 ev_unref (EV_A); 4239 ev_unref (EV_A);
4216 EV_FREQUENT_CHECK; 4240 EV_FREQUENT_CHECK;
4217} 4241}
4218 4242
4219void 4243void
4220ev_cleanup_stop (EV_P_ ev_cleanup *w) 4244ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4221{ 4245{
4222 clear_pending (EV_A_ (W)w); 4246 clear_pending (EV_A_ (W)w);
4223 if (expect_false (!ev_is_active (w))) 4247 if (expect_false (!ev_is_active (w)))
4224 return; 4248 return;
4225 4249
4239} 4263}
4240#endif 4264#endif
4241 4265
4242#if EV_ASYNC_ENABLE 4266#if EV_ASYNC_ENABLE
4243void 4267void
4244ev_async_start (EV_P_ ev_async *w) 4268ev_async_start (EV_P_ ev_async *w) EV_THROW
4245{ 4269{
4246 if (expect_false (ev_is_active (w))) 4270 if (expect_false (ev_is_active (w)))
4247 return; 4271 return;
4248 4272
4249 w->sent = 0; 4273 w->sent = 0;
4258 4282
4259 EV_FREQUENT_CHECK; 4283 EV_FREQUENT_CHECK;
4260} 4284}
4261 4285
4262void 4286void
4263ev_async_stop (EV_P_ ev_async *w) 4287ev_async_stop (EV_P_ ev_async *w) EV_THROW
4264{ 4288{
4265 clear_pending (EV_A_ (W)w); 4289 clear_pending (EV_A_ (W)w);
4266 if (expect_false (!ev_is_active (w))) 4290 if (expect_false (!ev_is_active (w)))
4267 return; 4291 return;
4268 4292
4279 4303
4280 EV_FREQUENT_CHECK; 4304 EV_FREQUENT_CHECK;
4281} 4305}
4282 4306
4283void 4307void
4284ev_async_send (EV_P_ ev_async *w) 4308ev_async_send (EV_P_ ev_async *w) EV_THROW
4285{ 4309{
4286 w->sent = 1; 4310 w->sent = 1;
4287 evpipe_write (EV_A_ &async_pending); 4311 evpipe_write (EV_A_ &async_pending);
4288} 4312}
4289#endif 4313#endif
4326 4350
4327 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4351 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4328} 4352}
4329 4353
4330void 4354void
4331ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4355ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4332{ 4356{
4333 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4357 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4334 4358
4335 if (expect_false (!once)) 4359 if (expect_false (!once))
4336 { 4360 {
4358 4382
4359/*****************************************************************************/ 4383/*****************************************************************************/
4360 4384
4361#if EV_WALK_ENABLE 4385#if EV_WALK_ENABLE
4362void ecb_cold 4386void ecb_cold
4363ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4387ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4364{ 4388{
4365 int i, j; 4389 int i, j;
4366 ev_watcher_list *wl, *wn; 4390 ev_watcher_list *wl, *wn;
4367 4391
4368 if (types & (EV_IO | EV_EMBED)) 4392 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines