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.423 by root, Sun Apr 22 10:14:20 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
1871 /* win32 people keep sending patches that change this write() to send() */ 1877 /* 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 */ 1878 /* 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 */ 1879 /* 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 */ 1880 /* where your send() is from - it's definitely not the microsoft send, and */
1875 /* tell me. thank you. */ 1881 /* tell me. thank you. */
1882 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */
1883 /* check the ev documentation on how to use this flag */
1876 write (evpipe [1], &(evpipe [1]), 1); 1884 write (evpipe [1], &(evpipe [1]), 1);
1877 } 1885 }
1878 1886
1879 errno = old_errno; 1887 errno = old_errno;
1880 } 1888 }
1933} 1941}
1934 1942
1935/*****************************************************************************/ 1943/*****************************************************************************/
1936 1944
1937void 1945void
1938ev_feed_signal (int signum) 1946ev_feed_signal (int signum) EV_THROW
1939{ 1947{
1940#if EV_MULTIPLICITY 1948#if EV_MULTIPLICITY
1941 EV_P = signals [signum - 1].loop; 1949 EV_P = signals [signum - 1].loop;
1942 1950
1943 if (!EV_A) 1951 if (!EV_A)
1960 1968
1961 ev_feed_signal (signum); 1969 ev_feed_signal (signum);
1962} 1970}
1963 1971
1964void noinline 1972void noinline
1965ev_feed_signal_event (EV_P_ int signum) 1973ev_feed_signal_event (EV_P_ int signum) EV_THROW
1966{ 1974{
1967 WL w; 1975 WL w;
1968 1976
1969 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1977 if (expect_false (signum <= 0 || signum > EV_NSIG))
1970 return; 1978 return;
2086#if EV_USE_SELECT 2094#if EV_USE_SELECT
2087# include "ev_select.c" 2095# include "ev_select.c"
2088#endif 2096#endif
2089 2097
2090int ecb_cold 2098int ecb_cold
2091ev_version_major (void) 2099ev_version_major (void) EV_THROW
2092{ 2100{
2093 return EV_VERSION_MAJOR; 2101 return EV_VERSION_MAJOR;
2094} 2102}
2095 2103
2096int ecb_cold 2104int ecb_cold
2097ev_version_minor (void) 2105ev_version_minor (void) EV_THROW
2098{ 2106{
2099 return EV_VERSION_MINOR; 2107 return EV_VERSION_MINOR;
2100} 2108}
2101 2109
2102/* return true if we are running with elevated privileges and should ignore env variables */ 2110/* return true if we are running with elevated privileges and should ignore env variables */
2110 || getgid () != getegid (); 2118 || getgid () != getegid ();
2111#endif 2119#endif
2112} 2120}
2113 2121
2114unsigned int ecb_cold 2122unsigned int ecb_cold
2115ev_supported_backends (void) 2123ev_supported_backends (void) EV_THROW
2116{ 2124{
2117 unsigned int flags = 0; 2125 unsigned int flags = 0;
2118 2126
2119 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2127 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2120 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2128 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2124 2132
2125 return flags; 2133 return flags;
2126} 2134}
2127 2135
2128unsigned int ecb_cold 2136unsigned int ecb_cold
2129ev_recommended_backends (void) 2137ev_recommended_backends (void) EV_THROW
2130{ 2138{
2131 unsigned int flags = ev_supported_backends (); 2139 unsigned int flags = ev_supported_backends ();
2132 2140
2133#ifndef __NetBSD__ 2141#ifndef __NetBSD__
2134 /* kqueue is borked on everything but netbsd apparently */ 2142 /* kqueue is borked on everything but netbsd apparently */
2146 2154
2147 return flags; 2155 return flags;
2148} 2156}
2149 2157
2150unsigned int ecb_cold 2158unsigned int ecb_cold
2151ev_embeddable_backends (void) 2159ev_embeddable_backends (void) EV_THROW
2152{ 2160{
2153 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2161 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2154 2162
2155 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2163 /* 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 */ 2164 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2158 2166
2159 return flags; 2167 return flags;
2160} 2168}
2161 2169
2162unsigned int 2170unsigned int
2163ev_backend (EV_P) 2171ev_backend (EV_P) EV_THROW
2164{ 2172{
2165 return backend; 2173 return backend;
2166} 2174}
2167 2175
2168#if EV_FEATURE_API 2176#if EV_FEATURE_API
2169unsigned int 2177unsigned int
2170ev_iteration (EV_P) 2178ev_iteration (EV_P) EV_THROW
2171{ 2179{
2172 return loop_count; 2180 return loop_count;
2173} 2181}
2174 2182
2175unsigned int 2183unsigned int
2176ev_depth (EV_P) 2184ev_depth (EV_P) EV_THROW
2177{ 2185{
2178 return loop_depth; 2186 return loop_depth;
2179} 2187}
2180 2188
2181void 2189void
2182ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2190ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2183{ 2191{
2184 io_blocktime = interval; 2192 io_blocktime = interval;
2185} 2193}
2186 2194
2187void 2195void
2188ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2196ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2189{ 2197{
2190 timeout_blocktime = interval; 2198 timeout_blocktime = interval;
2191} 2199}
2192 2200
2193void 2201void
2194ev_set_userdata (EV_P_ void *data) 2202ev_set_userdata (EV_P_ void *data) EV_THROW
2195{ 2203{
2196 userdata = data; 2204 userdata = data;
2197} 2205}
2198 2206
2199void * 2207void *
2200ev_userdata (EV_P) 2208ev_userdata (EV_P) EV_THROW
2201{ 2209{
2202 return userdata; 2210 return userdata;
2203} 2211}
2204 2212
2205void 2213void
2206ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 2214ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW
2207{ 2215{
2208 invoke_cb = invoke_pending_cb; 2216 invoke_cb = invoke_pending_cb;
2209} 2217}
2210 2218
2211void 2219void
2212ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 2220ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW
2213{ 2221{
2214 release_cb = release; 2222 release_cb = release;
2215 acquire_cb = acquire; 2223 acquire_cb = acquire;
2216} 2224}
2217#endif 2225#endif
2218 2226
2219/* initialise a loop structure, must be zero-initialised */ 2227/* initialise a loop structure, must be zero-initialised */
2220static void noinline ecb_cold 2228static void noinline ecb_cold
2221loop_init (EV_P_ unsigned int flags) 2229loop_init (EV_P_ unsigned int flags) EV_THROW
2222{ 2230{
2223 if (!backend) 2231 if (!backend)
2224 { 2232 {
2225 origflags = flags; 2233 origflags = flags;
2226 2234
2479} 2487}
2480 2488
2481#if EV_MULTIPLICITY 2489#if EV_MULTIPLICITY
2482 2490
2483struct ev_loop * ecb_cold 2491struct ev_loop * ecb_cold
2484ev_loop_new (unsigned int flags) 2492ev_loop_new (unsigned int flags) EV_THROW
2485{ 2493{
2486 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2494 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2487 2495
2488 memset (EV_A, 0, sizeof (struct ev_loop)); 2496 memset (EV_A, 0, sizeof (struct ev_loop));
2489 loop_init (EV_A_ flags); 2497 loop_init (EV_A_ flags);
2533} 2541}
2534#endif 2542#endif
2535 2543
2536#if EV_FEATURE_API 2544#if EV_FEATURE_API
2537void ecb_cold 2545void ecb_cold
2538ev_verify (EV_P) 2546ev_verify (EV_P) EV_THROW
2539{ 2547{
2540#if EV_VERIFY 2548#if EV_VERIFY
2541 int i; 2549 int i;
2542 WL w; 2550 WL w;
2543 2551
2612#if EV_MULTIPLICITY 2620#if EV_MULTIPLICITY
2613struct ev_loop * ecb_cold 2621struct ev_loop * ecb_cold
2614#else 2622#else
2615int 2623int
2616#endif 2624#endif
2617ev_default_loop (unsigned int flags) 2625ev_default_loop (unsigned int flags) EV_THROW
2618{ 2626{
2619 if (!ev_default_loop_ptr) 2627 if (!ev_default_loop_ptr)
2620 { 2628 {
2621#if EV_MULTIPLICITY 2629#if EV_MULTIPLICITY
2622 EV_P = ev_default_loop_ptr = &default_loop_struct; 2630 EV_P = ev_default_loop_ptr = &default_loop_struct;
2641 2649
2642 return ev_default_loop_ptr; 2650 return ev_default_loop_ptr;
2643} 2651}
2644 2652
2645void 2653void
2646ev_loop_fork (EV_P) 2654ev_loop_fork (EV_P) EV_THROW
2647{ 2655{
2648 postfork = 1; /* must be in line with ev_default_fork */ 2656 postfork = 1; /* must be in line with ev_default_fork */
2649} 2657}
2650 2658
2651/*****************************************************************************/ 2659/*****************************************************************************/
2655{ 2663{
2656 EV_CB_INVOKE ((W)w, revents); 2664 EV_CB_INVOKE ((W)w, revents);
2657} 2665}
2658 2666
2659unsigned int 2667unsigned int
2660ev_pending_count (EV_P) 2668ev_pending_count (EV_P) EV_THROW
2661{ 2669{
2662 int pri; 2670 int pri;
2663 unsigned int count = 0; 2671 unsigned int count = 0;
2664 2672
2665 for (pri = NUMPRI; pri--; ) 2673 for (pri = NUMPRI; pri--; )
2924 2932
2925 mn_now = ev_rt_now; 2933 mn_now = ev_rt_now;
2926 } 2934 }
2927} 2935}
2928 2936
2929void 2937int
2930ev_run (EV_P_ int flags) 2938ev_run (EV_P_ int flags)
2931{ 2939{
2932#if EV_FEATURE_API 2940#if EV_FEATURE_API
2933 ++loop_depth; 2941 ++loop_depth;
2934#endif 2942#endif
3091 loop_done = EVBREAK_CANCEL; 3099 loop_done = EVBREAK_CANCEL;
3092 3100
3093#if EV_FEATURE_API 3101#if EV_FEATURE_API
3094 --loop_depth; 3102 --loop_depth;
3095#endif 3103#endif
3104
3105 return activecnt;
3096} 3106}
3097 3107
3098void 3108void
3099ev_break (EV_P_ int how) 3109ev_break (EV_P_ int how) EV_THROW
3100{ 3110{
3101 loop_done = how; 3111 loop_done = how;
3102} 3112}
3103 3113
3104void 3114void
3105ev_ref (EV_P) 3115ev_ref (EV_P) EV_THROW
3106{ 3116{
3107 ++activecnt; 3117 ++activecnt;
3108} 3118}
3109 3119
3110void 3120void
3111ev_unref (EV_P) 3121ev_unref (EV_P) EV_THROW
3112{ 3122{
3113 --activecnt; 3123 --activecnt;
3114} 3124}
3115 3125
3116void 3126void
3117ev_now_update (EV_P) 3127ev_now_update (EV_P) EV_THROW
3118{ 3128{
3119 time_update (EV_A_ 1e100); 3129 time_update (EV_A_ 1e100);
3120} 3130}
3121 3131
3122void 3132void
3123ev_suspend (EV_P) 3133ev_suspend (EV_P) EV_THROW
3124{ 3134{
3125 ev_now_update (EV_A); 3135 ev_now_update (EV_A);
3126} 3136}
3127 3137
3128void 3138void
3129ev_resume (EV_P) 3139ev_resume (EV_P) EV_THROW
3130{ 3140{
3131 ev_tstamp mn_prev = mn_now; 3141 ev_tstamp mn_prev = mn_now;
3132 3142
3133 ev_now_update (EV_A); 3143 ev_now_update (EV_A);
3134 timers_reschedule (EV_A_ mn_now - mn_prev); 3144 timers_reschedule (EV_A_ mn_now - mn_prev);
3173 w->pending = 0; 3183 w->pending = 0;
3174 } 3184 }
3175} 3185}
3176 3186
3177int 3187int
3178ev_clear_pending (EV_P_ void *w) 3188ev_clear_pending (EV_P_ void *w) EV_THROW
3179{ 3189{
3180 W w_ = (W)w; 3190 W w_ = (W)w;
3181 int pending = w_->pending; 3191 int pending = w_->pending;
3182 3192
3183 if (expect_true (pending)) 3193 if (expect_true (pending))
3216} 3226}
3217 3227
3218/*****************************************************************************/ 3228/*****************************************************************************/
3219 3229
3220void noinline 3230void noinline
3221ev_io_start (EV_P_ ev_io *w) 3231ev_io_start (EV_P_ ev_io *w) EV_THROW
3222{ 3232{
3223 int fd = w->fd; 3233 int fd = w->fd;
3224 3234
3225 if (expect_false (ev_is_active (w))) 3235 if (expect_false (ev_is_active (w)))
3226 return; 3236 return;
3239 3249
3240 EV_FREQUENT_CHECK; 3250 EV_FREQUENT_CHECK;
3241} 3251}
3242 3252
3243void noinline 3253void noinline
3244ev_io_stop (EV_P_ ev_io *w) 3254ev_io_stop (EV_P_ ev_io *w) EV_THROW
3245{ 3255{
3246 clear_pending (EV_A_ (W)w); 3256 clear_pending (EV_A_ (W)w);
3247 if (expect_false (!ev_is_active (w))) 3257 if (expect_false (!ev_is_active (w)))
3248 return; 3258 return;
3249 3259
3258 3268
3259 EV_FREQUENT_CHECK; 3269 EV_FREQUENT_CHECK;
3260} 3270}
3261 3271
3262void noinline 3272void noinline
3263ev_timer_start (EV_P_ ev_timer *w) 3273ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3264{ 3274{
3265 if (expect_false (ev_is_active (w))) 3275 if (expect_false (ev_is_active (w)))
3266 return; 3276 return;
3267 3277
3268 ev_at (w) += mn_now; 3278 ev_at (w) += mn_now;
3282 3292
3283 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3293 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3284} 3294}
3285 3295
3286void noinline 3296void noinline
3287ev_timer_stop (EV_P_ ev_timer *w) 3297ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3288{ 3298{
3289 clear_pending (EV_A_ (W)w); 3299 clear_pending (EV_A_ (W)w);
3290 if (expect_false (!ev_is_active (w))) 3300 if (expect_false (!ev_is_active (w)))
3291 return; 3301 return;
3292 3302
3312 3322
3313 EV_FREQUENT_CHECK; 3323 EV_FREQUENT_CHECK;
3314} 3324}
3315 3325
3316void noinline 3326void noinline
3317ev_timer_again (EV_P_ ev_timer *w) 3327ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3318{ 3328{
3319 EV_FREQUENT_CHECK; 3329 EV_FREQUENT_CHECK;
3320 3330
3321 clear_pending (EV_A_ (W)w); 3331 clear_pending (EV_A_ (W)w);
3322 3332
3339 3349
3340 EV_FREQUENT_CHECK; 3350 EV_FREQUENT_CHECK;
3341} 3351}
3342 3352
3343ev_tstamp 3353ev_tstamp
3344ev_timer_remaining (EV_P_ ev_timer *w) 3354ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3345{ 3355{
3346 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3356 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3347} 3357}
3348 3358
3349#if EV_PERIODIC_ENABLE 3359#if EV_PERIODIC_ENABLE
3350void noinline 3360void noinline
3351ev_periodic_start (EV_P_ ev_periodic *w) 3361ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3352{ 3362{
3353 if (expect_false (ev_is_active (w))) 3363 if (expect_false (ev_is_active (w)))
3354 return; 3364 return;
3355 3365
3356 if (w->reschedule_cb) 3366 if (w->reschedule_cb)
3376 3386
3377 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3387 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3378} 3388}
3379 3389
3380void noinline 3390void noinline
3381ev_periodic_stop (EV_P_ ev_periodic *w) 3391ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3382{ 3392{
3383 clear_pending (EV_A_ (W)w); 3393 clear_pending (EV_A_ (W)w);
3384 if (expect_false (!ev_is_active (w))) 3394 if (expect_false (!ev_is_active (w)))
3385 return; 3395 return;
3386 3396
3404 3414
3405 EV_FREQUENT_CHECK; 3415 EV_FREQUENT_CHECK;
3406} 3416}
3407 3417
3408void noinline 3418void noinline
3409ev_periodic_again (EV_P_ ev_periodic *w) 3419ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3410{ 3420{
3411 /* TODO: use adjustheap and recalculation */ 3421 /* TODO: use adjustheap and recalculation */
3412 ev_periodic_stop (EV_A_ w); 3422 ev_periodic_stop (EV_A_ w);
3413 ev_periodic_start (EV_A_ w); 3423 ev_periodic_start (EV_A_ w);
3414} 3424}
3419#endif 3429#endif
3420 3430
3421#if EV_SIGNAL_ENABLE 3431#if EV_SIGNAL_ENABLE
3422 3432
3423void noinline 3433void noinline
3424ev_signal_start (EV_P_ ev_signal *w) 3434ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3425{ 3435{
3426 if (expect_false (ev_is_active (w))) 3436 if (expect_false (ev_is_active (w)))
3427 return; 3437 return;
3428 3438
3429 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3439 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3500 3510
3501 EV_FREQUENT_CHECK; 3511 EV_FREQUENT_CHECK;
3502} 3512}
3503 3513
3504void noinline 3514void noinline
3505ev_signal_stop (EV_P_ ev_signal *w) 3515ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3506{ 3516{
3507 clear_pending (EV_A_ (W)w); 3517 clear_pending (EV_A_ (W)w);
3508 if (expect_false (!ev_is_active (w))) 3518 if (expect_false (!ev_is_active (w)))
3509 return; 3519 return;
3510 3520
3541#endif 3551#endif
3542 3552
3543#if EV_CHILD_ENABLE 3553#if EV_CHILD_ENABLE
3544 3554
3545void 3555void
3546ev_child_start (EV_P_ ev_child *w) 3556ev_child_start (EV_P_ ev_child *w) EV_THROW
3547{ 3557{
3548#if EV_MULTIPLICITY 3558#if EV_MULTIPLICITY
3549 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3559 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3550#endif 3560#endif
3551 if (expect_false (ev_is_active (w))) 3561 if (expect_false (ev_is_active (w)))
3558 3568
3559 EV_FREQUENT_CHECK; 3569 EV_FREQUENT_CHECK;
3560} 3570}
3561 3571
3562void 3572void
3563ev_child_stop (EV_P_ ev_child *w) 3573ev_child_stop (EV_P_ ev_child *w) EV_THROW
3564{ 3574{
3565 clear_pending (EV_A_ (W)w); 3575 clear_pending (EV_A_ (W)w);
3566 if (expect_false (!ev_is_active (w))) 3576 if (expect_false (!ev_is_active (w)))
3567 return; 3577 return;
3568 3578
3735} 3745}
3736 3746
3737inline_size int 3747inline_size int
3738infy_newfd (void) 3748infy_newfd (void)
3739{ 3749{
3740#if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) 3750#if defined IN_CLOEXEC && defined IN_NONBLOCK
3741 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); 3751 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK);
3742 if (fd >= 0) 3752 if (fd >= 0)
3743 return fd; 3753 return fd;
3744#endif 3754#endif
3745 return inotify_init (); 3755 return inotify_init ();
3820#else 3830#else
3821# define EV_LSTAT(p,b) lstat (p, b) 3831# define EV_LSTAT(p,b) lstat (p, b)
3822#endif 3832#endif
3823 3833
3824void 3834void
3825ev_stat_stat (EV_P_ ev_stat *w) 3835ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3826{ 3836{
3827 if (lstat (w->path, &w->attr) < 0) 3837 if (lstat (w->path, &w->attr) < 0)
3828 w->attr.st_nlink = 0; 3838 w->attr.st_nlink = 0;
3829 else if (!w->attr.st_nlink) 3839 else if (!w->attr.st_nlink)
3830 w->attr.st_nlink = 1; 3840 w->attr.st_nlink = 1;
3869 ev_feed_event (EV_A_ w, EV_STAT); 3879 ev_feed_event (EV_A_ w, EV_STAT);
3870 } 3880 }
3871} 3881}
3872 3882
3873void 3883void
3874ev_stat_start (EV_P_ ev_stat *w) 3884ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3875{ 3885{
3876 if (expect_false (ev_is_active (w))) 3886 if (expect_false (ev_is_active (w)))
3877 return; 3887 return;
3878 3888
3879 ev_stat_stat (EV_A_ w); 3889 ev_stat_stat (EV_A_ w);
3900 3910
3901 EV_FREQUENT_CHECK; 3911 EV_FREQUENT_CHECK;
3902} 3912}
3903 3913
3904void 3914void
3905ev_stat_stop (EV_P_ ev_stat *w) 3915ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3906{ 3916{
3907 clear_pending (EV_A_ (W)w); 3917 clear_pending (EV_A_ (W)w);
3908 if (expect_false (!ev_is_active (w))) 3918 if (expect_false (!ev_is_active (w)))
3909 return; 3919 return;
3910 3920
3926} 3936}
3927#endif 3937#endif
3928 3938
3929#if EV_IDLE_ENABLE 3939#if EV_IDLE_ENABLE
3930void 3940void
3931ev_idle_start (EV_P_ ev_idle *w) 3941ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3932{ 3942{
3933 if (expect_false (ev_is_active (w))) 3943 if (expect_false (ev_is_active (w)))
3934 return; 3944 return;
3935 3945
3936 pri_adjust (EV_A_ (W)w); 3946 pri_adjust (EV_A_ (W)w);
3949 3959
3950 EV_FREQUENT_CHECK; 3960 EV_FREQUENT_CHECK;
3951} 3961}
3952 3962
3953void 3963void
3954ev_idle_stop (EV_P_ ev_idle *w) 3964ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3955{ 3965{
3956 clear_pending (EV_A_ (W)w); 3966 clear_pending (EV_A_ (W)w);
3957 if (expect_false (!ev_is_active (w))) 3967 if (expect_false (!ev_is_active (w)))
3958 return; 3968 return;
3959 3969
3973} 3983}
3974#endif 3984#endif
3975 3985
3976#if EV_PREPARE_ENABLE 3986#if EV_PREPARE_ENABLE
3977void 3987void
3978ev_prepare_start (EV_P_ ev_prepare *w) 3988ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3979{ 3989{
3980 if (expect_false (ev_is_active (w))) 3990 if (expect_false (ev_is_active (w)))
3981 return; 3991 return;
3982 3992
3983 EV_FREQUENT_CHECK; 3993 EV_FREQUENT_CHECK;
3988 3998
3989 EV_FREQUENT_CHECK; 3999 EV_FREQUENT_CHECK;
3990} 4000}
3991 4001
3992void 4002void
3993ev_prepare_stop (EV_P_ ev_prepare *w) 4003ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
3994{ 4004{
3995 clear_pending (EV_A_ (W)w); 4005 clear_pending (EV_A_ (W)w);
3996 if (expect_false (!ev_is_active (w))) 4006 if (expect_false (!ev_is_active (w)))
3997 return; 4007 return;
3998 4008
4011} 4021}
4012#endif 4022#endif
4013 4023
4014#if EV_CHECK_ENABLE 4024#if EV_CHECK_ENABLE
4015void 4025void
4016ev_check_start (EV_P_ ev_check *w) 4026ev_check_start (EV_P_ ev_check *w) EV_THROW
4017{ 4027{
4018 if (expect_false (ev_is_active (w))) 4028 if (expect_false (ev_is_active (w)))
4019 return; 4029 return;
4020 4030
4021 EV_FREQUENT_CHECK; 4031 EV_FREQUENT_CHECK;
4026 4036
4027 EV_FREQUENT_CHECK; 4037 EV_FREQUENT_CHECK;
4028} 4038}
4029 4039
4030void 4040void
4031ev_check_stop (EV_P_ ev_check *w) 4041ev_check_stop (EV_P_ ev_check *w) EV_THROW
4032{ 4042{
4033 clear_pending (EV_A_ (W)w); 4043 clear_pending (EV_A_ (W)w);
4034 if (expect_false (!ev_is_active (w))) 4044 if (expect_false (!ev_is_active (w)))
4035 return; 4045 return;
4036 4046
4049} 4059}
4050#endif 4060#endif
4051 4061
4052#if EV_EMBED_ENABLE 4062#if EV_EMBED_ENABLE
4053void noinline 4063void noinline
4054ev_embed_sweep (EV_P_ ev_embed *w) 4064ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4055{ 4065{
4056 ev_run (w->other, EVRUN_NOWAIT); 4066 ev_run (w->other, EVRUN_NOWAIT);
4057} 4067}
4058 4068
4059static void 4069static void
4107 ev_idle_stop (EV_A_ idle); 4117 ev_idle_stop (EV_A_ idle);
4108} 4118}
4109#endif 4119#endif
4110 4120
4111void 4121void
4112ev_embed_start (EV_P_ ev_embed *w) 4122ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4113{ 4123{
4114 if (expect_false (ev_is_active (w))) 4124 if (expect_false (ev_is_active (w)))
4115 return; 4125 return;
4116 4126
4117 { 4127 {
4138 4148
4139 EV_FREQUENT_CHECK; 4149 EV_FREQUENT_CHECK;
4140} 4150}
4141 4151
4142void 4152void
4143ev_embed_stop (EV_P_ ev_embed *w) 4153ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4144{ 4154{
4145 clear_pending (EV_A_ (W)w); 4155 clear_pending (EV_A_ (W)w);
4146 if (expect_false (!ev_is_active (w))) 4156 if (expect_false (!ev_is_active (w)))
4147 return; 4157 return;
4148 4158
4158} 4168}
4159#endif 4169#endif
4160 4170
4161#if EV_FORK_ENABLE 4171#if EV_FORK_ENABLE
4162void 4172void
4163ev_fork_start (EV_P_ ev_fork *w) 4173ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4164{ 4174{
4165 if (expect_false (ev_is_active (w))) 4175 if (expect_false (ev_is_active (w)))
4166 return; 4176 return;
4167 4177
4168 EV_FREQUENT_CHECK; 4178 EV_FREQUENT_CHECK;
4173 4183
4174 EV_FREQUENT_CHECK; 4184 EV_FREQUENT_CHECK;
4175} 4185}
4176 4186
4177void 4187void
4178ev_fork_stop (EV_P_ ev_fork *w) 4188ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4179{ 4189{
4180 clear_pending (EV_A_ (W)w); 4190 clear_pending (EV_A_ (W)w);
4181 if (expect_false (!ev_is_active (w))) 4191 if (expect_false (!ev_is_active (w)))
4182 return; 4192 return;
4183 4193
4196} 4206}
4197#endif 4207#endif
4198 4208
4199#if EV_CLEANUP_ENABLE 4209#if EV_CLEANUP_ENABLE
4200void 4210void
4201ev_cleanup_start (EV_P_ ev_cleanup *w) 4211ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4202{ 4212{
4203 if (expect_false (ev_is_active (w))) 4213 if (expect_false (ev_is_active (w)))
4204 return; 4214 return;
4205 4215
4206 EV_FREQUENT_CHECK; 4216 EV_FREQUENT_CHECK;
4213 ev_unref (EV_A); 4223 ev_unref (EV_A);
4214 EV_FREQUENT_CHECK; 4224 EV_FREQUENT_CHECK;
4215} 4225}
4216 4226
4217void 4227void
4218ev_cleanup_stop (EV_P_ ev_cleanup *w) 4228ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4219{ 4229{
4220 clear_pending (EV_A_ (W)w); 4230 clear_pending (EV_A_ (W)w);
4221 if (expect_false (!ev_is_active (w))) 4231 if (expect_false (!ev_is_active (w)))
4222 return; 4232 return;
4223 4233
4237} 4247}
4238#endif 4248#endif
4239 4249
4240#if EV_ASYNC_ENABLE 4250#if EV_ASYNC_ENABLE
4241void 4251void
4242ev_async_start (EV_P_ ev_async *w) 4252ev_async_start (EV_P_ ev_async *w) EV_THROW
4243{ 4253{
4244 if (expect_false (ev_is_active (w))) 4254 if (expect_false (ev_is_active (w)))
4245 return; 4255 return;
4246 4256
4247 w->sent = 0; 4257 w->sent = 0;
4256 4266
4257 EV_FREQUENT_CHECK; 4267 EV_FREQUENT_CHECK;
4258} 4268}
4259 4269
4260void 4270void
4261ev_async_stop (EV_P_ ev_async *w) 4271ev_async_stop (EV_P_ ev_async *w) EV_THROW
4262{ 4272{
4263 clear_pending (EV_A_ (W)w); 4273 clear_pending (EV_A_ (W)w);
4264 if (expect_false (!ev_is_active (w))) 4274 if (expect_false (!ev_is_active (w)))
4265 return; 4275 return;
4266 4276
4277 4287
4278 EV_FREQUENT_CHECK; 4288 EV_FREQUENT_CHECK;
4279} 4289}
4280 4290
4281void 4291void
4282ev_async_send (EV_P_ ev_async *w) 4292ev_async_send (EV_P_ ev_async *w) EV_THROW
4283{ 4293{
4284 w->sent = 1; 4294 w->sent = 1;
4285 evpipe_write (EV_A_ &async_pending); 4295 evpipe_write (EV_A_ &async_pending);
4286} 4296}
4287#endif 4297#endif
4324 4334
4325 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4335 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4326} 4336}
4327 4337
4328void 4338void
4329ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4339ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4330{ 4340{
4331 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4341 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4332 4342
4333 if (expect_false (!once)) 4343 if (expect_false (!once))
4334 { 4344 {
4356 4366
4357/*****************************************************************************/ 4367/*****************************************************************************/
4358 4368
4359#if EV_WALK_ENABLE 4369#if EV_WALK_ENABLE
4360void ecb_cold 4370void ecb_cold
4361ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4371ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4362{ 4372{
4363 int i, j; 4373 int i, j;
4364 ev_watcher_list *wl, *wn; 4374 ev_watcher_list *wl, *wn;
4365 4375
4366 if (types & (EV_IO | EV_EMBED)) 4376 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines