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

Comparing libev/ev.c (file contents):
Revision 1.416 by root, Mon Apr 2 20:12:16 2012 UTC vs.
Revision 1.433 by root, Tue May 15 13:03: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 *
201# include <sys/wait.h> 201# include <sys/wait.h>
202# include <unistd.h> 202# include <unistd.h>
203#else 203#else
204# include <io.h> 204# include <io.h>
205# define WIN32_LEAN_AND_MEAN 205# define WIN32_LEAN_AND_MEAN
206# include <winsock2.h>
206# include <windows.h> 207# include <windows.h>
207# ifndef EV_SELECT_IS_WINSOCKET 208# ifndef EV_SELECT_IS_WINSOCKET
208# define EV_SELECT_IS_WINSOCKET 1 209# define EV_SELECT_IS_WINSOCKET 1
209# endif 210# endif
210# undef EV_AVOID_STDIO 211# undef EV_AVOID_STDIO
359#endif 360#endif
360 361
361/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 362/* 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. */ 363/* which makes programs even slower. might work on other unices, too. */
363#if EV_USE_CLOCK_SYSCALL 364#if EV_USE_CLOCK_SYSCALL
364# include <syscall.h> 365# include <sys/syscall.h>
365# ifdef SYS_clock_gettime 366# ifdef SYS_clock_gettime
366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 367# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
367# undef EV_USE_MONOTONIC 368# undef EV_USE_MONOTONIC
368# define EV_USE_MONOTONIC 1 369# define EV_USE_MONOTONIC 1
369# else 370# else
408/* some very old inotify.h headers don't have IN_DONT_FOLLOW */ 409/* some very old inotify.h headers don't have IN_DONT_FOLLOW */
409# ifndef IN_DONT_FOLLOW 410# ifndef IN_DONT_FOLLOW
410# undef EV_USE_INOTIFY 411# undef EV_USE_INOTIFY
411# define EV_USE_INOTIFY 0 412# define EV_USE_INOTIFY 0
412# endif 413# endif
413#endif
414
415#if EV_SELECT_IS_WINSOCKET
416# include <winsock.h>
417#endif 414#endif
418 415
419#if EV_USE_EVENTFD 416#if EV_USE_EVENTFD
420/* our minimum requirement is glibc 2.7 which has the stub, but not the header */ 417/* our minimum requirement is glibc 2.7 which has the stub, but not the header */
421# include <stdint.h> 418# include <stdint.h>
533 * or so. 530 * or so.
534 * we try to detect these and simply assume they are not gcc - if they have 531 * 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. 532 * an issue with that they should have done it right in the first place.
536 */ 533 */
537#ifndef ECB_GCC_VERSION 534#ifndef ECB_GCC_VERSION
538 #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) 535 #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 536 #define ECB_GCC_VERSION(major,minor) 0
540 #else 537 #else
541 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 538 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
542 #endif 539 #endif
543#endif 540#endif
554#if ECB_NO_THREADS || ECB_NO_SMP 551#if ECB_NO_THREADS || ECB_NO_SMP
555 #define ECB_MEMORY_FENCE do { } while (0) 552 #define ECB_MEMORY_FENCE do { } while (0)
556#endif 553#endif
557 554
558#ifndef ECB_MEMORY_FENCE 555#ifndef ECB_MEMORY_FENCE
559 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 556 #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
560 #if __i386 || __i386__ 557 #if __i386 || __i386__
561 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 558 #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 */ 559 #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 */ 560 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 561 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 562 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 563 #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 */ 564 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 565 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 566 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
570 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 567 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
571 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 568 || 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") 569 #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__ ) \ 570 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
574 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 571 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 572 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
576 #elif __sparc || __sparc__ 573 #elif __sparc || __sparc__
577 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") 574 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory")
578 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 575 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 576 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
580 #elif defined(__s390__) || defined(__s390x__) 577 #elif defined __s390__ || defined __s390x__
581 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 578 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
582 #elif defined(__mips__) 579 #elif defined __mips__
583 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 580 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
581 #elif defined __alpha__
582 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
584 #endif 583 #endif
585 #endif 584 #endif
586#endif 585#endif
587 586
588#ifndef ECB_MEMORY_FENCE 587#ifndef ECB_MEMORY_FENCE
589 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) 588 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
590 #define ECB_MEMORY_FENCE __sync_synchronize () 589 #define ECB_MEMORY_FENCE __sync_synchronize ()
591 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ 590 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */
592 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ 591 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
593 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 592 #elif _MSC_VER >= 1400 /* VC++ 2005 */
594 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 593 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
595 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 594 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
596 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ 595 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
597 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 596 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
598 #elif defined(_WIN32) 597 #elif defined _WIN32
599 #include <WinNT.h> 598 #include <WinNT.h>
600 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 599 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
601 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 600 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
602 #include <mbarrier.h> 601 #include <mbarrier.h>
603 #define ECB_MEMORY_FENCE __machine_rw_barrier () 602 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
624 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; 623 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
625 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) 624 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
626 #endif 625 #endif
627#endif 626#endif
628 627
629#if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) 628#if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE
630 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 629 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
631#endif 630#endif
632 631
633#if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) 632#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
634 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 633 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
635#endif 634#endif
636 635
637/*****************************************************************************/ 636/*****************************************************************************/
638 637
1103{ 1102{
1104 write (STDERR_FILENO, msg, strlen (msg)); 1103 write (STDERR_FILENO, msg, strlen (msg));
1105} 1104}
1106#endif 1105#endif
1107 1106
1108static void (*syserr_cb)(const char *msg); 1107static void (*syserr_cb)(const char *msg) EV_THROW;
1109 1108
1110void ecb_cold 1109void ecb_cold
1111ev_set_syserr_cb (void (*cb)(const char *msg)) 1110ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW
1112{ 1111{
1113 syserr_cb = cb; 1112 syserr_cb = cb;
1114} 1113}
1115 1114
1116static void noinline ecb_cold 1115static void noinline ecb_cold
1152 free (ptr); 1151 free (ptr);
1153 return 0; 1152 return 0;
1154#endif 1153#endif
1155} 1154}
1156 1155
1157static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 1156static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1158 1157
1159void ecb_cold 1158void ecb_cold
1160ev_set_allocator (void *(*cb)(void *ptr, long size)) 1159ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW
1161{ 1160{
1162 alloc = cb; 1161 alloc = cb;
1163} 1162}
1164 1163
1165inline_speed void * 1164inline_speed void *
1282 1281
1283/*****************************************************************************/ 1282/*****************************************************************************/
1284 1283
1285#ifndef EV_HAVE_EV_TIME 1284#ifndef EV_HAVE_EV_TIME
1286ev_tstamp 1285ev_tstamp
1287ev_time (void) 1286ev_time (void) EV_THROW
1288{ 1287{
1289#if EV_USE_REALTIME 1288#if EV_USE_REALTIME
1290 if (expect_true (have_realtime)) 1289 if (expect_true (have_realtime))
1291 { 1290 {
1292 struct timespec ts; 1291 struct timespec ts;
1316 return ev_time (); 1315 return ev_time ();
1317} 1316}
1318 1317
1319#if EV_MULTIPLICITY 1318#if EV_MULTIPLICITY
1320ev_tstamp 1319ev_tstamp
1321ev_now (EV_P) 1320ev_now (EV_P) EV_THROW
1322{ 1321{
1323 return ev_rt_now; 1322 return ev_rt_now;
1324} 1323}
1325#endif 1324#endif
1326 1325
1327void 1326void
1328ev_sleep (ev_tstamp delay) 1327ev_sleep (ev_tstamp delay) EV_THROW
1329{ 1328{
1330 if (delay > 0.) 1329 if (delay > 0.)
1331 { 1330 {
1332#if EV_USE_NANOSLEEP 1331#if EV_USE_NANOSLEEP
1333 struct timespec ts; 1332 struct timespec ts;
1414pendingcb (EV_P_ ev_prepare *w, int revents) 1413pendingcb (EV_P_ ev_prepare *w, int revents)
1415{ 1414{
1416} 1415}
1417 1416
1418void noinline 1417void noinline
1419ev_feed_event (EV_P_ void *w, int revents) 1418ev_feed_event (EV_P_ void *w, int revents) EV_THROW
1420{ 1419{
1421 W w_ = (W)w; 1420 W w_ = (W)w;
1422 int pri = ABSPRI (w_); 1421 int pri = ABSPRI (w_);
1423 1422
1424 if (expect_false (w_->pending)) 1423 if (expect_false (w_->pending))
1428 w_->pending = ++pendingcnt [pri]; 1427 w_->pending = ++pendingcnt [pri];
1429 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 1428 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2);
1430 pendings [pri][w_->pending - 1].w = w_; 1429 pendings [pri][w_->pending - 1].w = w_;
1431 pendings [pri][w_->pending - 1].events = revents; 1430 pendings [pri][w_->pending - 1].events = revents;
1432 } 1431 }
1432
1433 pendingpri = NUMPRI - 1;
1433} 1434}
1434 1435
1435inline_speed void 1436inline_speed void
1436feed_reverse (EV_P_ W w) 1437feed_reverse (EV_P_ W w)
1437{ 1438{
1483 if (expect_true (!anfd->reify)) 1484 if (expect_true (!anfd->reify))
1484 fd_event_nocheck (EV_A_ fd, revents); 1485 fd_event_nocheck (EV_A_ fd, revents);
1485} 1486}
1486 1487
1487void 1488void
1488ev_feed_fd_event (EV_P_ int fd, int revents) 1489ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1489{ 1490{
1490 if (fd >= 0 && fd < anfdmax) 1491 if (fd >= 0 && fd < anfdmax)
1491 fd_event_nocheck (EV_A_ fd, revents); 1492 fd_event_nocheck (EV_A_ fd, revents);
1492} 1493}
1493 1494
1842} 1843}
1843 1844
1844inline_speed void 1845inline_speed void
1845evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1846evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1846{ 1847{
1848 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1849
1847 if (expect_true (*flag)) 1850 if (expect_true (*flag))
1848 return; 1851 return;
1849 1852
1850 *flag = 1; 1853 *flag = 1;
1851 1854
1870 write (evfd, &counter, sizeof (uint64_t)); 1873 write (evfd, &counter, sizeof (uint64_t));
1871 } 1874 }
1872 else 1875 else
1873#endif 1876#endif
1874 { 1877 {
1875 /* win32 people keep sending patches that change this write() to send() */ 1878#ifdef _WIN32
1876 /* and then run away. but send() is wrong, it wants a socket handle on win32 */ 1879 WSABUF buf;
1877 /* so when you think this write should be a send instead, please find out */ 1880 DWORD sent;
1878 /* where your send() is from - it's definitely not the microsoft send, and */ 1881 buf.buf = &buf;
1879 /* tell me. thank you. */ 1882 buf.len = 1;
1880 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ 1883 WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0);
1881 /* check the ev documentation on how to use this flag */ 1884#else
1882 write (evpipe [1], &(evpipe [1]), 1); 1885 write (evpipe [1], &(evpipe [1]), 1);
1886#endif
1883 } 1887 }
1884 1888
1885 errno = old_errno; 1889 errno = old_errno;
1886 } 1890 }
1887} 1891}
1902 read (evfd, &counter, sizeof (uint64_t)); 1906 read (evfd, &counter, sizeof (uint64_t));
1903 } 1907 }
1904 else 1908 else
1905#endif 1909#endif
1906 { 1910 {
1907 char dummy; 1911 char dummy[4];
1908 /* see discussion in evpipe_write when you think this read should be recv in win32 */ 1912#ifdef _WIN32
1913 WSABUF buf;
1914 DWORD recvd;
1915 DWORD flags = 0;
1916 buf.buf = dummy;
1917 buf.len = sizeof (dummy);
1918 WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0);
1919#else
1909 read (evpipe [0], &dummy, 1); 1920 read (evpipe [0], &dummy, sizeof (dummy));
1921#endif
1910 } 1922 }
1911 } 1923 }
1912 1924
1913 pipe_write_skipped = 0; 1925 pipe_write_skipped = 0;
1926
1927 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1914 1928
1915#if EV_SIGNAL_ENABLE 1929#if EV_SIGNAL_ENABLE
1916 if (sig_pending) 1930 if (sig_pending)
1917 { 1931 {
1918 sig_pending = 0; 1932 sig_pending = 0;
1933
1934 ECB_MEMORY_FENCE_RELEASE;
1919 1935
1920 for (i = EV_NSIG - 1; i--; ) 1936 for (i = EV_NSIG - 1; i--; )
1921 if (expect_false (signals [i].pending)) 1937 if (expect_false (signals [i].pending))
1922 ev_feed_signal_event (EV_A_ i + 1); 1938 ev_feed_signal_event (EV_A_ i + 1);
1923 } 1939 }
1925 1941
1926#if EV_ASYNC_ENABLE 1942#if EV_ASYNC_ENABLE
1927 if (async_pending) 1943 if (async_pending)
1928 { 1944 {
1929 async_pending = 0; 1945 async_pending = 0;
1946
1947 ECB_MEMORY_FENCE_RELEASE;
1930 1948
1931 for (i = asynccnt; i--; ) 1949 for (i = asynccnt; i--; )
1932 if (asyncs [i]->sent) 1950 if (asyncs [i]->sent)
1933 { 1951 {
1934 asyncs [i]->sent = 0; 1952 asyncs [i]->sent = 0;
1939} 1957}
1940 1958
1941/*****************************************************************************/ 1959/*****************************************************************************/
1942 1960
1943void 1961void
1944ev_feed_signal (int signum) 1962ev_feed_signal (int signum) EV_THROW
1945{ 1963{
1946#if EV_MULTIPLICITY 1964#if EV_MULTIPLICITY
1947 EV_P = signals [signum - 1].loop; 1965 EV_P = signals [signum - 1].loop;
1948 1966
1949 if (!EV_A) 1967 if (!EV_A)
1966 1984
1967 ev_feed_signal (signum); 1985 ev_feed_signal (signum);
1968} 1986}
1969 1987
1970void noinline 1988void noinline
1971ev_feed_signal_event (EV_P_ int signum) 1989ev_feed_signal_event (EV_P_ int signum) EV_THROW
1972{ 1990{
1973 WL w; 1991 WL w;
1974 1992
1975 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1993 if (expect_false (signum <= 0 || signum > EV_NSIG))
1976 return; 1994 return;
2092#if EV_USE_SELECT 2110#if EV_USE_SELECT
2093# include "ev_select.c" 2111# include "ev_select.c"
2094#endif 2112#endif
2095 2113
2096int ecb_cold 2114int ecb_cold
2097ev_version_major (void) 2115ev_version_major (void) EV_THROW
2098{ 2116{
2099 return EV_VERSION_MAJOR; 2117 return EV_VERSION_MAJOR;
2100} 2118}
2101 2119
2102int ecb_cold 2120int ecb_cold
2103ev_version_minor (void) 2121ev_version_minor (void) EV_THROW
2104{ 2122{
2105 return EV_VERSION_MINOR; 2123 return EV_VERSION_MINOR;
2106} 2124}
2107 2125
2108/* return true if we are running with elevated privileges and should ignore env variables */ 2126/* return true if we are running with elevated privileges and should ignore env variables */
2116 || getgid () != getegid (); 2134 || getgid () != getegid ();
2117#endif 2135#endif
2118} 2136}
2119 2137
2120unsigned int ecb_cold 2138unsigned int ecb_cold
2121ev_supported_backends (void) 2139ev_supported_backends (void) EV_THROW
2122{ 2140{
2123 unsigned int flags = 0; 2141 unsigned int flags = 0;
2124 2142
2125 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2143 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2126 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2144 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2130 2148
2131 return flags; 2149 return flags;
2132} 2150}
2133 2151
2134unsigned int ecb_cold 2152unsigned int ecb_cold
2135ev_recommended_backends (void) 2153ev_recommended_backends (void) EV_THROW
2136{ 2154{
2137 unsigned int flags = ev_supported_backends (); 2155 unsigned int flags = ev_supported_backends ();
2138 2156
2139#ifndef __NetBSD__ 2157#ifndef __NetBSD__
2140 /* kqueue is borked on everything but netbsd apparently */ 2158 /* kqueue is borked on everything but netbsd apparently */
2152 2170
2153 return flags; 2171 return flags;
2154} 2172}
2155 2173
2156unsigned int ecb_cold 2174unsigned int ecb_cold
2157ev_embeddable_backends (void) 2175ev_embeddable_backends (void) EV_THROW
2158{ 2176{
2159 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2177 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2160 2178
2161 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ 2179 /* epoll embeddability broken on all linux versions up to at least 2.6.23 */
2162 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ 2180 if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */
2164 2182
2165 return flags; 2183 return flags;
2166} 2184}
2167 2185
2168unsigned int 2186unsigned int
2169ev_backend (EV_P) 2187ev_backend (EV_P) EV_THROW
2170{ 2188{
2171 return backend; 2189 return backend;
2172} 2190}
2173 2191
2174#if EV_FEATURE_API 2192#if EV_FEATURE_API
2175unsigned int 2193unsigned int
2176ev_iteration (EV_P) 2194ev_iteration (EV_P) EV_THROW
2177{ 2195{
2178 return loop_count; 2196 return loop_count;
2179} 2197}
2180 2198
2181unsigned int 2199unsigned int
2182ev_depth (EV_P) 2200ev_depth (EV_P) EV_THROW
2183{ 2201{
2184 return loop_depth; 2202 return loop_depth;
2185} 2203}
2186 2204
2187void 2205void
2188ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2206ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2189{ 2207{
2190 io_blocktime = interval; 2208 io_blocktime = interval;
2191} 2209}
2192 2210
2193void 2211void
2194ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2212ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2195{ 2213{
2196 timeout_blocktime = interval; 2214 timeout_blocktime = interval;
2197} 2215}
2198 2216
2199void 2217void
2200ev_set_userdata (EV_P_ void *data) 2218ev_set_userdata (EV_P_ void *data) EV_THROW
2201{ 2219{
2202 userdata = data; 2220 userdata = data;
2203} 2221}
2204 2222
2205void * 2223void *
2206ev_userdata (EV_P) 2224ev_userdata (EV_P) EV_THROW
2207{ 2225{
2208 return userdata; 2226 return userdata;
2209} 2227}
2210 2228
2211void 2229void
2212ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) 2230ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW
2213{ 2231{
2214 invoke_cb = invoke_pending_cb; 2232 invoke_cb = invoke_pending_cb;
2215} 2233}
2216 2234
2217void 2235void
2218ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) 2236ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW
2219{ 2237{
2220 release_cb = release; 2238 release_cb = release;
2221 acquire_cb = acquire; 2239 acquire_cb = acquire;
2222} 2240}
2223#endif 2241#endif
2224 2242
2225/* initialise a loop structure, must be zero-initialised */ 2243/* initialise a loop structure, must be zero-initialised */
2226static void noinline ecb_cold 2244static void noinline ecb_cold
2227loop_init (EV_P_ unsigned int flags) 2245loop_init (EV_P_ unsigned int flags) EV_THROW
2228{ 2246{
2229 if (!backend) 2247 if (!backend)
2230 { 2248 {
2231 origflags = flags; 2249 origflags = flags;
2232 2250
2337 EV_INVOKE_PENDING; 2355 EV_INVOKE_PENDING;
2338 } 2356 }
2339#endif 2357#endif
2340 2358
2341#if EV_CHILD_ENABLE 2359#if EV_CHILD_ENABLE
2342 if (ev_is_active (&childev)) 2360 if (ev_is_default_loop (EV_A) && ev_is_active (&childev))
2343 { 2361 {
2344 ev_ref (EV_A); /* child watcher */ 2362 ev_ref (EV_A); /* child watcher */
2345 ev_signal_stop (EV_A_ &childev); 2363 ev_signal_stop (EV_A_ &childev);
2346 } 2364 }
2347#endif 2365#endif
2485} 2503}
2486 2504
2487#if EV_MULTIPLICITY 2505#if EV_MULTIPLICITY
2488 2506
2489struct ev_loop * ecb_cold 2507struct ev_loop * ecb_cold
2490ev_loop_new (unsigned int flags) 2508ev_loop_new (unsigned int flags) EV_THROW
2491{ 2509{
2492 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2510 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2493 2511
2494 memset (EV_A, 0, sizeof (struct ev_loop)); 2512 memset (EV_A, 0, sizeof (struct ev_loop));
2495 loop_init (EV_A_ flags); 2513 loop_init (EV_A_ flags);
2539} 2557}
2540#endif 2558#endif
2541 2559
2542#if EV_FEATURE_API 2560#if EV_FEATURE_API
2543void ecb_cold 2561void ecb_cold
2544ev_verify (EV_P) 2562ev_verify (EV_P) EV_THROW
2545{ 2563{
2546#if EV_VERIFY 2564#if EV_VERIFY
2547 int i; 2565 int i;
2548 WL w; 2566 WL w, w2;
2549 2567
2550 assert (activecnt >= -1); 2568 assert (activecnt >= -1);
2551 2569
2552 assert (fdchangemax >= fdchangecnt); 2570 assert (fdchangemax >= fdchangecnt);
2553 for (i = 0; i < fdchangecnt; ++i) 2571 for (i = 0; i < fdchangecnt; ++i)
2554 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); 2572 assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0));
2555 2573
2556 assert (anfdmax >= 0); 2574 assert (anfdmax >= 0);
2557 for (i = 0; i < anfdmax; ++i) 2575 for (i = 0; i < anfdmax; ++i)
2576 {
2577 int j = 0;
2578
2558 for (w = anfds [i].head; w; w = w->next) 2579 for (w = w2 = anfds [i].head; w; w = w->next)
2559 { 2580 {
2560 verify_watcher (EV_A_ (W)w); 2581 verify_watcher (EV_A_ (W)w);
2582
2583 if (j++ & 1)
2584 {
2585 assert (("libev: io watcher list contains a loop", w != w2));
2586 w2 = w2->next;
2587 }
2588
2561 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); 2589 assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1));
2562 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); 2590 assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i));
2563 } 2591 }
2592 }
2564 2593
2565 assert (timermax >= timercnt); 2594 assert (timermax >= timercnt);
2566 verify_heap (EV_A_ timers, timercnt); 2595 verify_heap (EV_A_ timers, timercnt);
2567 2596
2568#if EV_PERIODIC_ENABLE 2597#if EV_PERIODIC_ENABLE
2618#if EV_MULTIPLICITY 2647#if EV_MULTIPLICITY
2619struct ev_loop * ecb_cold 2648struct ev_loop * ecb_cold
2620#else 2649#else
2621int 2650int
2622#endif 2651#endif
2623ev_default_loop (unsigned int flags) 2652ev_default_loop (unsigned int flags) EV_THROW
2624{ 2653{
2625 if (!ev_default_loop_ptr) 2654 if (!ev_default_loop_ptr)
2626 { 2655 {
2627#if EV_MULTIPLICITY 2656#if EV_MULTIPLICITY
2628 EV_P = ev_default_loop_ptr = &default_loop_struct; 2657 EV_P = ev_default_loop_ptr = &default_loop_struct;
2647 2676
2648 return ev_default_loop_ptr; 2677 return ev_default_loop_ptr;
2649} 2678}
2650 2679
2651void 2680void
2652ev_loop_fork (EV_P) 2681ev_loop_fork (EV_P) EV_THROW
2653{ 2682{
2654 postfork = 1; /* must be in line with ev_default_fork */ 2683 postfork = 1; /* must be in line with ev_default_fork */
2655} 2684}
2656 2685
2657/*****************************************************************************/ 2686/*****************************************************************************/
2661{ 2690{
2662 EV_CB_INVOKE ((W)w, revents); 2691 EV_CB_INVOKE ((W)w, revents);
2663} 2692}
2664 2693
2665unsigned int 2694unsigned int
2666ev_pending_count (EV_P) 2695ev_pending_count (EV_P) EV_THROW
2667{ 2696{
2668 int pri; 2697 int pri;
2669 unsigned int count = 0; 2698 unsigned int count = 0;
2670 2699
2671 for (pri = NUMPRI; pri--; ) 2700 for (pri = NUMPRI; pri--; )
2675} 2704}
2676 2705
2677void noinline 2706void noinline
2678ev_invoke_pending (EV_P) 2707ev_invoke_pending (EV_P)
2679{ 2708{
2680 int pri; 2709 for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */
2681
2682 for (pri = NUMPRI; pri--; )
2683 while (pendingcnt [pri]) 2710 while (pendingcnt [pendingpri])
2684 { 2711 {
2685 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2712 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
2686 2713
2687 p->w->pending = 0; 2714 p->w->pending = 0;
2688 EV_CB_INVOKE (p->w, p->events); 2715 EV_CB_INVOKE (p->w, p->events);
2689 EV_FREQUENT_CHECK; 2716 EV_FREQUENT_CHECK;
2690 } 2717 }
2930 2957
2931 mn_now = ev_rt_now; 2958 mn_now = ev_rt_now;
2932 } 2959 }
2933} 2960}
2934 2961
2935void 2962int
2936ev_run (EV_P_ int flags) 2963ev_run (EV_P_ int flags)
2937{ 2964{
2938#if EV_FEATURE_API 2965#if EV_FEATURE_API
2939 ++loop_depth; 2966 ++loop_depth;
2940#endif 2967#endif
3097 loop_done = EVBREAK_CANCEL; 3124 loop_done = EVBREAK_CANCEL;
3098 3125
3099#if EV_FEATURE_API 3126#if EV_FEATURE_API
3100 --loop_depth; 3127 --loop_depth;
3101#endif 3128#endif
3129
3130 return activecnt;
3102} 3131}
3103 3132
3104void 3133void
3105ev_break (EV_P_ int how) 3134ev_break (EV_P_ int how) EV_THROW
3106{ 3135{
3107 loop_done = how; 3136 loop_done = how;
3108} 3137}
3109 3138
3110void 3139void
3111ev_ref (EV_P) 3140ev_ref (EV_P) EV_THROW
3112{ 3141{
3113 ++activecnt; 3142 ++activecnt;
3114} 3143}
3115 3144
3116void 3145void
3117ev_unref (EV_P) 3146ev_unref (EV_P) EV_THROW
3118{ 3147{
3119 --activecnt; 3148 --activecnt;
3120} 3149}
3121 3150
3122void 3151void
3123ev_now_update (EV_P) 3152ev_now_update (EV_P) EV_THROW
3124{ 3153{
3125 time_update (EV_A_ 1e100); 3154 time_update (EV_A_ 1e100);
3126} 3155}
3127 3156
3128void 3157void
3129ev_suspend (EV_P) 3158ev_suspend (EV_P) EV_THROW
3130{ 3159{
3131 ev_now_update (EV_A); 3160 ev_now_update (EV_A);
3132} 3161}
3133 3162
3134void 3163void
3135ev_resume (EV_P) 3164ev_resume (EV_P) EV_THROW
3136{ 3165{
3137 ev_tstamp mn_prev = mn_now; 3166 ev_tstamp mn_prev = mn_now;
3138 3167
3139 ev_now_update (EV_A); 3168 ev_now_update (EV_A);
3140 timers_reschedule (EV_A_ mn_now - mn_prev); 3169 timers_reschedule (EV_A_ mn_now - mn_prev);
3179 w->pending = 0; 3208 w->pending = 0;
3180 } 3209 }
3181} 3210}
3182 3211
3183int 3212int
3184ev_clear_pending (EV_P_ void *w) 3213ev_clear_pending (EV_P_ void *w) EV_THROW
3185{ 3214{
3186 W w_ = (W)w; 3215 W w_ = (W)w;
3187 int pending = w_->pending; 3216 int pending = w_->pending;
3188 3217
3189 if (expect_true (pending)) 3218 if (expect_true (pending))
3222} 3251}
3223 3252
3224/*****************************************************************************/ 3253/*****************************************************************************/
3225 3254
3226void noinline 3255void noinline
3227ev_io_start (EV_P_ ev_io *w) 3256ev_io_start (EV_P_ ev_io *w) EV_THROW
3228{ 3257{
3229 int fd = w->fd; 3258 int fd = w->fd;
3230 3259
3231 if (expect_false (ev_is_active (w))) 3260 if (expect_false (ev_is_active (w)))
3232 return; 3261 return;
3238 3267
3239 ev_start (EV_A_ (W)w, 1); 3268 ev_start (EV_A_ (W)w, 1);
3240 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); 3269 array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero);
3241 wlist_add (&anfds[fd].head, (WL)w); 3270 wlist_add (&anfds[fd].head, (WL)w);
3242 3271
3272 /* common bug, apparently */
3273 assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w));
3274
3243 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); 3275 fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY);
3244 w->events &= ~EV__IOFDSET; 3276 w->events &= ~EV__IOFDSET;
3245 3277
3246 EV_FREQUENT_CHECK; 3278 EV_FREQUENT_CHECK;
3247} 3279}
3248 3280
3249void noinline 3281void noinline
3250ev_io_stop (EV_P_ ev_io *w) 3282ev_io_stop (EV_P_ ev_io *w) EV_THROW
3251{ 3283{
3252 clear_pending (EV_A_ (W)w); 3284 clear_pending (EV_A_ (W)w);
3253 if (expect_false (!ev_is_active (w))) 3285 if (expect_false (!ev_is_active (w)))
3254 return; 3286 return;
3255 3287
3264 3296
3265 EV_FREQUENT_CHECK; 3297 EV_FREQUENT_CHECK;
3266} 3298}
3267 3299
3268void noinline 3300void noinline
3269ev_timer_start (EV_P_ ev_timer *w) 3301ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3270{ 3302{
3271 if (expect_false (ev_is_active (w))) 3303 if (expect_false (ev_is_active (w)))
3272 return; 3304 return;
3273 3305
3274 ev_at (w) += mn_now; 3306 ev_at (w) += mn_now;
3288 3320
3289 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3321 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3290} 3322}
3291 3323
3292void noinline 3324void noinline
3293ev_timer_stop (EV_P_ ev_timer *w) 3325ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3294{ 3326{
3295 clear_pending (EV_A_ (W)w); 3327 clear_pending (EV_A_ (W)w);
3296 if (expect_false (!ev_is_active (w))) 3328 if (expect_false (!ev_is_active (w)))
3297 return; 3329 return;
3298 3330
3318 3350
3319 EV_FREQUENT_CHECK; 3351 EV_FREQUENT_CHECK;
3320} 3352}
3321 3353
3322void noinline 3354void noinline
3323ev_timer_again (EV_P_ ev_timer *w) 3355ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3324{ 3356{
3325 EV_FREQUENT_CHECK; 3357 EV_FREQUENT_CHECK;
3326 3358
3327 clear_pending (EV_A_ (W)w); 3359 clear_pending (EV_A_ (W)w);
3328 3360
3345 3377
3346 EV_FREQUENT_CHECK; 3378 EV_FREQUENT_CHECK;
3347} 3379}
3348 3380
3349ev_tstamp 3381ev_tstamp
3350ev_timer_remaining (EV_P_ ev_timer *w) 3382ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3351{ 3383{
3352 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3384 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3353} 3385}
3354 3386
3355#if EV_PERIODIC_ENABLE 3387#if EV_PERIODIC_ENABLE
3356void noinline 3388void noinline
3357ev_periodic_start (EV_P_ ev_periodic *w) 3389ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3358{ 3390{
3359 if (expect_false (ev_is_active (w))) 3391 if (expect_false (ev_is_active (w)))
3360 return; 3392 return;
3361 3393
3362 if (w->reschedule_cb) 3394 if (w->reschedule_cb)
3382 3414
3383 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3415 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3384} 3416}
3385 3417
3386void noinline 3418void noinline
3387ev_periodic_stop (EV_P_ ev_periodic *w) 3419ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3388{ 3420{
3389 clear_pending (EV_A_ (W)w); 3421 clear_pending (EV_A_ (W)w);
3390 if (expect_false (!ev_is_active (w))) 3422 if (expect_false (!ev_is_active (w)))
3391 return; 3423 return;
3392 3424
3410 3442
3411 EV_FREQUENT_CHECK; 3443 EV_FREQUENT_CHECK;
3412} 3444}
3413 3445
3414void noinline 3446void noinline
3415ev_periodic_again (EV_P_ ev_periodic *w) 3447ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3416{ 3448{
3417 /* TODO: use adjustheap and recalculation */ 3449 /* TODO: use adjustheap and recalculation */
3418 ev_periodic_stop (EV_A_ w); 3450 ev_periodic_stop (EV_A_ w);
3419 ev_periodic_start (EV_A_ w); 3451 ev_periodic_start (EV_A_ w);
3420} 3452}
3425#endif 3457#endif
3426 3458
3427#if EV_SIGNAL_ENABLE 3459#if EV_SIGNAL_ENABLE
3428 3460
3429void noinline 3461void noinline
3430ev_signal_start (EV_P_ ev_signal *w) 3462ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3431{ 3463{
3432 if (expect_false (ev_is_active (w))) 3464 if (expect_false (ev_is_active (w)))
3433 return; 3465 return;
3434 3466
3435 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3467 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3506 3538
3507 EV_FREQUENT_CHECK; 3539 EV_FREQUENT_CHECK;
3508} 3540}
3509 3541
3510void noinline 3542void noinline
3511ev_signal_stop (EV_P_ ev_signal *w) 3543ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3512{ 3544{
3513 clear_pending (EV_A_ (W)w); 3545 clear_pending (EV_A_ (W)w);
3514 if (expect_false (!ev_is_active (w))) 3546 if (expect_false (!ev_is_active (w)))
3515 return; 3547 return;
3516 3548
3547#endif 3579#endif
3548 3580
3549#if EV_CHILD_ENABLE 3581#if EV_CHILD_ENABLE
3550 3582
3551void 3583void
3552ev_child_start (EV_P_ ev_child *w) 3584ev_child_start (EV_P_ ev_child *w) EV_THROW
3553{ 3585{
3554#if EV_MULTIPLICITY 3586#if EV_MULTIPLICITY
3555 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3587 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3556#endif 3588#endif
3557 if (expect_false (ev_is_active (w))) 3589 if (expect_false (ev_is_active (w)))
3564 3596
3565 EV_FREQUENT_CHECK; 3597 EV_FREQUENT_CHECK;
3566} 3598}
3567 3599
3568void 3600void
3569ev_child_stop (EV_P_ ev_child *w) 3601ev_child_stop (EV_P_ ev_child *w) EV_THROW
3570{ 3602{
3571 clear_pending (EV_A_ (W)w); 3603 clear_pending (EV_A_ (W)w);
3572 if (expect_false (!ev_is_active (w))) 3604 if (expect_false (!ev_is_active (w)))
3573 return; 3605 return;
3574 3606
3826#else 3858#else
3827# define EV_LSTAT(p,b) lstat (p, b) 3859# define EV_LSTAT(p,b) lstat (p, b)
3828#endif 3860#endif
3829 3861
3830void 3862void
3831ev_stat_stat (EV_P_ ev_stat *w) 3863ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3832{ 3864{
3833 if (lstat (w->path, &w->attr) < 0) 3865 if (lstat (w->path, &w->attr) < 0)
3834 w->attr.st_nlink = 0; 3866 w->attr.st_nlink = 0;
3835 else if (!w->attr.st_nlink) 3867 else if (!w->attr.st_nlink)
3836 w->attr.st_nlink = 1; 3868 w->attr.st_nlink = 1;
3875 ev_feed_event (EV_A_ w, EV_STAT); 3907 ev_feed_event (EV_A_ w, EV_STAT);
3876 } 3908 }
3877} 3909}
3878 3910
3879void 3911void
3880ev_stat_start (EV_P_ ev_stat *w) 3912ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3881{ 3913{
3882 if (expect_false (ev_is_active (w))) 3914 if (expect_false (ev_is_active (w)))
3883 return; 3915 return;
3884 3916
3885 ev_stat_stat (EV_A_ w); 3917 ev_stat_stat (EV_A_ w);
3906 3938
3907 EV_FREQUENT_CHECK; 3939 EV_FREQUENT_CHECK;
3908} 3940}
3909 3941
3910void 3942void
3911ev_stat_stop (EV_P_ ev_stat *w) 3943ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3912{ 3944{
3913 clear_pending (EV_A_ (W)w); 3945 clear_pending (EV_A_ (W)w);
3914 if (expect_false (!ev_is_active (w))) 3946 if (expect_false (!ev_is_active (w)))
3915 return; 3947 return;
3916 3948
3932} 3964}
3933#endif 3965#endif
3934 3966
3935#if EV_IDLE_ENABLE 3967#if EV_IDLE_ENABLE
3936void 3968void
3937ev_idle_start (EV_P_ ev_idle *w) 3969ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3938{ 3970{
3939 if (expect_false (ev_is_active (w))) 3971 if (expect_false (ev_is_active (w)))
3940 return; 3972 return;
3941 3973
3942 pri_adjust (EV_A_ (W)w); 3974 pri_adjust (EV_A_ (W)w);
3955 3987
3956 EV_FREQUENT_CHECK; 3988 EV_FREQUENT_CHECK;
3957} 3989}
3958 3990
3959void 3991void
3960ev_idle_stop (EV_P_ ev_idle *w) 3992ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3961{ 3993{
3962 clear_pending (EV_A_ (W)w); 3994 clear_pending (EV_A_ (W)w);
3963 if (expect_false (!ev_is_active (w))) 3995 if (expect_false (!ev_is_active (w)))
3964 return; 3996 return;
3965 3997
3979} 4011}
3980#endif 4012#endif
3981 4013
3982#if EV_PREPARE_ENABLE 4014#if EV_PREPARE_ENABLE
3983void 4015void
3984ev_prepare_start (EV_P_ ev_prepare *w) 4016ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3985{ 4017{
3986 if (expect_false (ev_is_active (w))) 4018 if (expect_false (ev_is_active (w)))
3987 return; 4019 return;
3988 4020
3989 EV_FREQUENT_CHECK; 4021 EV_FREQUENT_CHECK;
3994 4026
3995 EV_FREQUENT_CHECK; 4027 EV_FREQUENT_CHECK;
3996} 4028}
3997 4029
3998void 4030void
3999ev_prepare_stop (EV_P_ ev_prepare *w) 4031ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
4000{ 4032{
4001 clear_pending (EV_A_ (W)w); 4033 clear_pending (EV_A_ (W)w);
4002 if (expect_false (!ev_is_active (w))) 4034 if (expect_false (!ev_is_active (w)))
4003 return; 4035 return;
4004 4036
4017} 4049}
4018#endif 4050#endif
4019 4051
4020#if EV_CHECK_ENABLE 4052#if EV_CHECK_ENABLE
4021void 4053void
4022ev_check_start (EV_P_ ev_check *w) 4054ev_check_start (EV_P_ ev_check *w) EV_THROW
4023{ 4055{
4024 if (expect_false (ev_is_active (w))) 4056 if (expect_false (ev_is_active (w)))
4025 return; 4057 return;
4026 4058
4027 EV_FREQUENT_CHECK; 4059 EV_FREQUENT_CHECK;
4032 4064
4033 EV_FREQUENT_CHECK; 4065 EV_FREQUENT_CHECK;
4034} 4066}
4035 4067
4036void 4068void
4037ev_check_stop (EV_P_ ev_check *w) 4069ev_check_stop (EV_P_ ev_check *w) EV_THROW
4038{ 4070{
4039 clear_pending (EV_A_ (W)w); 4071 clear_pending (EV_A_ (W)w);
4040 if (expect_false (!ev_is_active (w))) 4072 if (expect_false (!ev_is_active (w)))
4041 return; 4073 return;
4042 4074
4055} 4087}
4056#endif 4088#endif
4057 4089
4058#if EV_EMBED_ENABLE 4090#if EV_EMBED_ENABLE
4059void noinline 4091void noinline
4060ev_embed_sweep (EV_P_ ev_embed *w) 4092ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4061{ 4093{
4062 ev_run (w->other, EVRUN_NOWAIT); 4094 ev_run (w->other, EVRUN_NOWAIT);
4063} 4095}
4064 4096
4065static void 4097static void
4113 ev_idle_stop (EV_A_ idle); 4145 ev_idle_stop (EV_A_ idle);
4114} 4146}
4115#endif 4147#endif
4116 4148
4117void 4149void
4118ev_embed_start (EV_P_ ev_embed *w) 4150ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4119{ 4151{
4120 if (expect_false (ev_is_active (w))) 4152 if (expect_false (ev_is_active (w)))
4121 return; 4153 return;
4122 4154
4123 { 4155 {
4144 4176
4145 EV_FREQUENT_CHECK; 4177 EV_FREQUENT_CHECK;
4146} 4178}
4147 4179
4148void 4180void
4149ev_embed_stop (EV_P_ ev_embed *w) 4181ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4150{ 4182{
4151 clear_pending (EV_A_ (W)w); 4183 clear_pending (EV_A_ (W)w);
4152 if (expect_false (!ev_is_active (w))) 4184 if (expect_false (!ev_is_active (w)))
4153 return; 4185 return;
4154 4186
4164} 4196}
4165#endif 4197#endif
4166 4198
4167#if EV_FORK_ENABLE 4199#if EV_FORK_ENABLE
4168void 4200void
4169ev_fork_start (EV_P_ ev_fork *w) 4201ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4170{ 4202{
4171 if (expect_false (ev_is_active (w))) 4203 if (expect_false (ev_is_active (w)))
4172 return; 4204 return;
4173 4205
4174 EV_FREQUENT_CHECK; 4206 EV_FREQUENT_CHECK;
4179 4211
4180 EV_FREQUENT_CHECK; 4212 EV_FREQUENT_CHECK;
4181} 4213}
4182 4214
4183void 4215void
4184ev_fork_stop (EV_P_ ev_fork *w) 4216ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4185{ 4217{
4186 clear_pending (EV_A_ (W)w); 4218 clear_pending (EV_A_ (W)w);
4187 if (expect_false (!ev_is_active (w))) 4219 if (expect_false (!ev_is_active (w)))
4188 return; 4220 return;
4189 4221
4202} 4234}
4203#endif 4235#endif
4204 4236
4205#if EV_CLEANUP_ENABLE 4237#if EV_CLEANUP_ENABLE
4206void 4238void
4207ev_cleanup_start (EV_P_ ev_cleanup *w) 4239ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4208{ 4240{
4209 if (expect_false (ev_is_active (w))) 4241 if (expect_false (ev_is_active (w)))
4210 return; 4242 return;
4211 4243
4212 EV_FREQUENT_CHECK; 4244 EV_FREQUENT_CHECK;
4219 ev_unref (EV_A); 4251 ev_unref (EV_A);
4220 EV_FREQUENT_CHECK; 4252 EV_FREQUENT_CHECK;
4221} 4253}
4222 4254
4223void 4255void
4224ev_cleanup_stop (EV_P_ ev_cleanup *w) 4256ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4225{ 4257{
4226 clear_pending (EV_A_ (W)w); 4258 clear_pending (EV_A_ (W)w);
4227 if (expect_false (!ev_is_active (w))) 4259 if (expect_false (!ev_is_active (w)))
4228 return; 4260 return;
4229 4261
4243} 4275}
4244#endif 4276#endif
4245 4277
4246#if EV_ASYNC_ENABLE 4278#if EV_ASYNC_ENABLE
4247void 4279void
4248ev_async_start (EV_P_ ev_async *w) 4280ev_async_start (EV_P_ ev_async *w) EV_THROW
4249{ 4281{
4250 if (expect_false (ev_is_active (w))) 4282 if (expect_false (ev_is_active (w)))
4251 return; 4283 return;
4252 4284
4253 w->sent = 0; 4285 w->sent = 0;
4262 4294
4263 EV_FREQUENT_CHECK; 4295 EV_FREQUENT_CHECK;
4264} 4296}
4265 4297
4266void 4298void
4267ev_async_stop (EV_P_ ev_async *w) 4299ev_async_stop (EV_P_ ev_async *w) EV_THROW
4268{ 4300{
4269 clear_pending (EV_A_ (W)w); 4301 clear_pending (EV_A_ (W)w);
4270 if (expect_false (!ev_is_active (w))) 4302 if (expect_false (!ev_is_active (w)))
4271 return; 4303 return;
4272 4304
4283 4315
4284 EV_FREQUENT_CHECK; 4316 EV_FREQUENT_CHECK;
4285} 4317}
4286 4318
4287void 4319void
4288ev_async_send (EV_P_ ev_async *w) 4320ev_async_send (EV_P_ ev_async *w) EV_THROW
4289{ 4321{
4290 w->sent = 1; 4322 w->sent = 1;
4291 evpipe_write (EV_A_ &async_pending); 4323 evpipe_write (EV_A_ &async_pending);
4292} 4324}
4293#endif 4325#endif
4330 4362
4331 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4363 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4332} 4364}
4333 4365
4334void 4366void
4335ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4367ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4336{ 4368{
4337 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4369 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4338 4370
4339 if (expect_false (!once)) 4371 if (expect_false (!once))
4340 { 4372 {
4362 4394
4363/*****************************************************************************/ 4395/*****************************************************************************/
4364 4396
4365#if EV_WALK_ENABLE 4397#if EV_WALK_ENABLE
4366void ecb_cold 4398void ecb_cold
4367ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4399ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4368{ 4400{
4369 int i, j; 4401 int i, j;
4370 ev_watcher_list *wl, *wn; 4402 ev_watcher_list *wl, *wn;
4371 4403
4372 if (types & (EV_IO | EV_EMBED)) 4404 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines