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

Comparing libev/ev.c (file contents):
Revision 1.409 by root, Sat Feb 4 15:17:34 2012 UTC vs.
Revision 1.425 by root, Sun May 6 13:09:35 2012 UTC

1/* 1/*
2 * libev event processing core, watcher management 2 * libev event processing core, watcher management
3 * 3 *
4 * Copyright (c) 2007,2008,2009,2010,2011 Marc Alexander Lehmann <libev@schmorp.de> 4 * Copyright (c) 2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann <libev@schmorp.de>
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without modifica- 7 * Redistribution and use in source and binary forms, with or without modifica-
8 * tion, are permitted provided that the following conditions are met: 8 * tion, are permitted provided that the following conditions are met:
9 * 9 *
59# endif 59# endif
60# ifndef EV_USE_MONOTONIC 60# ifndef EV_USE_MONOTONIC
61# define EV_USE_MONOTONIC 1 61# define EV_USE_MONOTONIC 1
62# endif 62# endif
63# endif 63# endif
64# elif !defined(EV_USE_CLOCK_SYSCALL) 64# elif !defined EV_USE_CLOCK_SYSCALL
65# define EV_USE_CLOCK_SYSCALL 0 65# define EV_USE_CLOCK_SYSCALL 0
66# endif 66# endif
67 67
68# if HAVE_CLOCK_GETTIME 68# if HAVE_CLOCK_GETTIME
69# ifndef EV_USE_MONOTONIC 69# ifndef EV_USE_MONOTONIC
183# include EV_H 183# include EV_H
184#else 184#else
185# include "ev.h" 185# include "ev.h"
186#endif 186#endif
187 187
188#if EV_NO_THREADS
189# undef EV_NO_SMP
190# define EV_NO_SMP 1
191# undef ECB_NO_THREADS
192# define ECB_NO_THREADS 1
193#endif
194#if EV_NO_SMP
195# undef EV_NO_SMP
196# define ECB_NO_SMP 1
197#endif
198
188#ifndef _WIN32 199#ifndef _WIN32
189# include <sys/time.h> 200# include <sys/time.h>
190# include <sys/wait.h> 201# include <sys/wait.h>
191# include <unistd.h> 202# include <unistd.h>
192#else 203#else
208#define _DARWIN_UNLIMITED_SELECT 1 219#define _DARWIN_UNLIMITED_SELECT 1
209 220
210/* this block tries to deduce configuration from header-defined symbols and defaults */ 221/* this block tries to deduce configuration from header-defined symbols and defaults */
211 222
212/* try to deduce the maximum number of signals on this platform */ 223/* try to deduce the maximum number of signals on this platform */
213#if defined (EV_NSIG) 224#if defined EV_NSIG
214/* use what's provided */ 225/* use what's provided */
215#elif defined (NSIG) 226#elif defined NSIG
216# define EV_NSIG (NSIG) 227# define EV_NSIG (NSIG)
217#elif defined(_NSIG) 228#elif defined _NSIG
218# define EV_NSIG (_NSIG) 229# define EV_NSIG (_NSIG)
219#elif defined (SIGMAX) 230#elif defined SIGMAX
220# define EV_NSIG (SIGMAX+1) 231# define EV_NSIG (SIGMAX+1)
221#elif defined (SIG_MAX) 232#elif defined SIG_MAX
222# define EV_NSIG (SIG_MAX+1) 233# define EV_NSIG (SIG_MAX+1)
223#elif defined (_SIG_MAX) 234#elif defined _SIG_MAX
224# define EV_NSIG (_SIG_MAX+1) 235# define EV_NSIG (_SIG_MAX+1)
225#elif defined (MAXSIG) 236#elif defined MAXSIG
226# define EV_NSIG (MAXSIG+1) 237# define EV_NSIG (MAXSIG+1)
227#elif defined (MAX_SIG) 238#elif defined MAX_SIG
228# define EV_NSIG (MAX_SIG+1) 239# define EV_NSIG (MAX_SIG+1)
229#elif defined (SIGARRAYSIZE) 240#elif defined SIGARRAYSIZE
230# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ 241# define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */
231#elif defined (_sys_nsig) 242#elif defined _sys_nsig
232# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ 243# define EV_NSIG (_sys_nsig) /* Solaris 2.5 */
233#else 244#else
234# error "unable to find value for NSIG, please report" 245# error "unable to find value for NSIG, please report"
235/* to make it compile regardless, just remove the above line, */ 246/* to make it compile regardless, just remove the above line, */
236/* but consider reporting it, too! :) */ 247/* but consider reporting it, too! :) */
248# define EV_USE_CLOCK_SYSCALL 0 259# define EV_USE_CLOCK_SYSCALL 0
249# endif 260# endif
250#endif 261#endif
251 262
252#ifndef EV_USE_MONOTONIC 263#ifndef EV_USE_MONOTONIC
253# if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 264# if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0
254# define EV_USE_MONOTONIC EV_FEATURE_OS 265# define EV_USE_MONOTONIC EV_FEATURE_OS
255# else 266# else
256# define EV_USE_MONOTONIC 0 267# define EV_USE_MONOTONIC 0
257# endif 268# endif
258#endif 269#endif
348#endif 359#endif
349 360
350/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 361/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
351/* which makes programs even slower. might work on other unices, too. */ 362/* which makes programs even slower. might work on other unices, too. */
352#if EV_USE_CLOCK_SYSCALL 363#if EV_USE_CLOCK_SYSCALL
353# include <syscall.h> 364# include <sys/syscall.h>
354# ifdef SYS_clock_gettime 365# ifdef SYS_clock_gettime
355# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) 366# define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts))
356# undef EV_USE_MONOTONIC 367# undef EV_USE_MONOTONIC
357# define EV_USE_MONOTONIC 1 368# define EV_USE_MONOTONIC 1
358# else 369# else
384# define EV_USE_INOTIFY 0 395# define EV_USE_INOTIFY 0
385#endif 396#endif
386 397
387#if !EV_USE_NANOSLEEP 398#if !EV_USE_NANOSLEEP
388/* hp-ux has it in sys/time.h, which we unconditionally include above */ 399/* hp-ux has it in sys/time.h, which we unconditionally include above */
389# if !defined(_WIN32) && !defined(__hpux) 400# if !defined _WIN32 && !defined __hpux
390# include <sys/select.h> 401# include <sys/select.h>
391# endif 402# endif
392#endif 403#endif
393 404
394#if EV_USE_INOTIFY 405#if EV_USE_INOTIFY
522 * or so. 533 * or so.
523 * we try to detect these and simply assume they are not gcc - if they have 534 * we try to detect these and simply assume they are not gcc - if they have
524 * an issue with that they should have done it right in the first place. 535 * an issue with that they should have done it right in the first place.
525 */ 536 */
526#ifndef ECB_GCC_VERSION 537#ifndef ECB_GCC_VERSION
527 #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) 538 #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__
528 #define ECB_GCC_VERSION(major,minor) 0 539 #define ECB_GCC_VERSION(major,minor) 0
529 #else 540 #else
530 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 541 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
531 #endif 542 #endif
532#endif 543#endif
534/*****************************************************************************/ 545/*****************************************************************************/
535 546
536/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ 547/* ECB_NO_THREADS - ecb is not used by multiple threads, ever */
537/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ 548/* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */
538 549
550#if ECB_NO_THREADS
551# define ECB_NO_SMP 1
552#endif
553
539#if ECB_NO_THREADS || ECB_NO_SMP 554#if ECB_NO_THREADS || ECB_NO_SMP
540 #define ECB_MEMORY_FENCE do { } while (0) 555 #define ECB_MEMORY_FENCE do { } while (0)
541#endif 556#endif
542 557
543#ifndef ECB_MEMORY_FENCE 558#ifndef ECB_MEMORY_FENCE
544 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__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
545 #if __i386 || __i386__ 560 #if __i386 || __i386__
546 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 561 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
547 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ 562 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
548 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ 563 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
549 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ 564 #elif __amd64 || __amd64__ || __x86_64 || __x86_64__
550 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") 565 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
551 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") 566 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
552 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ 567 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
553 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ 568 #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__
554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 569 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory")
555 #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ 570 #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \
556 || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) 571 || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__
557 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") 572 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory")
558 #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ 573 #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \
559 || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) 574 || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__
560 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") 575 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory")
561 #elif __sparc || __sparc__ 576 #elif __sparc || __sparc__
562 #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")
563 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 578 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
564 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 579 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
565 #elif defined(__s390__) || defined(__s390x__) 580 #elif defined __s390__ || defined __s390x__
566 #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")
567 #endif 586 #endif
568 #endif 587 #endif
569#endif 588#endif
570 589
571#ifndef ECB_MEMORY_FENCE 590#ifndef ECB_MEMORY_FENCE
572 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) 591 #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__
573 #define ECB_MEMORY_FENCE __sync_synchronize () 592 #define ECB_MEMORY_FENCE __sync_synchronize ()
574 /*#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); }) */
575 /*#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 ); }) */
576 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 595 #elif _MSC_VER >= 1400 /* VC++ 2005 */
577 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 596 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
578 #define ECB_MEMORY_FENCE _ReadWriteBarrier () 597 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
579 #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 */
580 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () 599 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
581 #elif defined(_WIN32) 600 #elif defined _WIN32
582 #include <WinNT.h> 601 #include <WinNT.h>
583 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ 602 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
584 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 603 #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110
585 #include <mbarrier.h> 604 #include <mbarrier.h>
586 #define ECB_MEMORY_FENCE __machine_rw_barrier () 605 #define ECB_MEMORY_FENCE __machine_rw_barrier ()
587 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () 606 #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier ()
588 #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 ()
589 #endif 610 #endif
590#endif 611#endif
591 612
592#ifndef ECB_MEMORY_FENCE 613#ifndef ECB_MEMORY_FENCE
593 #if !ECB_AVOID_PTHREADS 614 #if !ECB_AVOID_PTHREADS
605 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; 626 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
606 #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)
607 #endif 628 #endif
608#endif 629#endif
609 630
610#if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) 631#if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE
611 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE 632 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
612#endif 633#endif
613 634
614#if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) 635#if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE
615 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE 636 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
616#endif 637#endif
617 638
618/*****************************************************************************/ 639/*****************************************************************************/
619 640
1084{ 1105{
1085 write (STDERR_FILENO, msg, strlen (msg)); 1106 write (STDERR_FILENO, msg, strlen (msg));
1086} 1107}
1087#endif 1108#endif
1088 1109
1089static void (*syserr_cb)(const char *msg); 1110static void (*syserr_cb)(const char *msg) EV_THROW;
1090 1111
1091void ecb_cold 1112void ecb_cold
1092ev_set_syserr_cb (void (*cb)(const char *msg)) 1113ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW
1093{ 1114{
1094 syserr_cb = cb; 1115 syserr_cb = cb;
1095} 1116}
1096 1117
1097static void noinline ecb_cold 1118static void noinline ecb_cold
1133 free (ptr); 1154 free (ptr);
1134 return 0; 1155 return 0;
1135#endif 1156#endif
1136} 1157}
1137 1158
1138static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; 1159static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul;
1139 1160
1140void ecb_cold 1161void ecb_cold
1141ev_set_allocator (void *(*cb)(void *ptr, long size)) 1162ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW
1142{ 1163{
1143 alloc = cb; 1164 alloc = cb;
1144} 1165}
1145 1166
1146inline_speed void * 1167inline_speed void *
1263 1284
1264/*****************************************************************************/ 1285/*****************************************************************************/
1265 1286
1266#ifndef EV_HAVE_EV_TIME 1287#ifndef EV_HAVE_EV_TIME
1267ev_tstamp 1288ev_tstamp
1268ev_time (void) 1289ev_time (void) EV_THROW
1269{ 1290{
1270#if EV_USE_REALTIME 1291#if EV_USE_REALTIME
1271 if (expect_true (have_realtime)) 1292 if (expect_true (have_realtime))
1272 { 1293 {
1273 struct timespec ts; 1294 struct timespec ts;
1297 return ev_time (); 1318 return ev_time ();
1298} 1319}
1299 1320
1300#if EV_MULTIPLICITY 1321#if EV_MULTIPLICITY
1301ev_tstamp 1322ev_tstamp
1302ev_now (EV_P) 1323ev_now (EV_P) EV_THROW
1303{ 1324{
1304 return ev_rt_now; 1325 return ev_rt_now;
1305} 1326}
1306#endif 1327#endif
1307 1328
1308void 1329void
1309ev_sleep (ev_tstamp delay) 1330ev_sleep (ev_tstamp delay) EV_THROW
1310{ 1331{
1311 if (delay > 0.) 1332 if (delay > 0.)
1312 { 1333 {
1313#if EV_USE_NANOSLEEP 1334#if EV_USE_NANOSLEEP
1314 struct timespec ts; 1335 struct timespec ts;
1315 1336
1316 EV_TS_SET (ts, delay); 1337 EV_TS_SET (ts, delay);
1317 nanosleep (&ts, 0); 1338 nanosleep (&ts, 0);
1318#elif defined(_WIN32) 1339#elif defined _WIN32
1319 Sleep ((unsigned long)(delay * 1e3)); 1340 Sleep ((unsigned long)(delay * 1e3));
1320#else 1341#else
1321 struct timeval tv; 1342 struct timeval tv;
1322 1343
1323 /* 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 */
1395pendingcb (EV_P_ ev_prepare *w, int revents) 1416pendingcb (EV_P_ ev_prepare *w, int revents)
1396{ 1417{
1397} 1418}
1398 1419
1399void noinline 1420void noinline
1400ev_feed_event (EV_P_ void *w, int revents) 1421ev_feed_event (EV_P_ void *w, int revents) EV_THROW
1401{ 1422{
1402 W w_ = (W)w; 1423 W w_ = (W)w;
1403 int pri = ABSPRI (w_); 1424 int pri = ABSPRI (w_);
1404 1425
1405 if (expect_false (w_->pending)) 1426 if (expect_false (w_->pending))
1409 w_->pending = ++pendingcnt [pri]; 1430 w_->pending = ++pendingcnt [pri];
1410 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); 1431 array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2);
1411 pendings [pri][w_->pending - 1].w = w_; 1432 pendings [pri][w_->pending - 1].w = w_;
1412 pendings [pri][w_->pending - 1].events = revents; 1433 pendings [pri][w_->pending - 1].events = revents;
1413 } 1434 }
1435
1436 pendingpri = NUMPRI - 1;
1414} 1437}
1415 1438
1416inline_speed void 1439inline_speed void
1417feed_reverse (EV_P_ W w) 1440feed_reverse (EV_P_ W w)
1418{ 1441{
1464 if (expect_true (!anfd->reify)) 1487 if (expect_true (!anfd->reify))
1465 fd_event_nocheck (EV_A_ fd, revents); 1488 fd_event_nocheck (EV_A_ fd, revents);
1466} 1489}
1467 1490
1468void 1491void
1469ev_feed_fd_event (EV_P_ int fd, int revents) 1492ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW
1470{ 1493{
1471 if (fd >= 0 && fd < anfdmax) 1494 if (fd >= 0 && fd < anfdmax)
1472 fd_event_nocheck (EV_A_ fd, revents); 1495 fd_event_nocheck (EV_A_ fd, revents);
1473} 1496}
1474 1497
1823} 1846}
1824 1847
1825inline_speed void 1848inline_speed void
1826evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1849evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1827{ 1850{
1851 ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */
1852
1828 if (expect_true (*flag)) 1853 if (expect_true (*flag))
1829 return; 1854 return;
1830 1855
1831 *flag = 1; 1856 *flag = 1;
1832 1857
1856 /* win32 people keep sending patches that change this write() to send() */ 1881 /* win32 people keep sending patches that change this write() to send() */
1857 /* and then run away. but send() is wrong, it wants a socket handle on win32 */ 1882 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1858 /* so when you think this write should be a send instead, please find out */ 1883 /* so when you think this write should be a send instead, please find out */
1859 /* where your send() is from - it's definitely not the microsoft send, and */ 1884 /* where your send() is from - it's definitely not the microsoft send, and */
1860 /* tell me. thank you. */ 1885 /* tell me. thank you. */
1886 /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */
1887 /* check the ev documentation on how to use this flag */
1861 write (evpipe [1], &(evpipe [1]), 1); 1888 write (evpipe [1], &(evpipe [1]), 1);
1862 } 1889 }
1863 1890
1864 errno = old_errno; 1891 errno = old_errno;
1865 } 1892 }
1889 } 1916 }
1890 } 1917 }
1891 1918
1892 pipe_write_skipped = 0; 1919 pipe_write_skipped = 0;
1893 1920
1921 ECB_MEMORY_FENCE; /* push out skipped, acquire flags */
1922
1894#if EV_SIGNAL_ENABLE 1923#if EV_SIGNAL_ENABLE
1895 if (sig_pending) 1924 if (sig_pending)
1896 { 1925 {
1897 sig_pending = 0; 1926 sig_pending = 0;
1927
1928 ECB_MEMORY_FENCE_RELEASE;
1898 1929
1899 for (i = EV_NSIG - 1; i--; ) 1930 for (i = EV_NSIG - 1; i--; )
1900 if (expect_false (signals [i].pending)) 1931 if (expect_false (signals [i].pending))
1901 ev_feed_signal_event (EV_A_ i + 1); 1932 ev_feed_signal_event (EV_A_ i + 1);
1902 } 1933 }
1904 1935
1905#if EV_ASYNC_ENABLE 1936#if EV_ASYNC_ENABLE
1906 if (async_pending) 1937 if (async_pending)
1907 { 1938 {
1908 async_pending = 0; 1939 async_pending = 0;
1940
1941 ECB_MEMORY_FENCE_RELEASE;
1909 1942
1910 for (i = asynccnt; i--; ) 1943 for (i = asynccnt; i--; )
1911 if (asyncs [i]->sent) 1944 if (asyncs [i]->sent)
1912 { 1945 {
1913 asyncs [i]->sent = 0; 1946 asyncs [i]->sent = 0;
1918} 1951}
1919 1952
1920/*****************************************************************************/ 1953/*****************************************************************************/
1921 1954
1922void 1955void
1923ev_feed_signal (int signum) 1956ev_feed_signal (int signum) EV_THROW
1924{ 1957{
1925#if EV_MULTIPLICITY 1958#if EV_MULTIPLICITY
1926 EV_P = signals [signum - 1].loop; 1959 EV_P = signals [signum - 1].loop;
1927 1960
1928 if (!EV_A) 1961 if (!EV_A)
1945 1978
1946 ev_feed_signal (signum); 1979 ev_feed_signal (signum);
1947} 1980}
1948 1981
1949void noinline 1982void noinline
1950ev_feed_signal_event (EV_P_ int signum) 1983ev_feed_signal_event (EV_P_ int signum) EV_THROW
1951{ 1984{
1952 WL w; 1985 WL w;
1953 1986
1954 if (expect_false (signum <= 0 || signum > EV_NSIG)) 1987 if (expect_false (signum <= 0 || signum > EV_NSIG))
1955 return; 1988 return;
2071#if EV_USE_SELECT 2104#if EV_USE_SELECT
2072# include "ev_select.c" 2105# include "ev_select.c"
2073#endif 2106#endif
2074 2107
2075int ecb_cold 2108int ecb_cold
2076ev_version_major (void) 2109ev_version_major (void) EV_THROW
2077{ 2110{
2078 return EV_VERSION_MAJOR; 2111 return EV_VERSION_MAJOR;
2079} 2112}
2080 2113
2081int ecb_cold 2114int ecb_cold
2082ev_version_minor (void) 2115ev_version_minor (void) EV_THROW
2083{ 2116{
2084 return EV_VERSION_MINOR; 2117 return EV_VERSION_MINOR;
2085} 2118}
2086 2119
2087/* 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 */
2095 || getgid () != getegid (); 2128 || getgid () != getegid ();
2096#endif 2129#endif
2097} 2130}
2098 2131
2099unsigned int ecb_cold 2132unsigned int ecb_cold
2100ev_supported_backends (void) 2133ev_supported_backends (void) EV_THROW
2101{ 2134{
2102 unsigned int flags = 0; 2135 unsigned int flags = 0;
2103 2136
2104 if (EV_USE_PORT ) flags |= EVBACKEND_PORT; 2137 if (EV_USE_PORT ) flags |= EVBACKEND_PORT;
2105 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; 2138 if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE;
2109 2142
2110 return flags; 2143 return flags;
2111} 2144}
2112 2145
2113unsigned int ecb_cold 2146unsigned int ecb_cold
2114ev_recommended_backends (void) 2147ev_recommended_backends (void) EV_THROW
2115{ 2148{
2116 unsigned int flags = ev_supported_backends (); 2149 unsigned int flags = ev_supported_backends ();
2117 2150
2118#ifndef __NetBSD__ 2151#ifndef __NetBSD__
2119 /* kqueue is borked on everything but netbsd apparently */ 2152 /* kqueue is borked on everything but netbsd apparently */
2131 2164
2132 return flags; 2165 return flags;
2133} 2166}
2134 2167
2135unsigned int ecb_cold 2168unsigned int ecb_cold
2136ev_embeddable_backends (void) 2169ev_embeddable_backends (void) EV_THROW
2137{ 2170{
2138 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; 2171 int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT;
2139 2172
2140 /* 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 */
2141 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 */
2143 2176
2144 return flags; 2177 return flags;
2145} 2178}
2146 2179
2147unsigned int 2180unsigned int
2148ev_backend (EV_P) 2181ev_backend (EV_P) EV_THROW
2149{ 2182{
2150 return backend; 2183 return backend;
2151} 2184}
2152 2185
2153#if EV_FEATURE_API 2186#if EV_FEATURE_API
2154unsigned int 2187unsigned int
2155ev_iteration (EV_P) 2188ev_iteration (EV_P) EV_THROW
2156{ 2189{
2157 return loop_count; 2190 return loop_count;
2158} 2191}
2159 2192
2160unsigned int 2193unsigned int
2161ev_depth (EV_P) 2194ev_depth (EV_P) EV_THROW
2162{ 2195{
2163 return loop_depth; 2196 return loop_depth;
2164} 2197}
2165 2198
2166void 2199void
2167ev_set_io_collect_interval (EV_P_ ev_tstamp interval) 2200ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2168{ 2201{
2169 io_blocktime = interval; 2202 io_blocktime = interval;
2170} 2203}
2171 2204
2172void 2205void
2173ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) 2206ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW
2174{ 2207{
2175 timeout_blocktime = interval; 2208 timeout_blocktime = interval;
2176} 2209}
2177 2210
2178void 2211void
2179ev_set_userdata (EV_P_ void *data) 2212ev_set_userdata (EV_P_ void *data) EV_THROW
2180{ 2213{
2181 userdata = data; 2214 userdata = data;
2182} 2215}
2183 2216
2184void * 2217void *
2185ev_userdata (EV_P) 2218ev_userdata (EV_P) EV_THROW
2186{ 2219{
2187 return userdata; 2220 return userdata;
2188} 2221}
2189 2222
2190void 2223void
2191ev_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
2192{ 2225{
2193 invoke_cb = invoke_pending_cb; 2226 invoke_cb = invoke_pending_cb;
2194} 2227}
2195 2228
2196void 2229void
2197ev_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
2198{ 2231{
2199 release_cb = release; 2232 release_cb = release;
2200 acquire_cb = acquire; 2233 acquire_cb = acquire;
2201} 2234}
2202#endif 2235#endif
2203 2236
2204/* initialise a loop structure, must be zero-initialised */ 2237/* initialise a loop structure, must be zero-initialised */
2205static void noinline ecb_cold 2238static void noinline ecb_cold
2206loop_init (EV_P_ unsigned int flags) 2239loop_init (EV_P_ unsigned int flags) EV_THROW
2207{ 2240{
2208 if (!backend) 2241 if (!backend)
2209 { 2242 {
2210 origflags = flags; 2243 origflags = flags;
2211 2244
2464} 2497}
2465 2498
2466#if EV_MULTIPLICITY 2499#if EV_MULTIPLICITY
2467 2500
2468struct ev_loop * ecb_cold 2501struct ev_loop * ecb_cold
2469ev_loop_new (unsigned int flags) 2502ev_loop_new (unsigned int flags) EV_THROW
2470{ 2503{
2471 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); 2504 EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop));
2472 2505
2473 memset (EV_A, 0, sizeof (struct ev_loop)); 2506 memset (EV_A, 0, sizeof (struct ev_loop));
2474 loop_init (EV_A_ flags); 2507 loop_init (EV_A_ flags);
2518} 2551}
2519#endif 2552#endif
2520 2553
2521#if EV_FEATURE_API 2554#if EV_FEATURE_API
2522void ecb_cold 2555void ecb_cold
2523ev_verify (EV_P) 2556ev_verify (EV_P) EV_THROW
2524{ 2557{
2525#if EV_VERIFY 2558#if EV_VERIFY
2526 int i; 2559 int i;
2527 WL w; 2560 WL w;
2528 2561
2597#if EV_MULTIPLICITY 2630#if EV_MULTIPLICITY
2598struct ev_loop * ecb_cold 2631struct ev_loop * ecb_cold
2599#else 2632#else
2600int 2633int
2601#endif 2634#endif
2602ev_default_loop (unsigned int flags) 2635ev_default_loop (unsigned int flags) EV_THROW
2603{ 2636{
2604 if (!ev_default_loop_ptr) 2637 if (!ev_default_loop_ptr)
2605 { 2638 {
2606#if EV_MULTIPLICITY 2639#if EV_MULTIPLICITY
2607 EV_P = ev_default_loop_ptr = &default_loop_struct; 2640 EV_P = ev_default_loop_ptr = &default_loop_struct;
2626 2659
2627 return ev_default_loop_ptr; 2660 return ev_default_loop_ptr;
2628} 2661}
2629 2662
2630void 2663void
2631ev_loop_fork (EV_P) 2664ev_loop_fork (EV_P) EV_THROW
2632{ 2665{
2633 postfork = 1; /* must be in line with ev_default_fork */ 2666 postfork = 1; /* must be in line with ev_default_fork */
2634} 2667}
2635 2668
2636/*****************************************************************************/ 2669/*****************************************************************************/
2640{ 2673{
2641 EV_CB_INVOKE ((W)w, revents); 2674 EV_CB_INVOKE ((W)w, revents);
2642} 2675}
2643 2676
2644unsigned int 2677unsigned int
2645ev_pending_count (EV_P) 2678ev_pending_count (EV_P) EV_THROW
2646{ 2679{
2647 int pri; 2680 int pri;
2648 unsigned int count = 0; 2681 unsigned int count = 0;
2649 2682
2650 for (pri = NUMPRI; pri--; ) 2683 for (pri = NUMPRI; pri--; )
2654} 2687}
2655 2688
2656void noinline 2689void noinline
2657ev_invoke_pending (EV_P) 2690ev_invoke_pending (EV_P)
2658{ 2691{
2659 int pri; 2692 for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */
2660
2661 for (pri = NUMPRI; pri--; )
2662 while (pendingcnt [pri]) 2693 while (pendingcnt [pendingpri])
2663 { 2694 {
2664 ANPENDING *p = pendings [pri] + --pendingcnt [pri]; 2695 ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri];
2665 2696
2666 p->w->pending = 0; 2697 p->w->pending = 0;
2667 EV_CB_INVOKE (p->w, p->events); 2698 EV_CB_INVOKE (p->w, p->events);
2668 EV_FREQUENT_CHECK; 2699 EV_FREQUENT_CHECK;
2669 } 2700 }
2909 2940
2910 mn_now = ev_rt_now; 2941 mn_now = ev_rt_now;
2911 } 2942 }
2912} 2943}
2913 2944
2914void 2945int
2915ev_run (EV_P_ int flags) 2946ev_run (EV_P_ int flags)
2916{ 2947{
2917#if EV_FEATURE_API 2948#if EV_FEATURE_API
2918 ++loop_depth; 2949 ++loop_depth;
2919#endif 2950#endif
3076 loop_done = EVBREAK_CANCEL; 3107 loop_done = EVBREAK_CANCEL;
3077 3108
3078#if EV_FEATURE_API 3109#if EV_FEATURE_API
3079 --loop_depth; 3110 --loop_depth;
3080#endif 3111#endif
3112
3113 return activecnt;
3081} 3114}
3082 3115
3083void 3116void
3084ev_break (EV_P_ int how) 3117ev_break (EV_P_ int how) EV_THROW
3085{ 3118{
3086 loop_done = how; 3119 loop_done = how;
3087} 3120}
3088 3121
3089void 3122void
3090ev_ref (EV_P) 3123ev_ref (EV_P) EV_THROW
3091{ 3124{
3092 ++activecnt; 3125 ++activecnt;
3093} 3126}
3094 3127
3095void 3128void
3096ev_unref (EV_P) 3129ev_unref (EV_P) EV_THROW
3097{ 3130{
3098 --activecnt; 3131 --activecnt;
3099} 3132}
3100 3133
3101void 3134void
3102ev_now_update (EV_P) 3135ev_now_update (EV_P) EV_THROW
3103{ 3136{
3104 time_update (EV_A_ 1e100); 3137 time_update (EV_A_ 1e100);
3105} 3138}
3106 3139
3107void 3140void
3108ev_suspend (EV_P) 3141ev_suspend (EV_P) EV_THROW
3109{ 3142{
3110 ev_now_update (EV_A); 3143 ev_now_update (EV_A);
3111} 3144}
3112 3145
3113void 3146void
3114ev_resume (EV_P) 3147ev_resume (EV_P) EV_THROW
3115{ 3148{
3116 ev_tstamp mn_prev = mn_now; 3149 ev_tstamp mn_prev = mn_now;
3117 3150
3118 ev_now_update (EV_A); 3151 ev_now_update (EV_A);
3119 timers_reschedule (EV_A_ mn_now - mn_prev); 3152 timers_reschedule (EV_A_ mn_now - mn_prev);
3158 w->pending = 0; 3191 w->pending = 0;
3159 } 3192 }
3160} 3193}
3161 3194
3162int 3195int
3163ev_clear_pending (EV_P_ void *w) 3196ev_clear_pending (EV_P_ void *w) EV_THROW
3164{ 3197{
3165 W w_ = (W)w; 3198 W w_ = (W)w;
3166 int pending = w_->pending; 3199 int pending = w_->pending;
3167 3200
3168 if (expect_true (pending)) 3201 if (expect_true (pending))
3201} 3234}
3202 3235
3203/*****************************************************************************/ 3236/*****************************************************************************/
3204 3237
3205void noinline 3238void noinline
3206ev_io_start (EV_P_ ev_io *w) 3239ev_io_start (EV_P_ ev_io *w) EV_THROW
3207{ 3240{
3208 int fd = w->fd; 3241 int fd = w->fd;
3209 3242
3210 if (expect_false (ev_is_active (w))) 3243 if (expect_false (ev_is_active (w)))
3211 return; 3244 return;
3224 3257
3225 EV_FREQUENT_CHECK; 3258 EV_FREQUENT_CHECK;
3226} 3259}
3227 3260
3228void noinline 3261void noinline
3229ev_io_stop (EV_P_ ev_io *w) 3262ev_io_stop (EV_P_ ev_io *w) EV_THROW
3230{ 3263{
3231 clear_pending (EV_A_ (W)w); 3264 clear_pending (EV_A_ (W)w);
3232 if (expect_false (!ev_is_active (w))) 3265 if (expect_false (!ev_is_active (w)))
3233 return; 3266 return;
3234 3267
3243 3276
3244 EV_FREQUENT_CHECK; 3277 EV_FREQUENT_CHECK;
3245} 3278}
3246 3279
3247void noinline 3280void noinline
3248ev_timer_start (EV_P_ ev_timer *w) 3281ev_timer_start (EV_P_ ev_timer *w) EV_THROW
3249{ 3282{
3250 if (expect_false (ev_is_active (w))) 3283 if (expect_false (ev_is_active (w)))
3251 return; 3284 return;
3252 3285
3253 ev_at (w) += mn_now; 3286 ev_at (w) += mn_now;
3267 3300
3268 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ 3301 /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/
3269} 3302}
3270 3303
3271void noinline 3304void noinline
3272ev_timer_stop (EV_P_ ev_timer *w) 3305ev_timer_stop (EV_P_ ev_timer *w) EV_THROW
3273{ 3306{
3274 clear_pending (EV_A_ (W)w); 3307 clear_pending (EV_A_ (W)w);
3275 if (expect_false (!ev_is_active (w))) 3308 if (expect_false (!ev_is_active (w)))
3276 return; 3309 return;
3277 3310
3297 3330
3298 EV_FREQUENT_CHECK; 3331 EV_FREQUENT_CHECK;
3299} 3332}
3300 3333
3301void noinline 3334void noinline
3302ev_timer_again (EV_P_ ev_timer *w) 3335ev_timer_again (EV_P_ ev_timer *w) EV_THROW
3303{ 3336{
3304 EV_FREQUENT_CHECK; 3337 EV_FREQUENT_CHECK;
3305 3338
3306 clear_pending (EV_A_ (W)w); 3339 clear_pending (EV_A_ (W)w);
3307 3340
3324 3357
3325 EV_FREQUENT_CHECK; 3358 EV_FREQUENT_CHECK;
3326} 3359}
3327 3360
3328ev_tstamp 3361ev_tstamp
3329ev_timer_remaining (EV_P_ ev_timer *w) 3362ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW
3330{ 3363{
3331 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); 3364 return ev_at (w) - (ev_is_active (w) ? mn_now : 0.);
3332} 3365}
3333 3366
3334#if EV_PERIODIC_ENABLE 3367#if EV_PERIODIC_ENABLE
3335void noinline 3368void noinline
3336ev_periodic_start (EV_P_ ev_periodic *w) 3369ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW
3337{ 3370{
3338 if (expect_false (ev_is_active (w))) 3371 if (expect_false (ev_is_active (w)))
3339 return; 3372 return;
3340 3373
3341 if (w->reschedule_cb) 3374 if (w->reschedule_cb)
3361 3394
3362 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ 3395 /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/
3363} 3396}
3364 3397
3365void noinline 3398void noinline
3366ev_periodic_stop (EV_P_ ev_periodic *w) 3399ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW
3367{ 3400{
3368 clear_pending (EV_A_ (W)w); 3401 clear_pending (EV_A_ (W)w);
3369 if (expect_false (!ev_is_active (w))) 3402 if (expect_false (!ev_is_active (w)))
3370 return; 3403 return;
3371 3404
3389 3422
3390 EV_FREQUENT_CHECK; 3423 EV_FREQUENT_CHECK;
3391} 3424}
3392 3425
3393void noinline 3426void noinline
3394ev_periodic_again (EV_P_ ev_periodic *w) 3427ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW
3395{ 3428{
3396 /* TODO: use adjustheap and recalculation */ 3429 /* TODO: use adjustheap and recalculation */
3397 ev_periodic_stop (EV_A_ w); 3430 ev_periodic_stop (EV_A_ w);
3398 ev_periodic_start (EV_A_ w); 3431 ev_periodic_start (EV_A_ w);
3399} 3432}
3404#endif 3437#endif
3405 3438
3406#if EV_SIGNAL_ENABLE 3439#if EV_SIGNAL_ENABLE
3407 3440
3408void noinline 3441void noinline
3409ev_signal_start (EV_P_ ev_signal *w) 3442ev_signal_start (EV_P_ ev_signal *w) EV_THROW
3410{ 3443{
3411 if (expect_false (ev_is_active (w))) 3444 if (expect_false (ev_is_active (w)))
3412 return; 3445 return;
3413 3446
3414 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); 3447 assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG));
3485 3518
3486 EV_FREQUENT_CHECK; 3519 EV_FREQUENT_CHECK;
3487} 3520}
3488 3521
3489void noinline 3522void noinline
3490ev_signal_stop (EV_P_ ev_signal *w) 3523ev_signal_stop (EV_P_ ev_signal *w) EV_THROW
3491{ 3524{
3492 clear_pending (EV_A_ (W)w); 3525 clear_pending (EV_A_ (W)w);
3493 if (expect_false (!ev_is_active (w))) 3526 if (expect_false (!ev_is_active (w)))
3494 return; 3527 return;
3495 3528
3526#endif 3559#endif
3527 3560
3528#if EV_CHILD_ENABLE 3561#if EV_CHILD_ENABLE
3529 3562
3530void 3563void
3531ev_child_start (EV_P_ ev_child *w) 3564ev_child_start (EV_P_ ev_child *w) EV_THROW
3532{ 3565{
3533#if EV_MULTIPLICITY 3566#if EV_MULTIPLICITY
3534 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); 3567 assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr));
3535#endif 3568#endif
3536 if (expect_false (ev_is_active (w))) 3569 if (expect_false (ev_is_active (w)))
3543 3576
3544 EV_FREQUENT_CHECK; 3577 EV_FREQUENT_CHECK;
3545} 3578}
3546 3579
3547void 3580void
3548ev_child_stop (EV_P_ ev_child *w) 3581ev_child_stop (EV_P_ ev_child *w) EV_THROW
3549{ 3582{
3550 clear_pending (EV_A_ (W)w); 3583 clear_pending (EV_A_ (W)w);
3551 if (expect_false (!ev_is_active (w))) 3584 if (expect_false (!ev_is_active (w)))
3552 return; 3585 return;
3553 3586
3720} 3753}
3721 3754
3722inline_size int 3755inline_size int
3723infy_newfd (void) 3756infy_newfd (void)
3724{ 3757{
3725#if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) 3758#if defined IN_CLOEXEC && defined IN_NONBLOCK
3726 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); 3759 int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK);
3727 if (fd >= 0) 3760 if (fd >= 0)
3728 return fd; 3761 return fd;
3729#endif 3762#endif
3730 return inotify_init (); 3763 return inotify_init ();
3805#else 3838#else
3806# define EV_LSTAT(p,b) lstat (p, b) 3839# define EV_LSTAT(p,b) lstat (p, b)
3807#endif 3840#endif
3808 3841
3809void 3842void
3810ev_stat_stat (EV_P_ ev_stat *w) 3843ev_stat_stat (EV_P_ ev_stat *w) EV_THROW
3811{ 3844{
3812 if (lstat (w->path, &w->attr) < 0) 3845 if (lstat (w->path, &w->attr) < 0)
3813 w->attr.st_nlink = 0; 3846 w->attr.st_nlink = 0;
3814 else if (!w->attr.st_nlink) 3847 else if (!w->attr.st_nlink)
3815 w->attr.st_nlink = 1; 3848 w->attr.st_nlink = 1;
3854 ev_feed_event (EV_A_ w, EV_STAT); 3887 ev_feed_event (EV_A_ w, EV_STAT);
3855 } 3888 }
3856} 3889}
3857 3890
3858void 3891void
3859ev_stat_start (EV_P_ ev_stat *w) 3892ev_stat_start (EV_P_ ev_stat *w) EV_THROW
3860{ 3893{
3861 if (expect_false (ev_is_active (w))) 3894 if (expect_false (ev_is_active (w)))
3862 return; 3895 return;
3863 3896
3864 ev_stat_stat (EV_A_ w); 3897 ev_stat_stat (EV_A_ w);
3885 3918
3886 EV_FREQUENT_CHECK; 3919 EV_FREQUENT_CHECK;
3887} 3920}
3888 3921
3889void 3922void
3890ev_stat_stop (EV_P_ ev_stat *w) 3923ev_stat_stop (EV_P_ ev_stat *w) EV_THROW
3891{ 3924{
3892 clear_pending (EV_A_ (W)w); 3925 clear_pending (EV_A_ (W)w);
3893 if (expect_false (!ev_is_active (w))) 3926 if (expect_false (!ev_is_active (w)))
3894 return; 3927 return;
3895 3928
3911} 3944}
3912#endif 3945#endif
3913 3946
3914#if EV_IDLE_ENABLE 3947#if EV_IDLE_ENABLE
3915void 3948void
3916ev_idle_start (EV_P_ ev_idle *w) 3949ev_idle_start (EV_P_ ev_idle *w) EV_THROW
3917{ 3950{
3918 if (expect_false (ev_is_active (w))) 3951 if (expect_false (ev_is_active (w)))
3919 return; 3952 return;
3920 3953
3921 pri_adjust (EV_A_ (W)w); 3954 pri_adjust (EV_A_ (W)w);
3934 3967
3935 EV_FREQUENT_CHECK; 3968 EV_FREQUENT_CHECK;
3936} 3969}
3937 3970
3938void 3971void
3939ev_idle_stop (EV_P_ ev_idle *w) 3972ev_idle_stop (EV_P_ ev_idle *w) EV_THROW
3940{ 3973{
3941 clear_pending (EV_A_ (W)w); 3974 clear_pending (EV_A_ (W)w);
3942 if (expect_false (!ev_is_active (w))) 3975 if (expect_false (!ev_is_active (w)))
3943 return; 3976 return;
3944 3977
3958} 3991}
3959#endif 3992#endif
3960 3993
3961#if EV_PREPARE_ENABLE 3994#if EV_PREPARE_ENABLE
3962void 3995void
3963ev_prepare_start (EV_P_ ev_prepare *w) 3996ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW
3964{ 3997{
3965 if (expect_false (ev_is_active (w))) 3998 if (expect_false (ev_is_active (w)))
3966 return; 3999 return;
3967 4000
3968 EV_FREQUENT_CHECK; 4001 EV_FREQUENT_CHECK;
3973 4006
3974 EV_FREQUENT_CHECK; 4007 EV_FREQUENT_CHECK;
3975} 4008}
3976 4009
3977void 4010void
3978ev_prepare_stop (EV_P_ ev_prepare *w) 4011ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW
3979{ 4012{
3980 clear_pending (EV_A_ (W)w); 4013 clear_pending (EV_A_ (W)w);
3981 if (expect_false (!ev_is_active (w))) 4014 if (expect_false (!ev_is_active (w)))
3982 return; 4015 return;
3983 4016
3996} 4029}
3997#endif 4030#endif
3998 4031
3999#if EV_CHECK_ENABLE 4032#if EV_CHECK_ENABLE
4000void 4033void
4001ev_check_start (EV_P_ ev_check *w) 4034ev_check_start (EV_P_ ev_check *w) EV_THROW
4002{ 4035{
4003 if (expect_false (ev_is_active (w))) 4036 if (expect_false (ev_is_active (w)))
4004 return; 4037 return;
4005 4038
4006 EV_FREQUENT_CHECK; 4039 EV_FREQUENT_CHECK;
4011 4044
4012 EV_FREQUENT_CHECK; 4045 EV_FREQUENT_CHECK;
4013} 4046}
4014 4047
4015void 4048void
4016ev_check_stop (EV_P_ ev_check *w) 4049ev_check_stop (EV_P_ ev_check *w) EV_THROW
4017{ 4050{
4018 clear_pending (EV_A_ (W)w); 4051 clear_pending (EV_A_ (W)w);
4019 if (expect_false (!ev_is_active (w))) 4052 if (expect_false (!ev_is_active (w)))
4020 return; 4053 return;
4021 4054
4034} 4067}
4035#endif 4068#endif
4036 4069
4037#if EV_EMBED_ENABLE 4070#if EV_EMBED_ENABLE
4038void noinline 4071void noinline
4039ev_embed_sweep (EV_P_ ev_embed *w) 4072ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW
4040{ 4073{
4041 ev_run (w->other, EVRUN_NOWAIT); 4074 ev_run (w->other, EVRUN_NOWAIT);
4042} 4075}
4043 4076
4044static void 4077static void
4092 ev_idle_stop (EV_A_ idle); 4125 ev_idle_stop (EV_A_ idle);
4093} 4126}
4094#endif 4127#endif
4095 4128
4096void 4129void
4097ev_embed_start (EV_P_ ev_embed *w) 4130ev_embed_start (EV_P_ ev_embed *w) EV_THROW
4098{ 4131{
4099 if (expect_false (ev_is_active (w))) 4132 if (expect_false (ev_is_active (w)))
4100 return; 4133 return;
4101 4134
4102 { 4135 {
4123 4156
4124 EV_FREQUENT_CHECK; 4157 EV_FREQUENT_CHECK;
4125} 4158}
4126 4159
4127void 4160void
4128ev_embed_stop (EV_P_ ev_embed *w) 4161ev_embed_stop (EV_P_ ev_embed *w) EV_THROW
4129{ 4162{
4130 clear_pending (EV_A_ (W)w); 4163 clear_pending (EV_A_ (W)w);
4131 if (expect_false (!ev_is_active (w))) 4164 if (expect_false (!ev_is_active (w)))
4132 return; 4165 return;
4133 4166
4143} 4176}
4144#endif 4177#endif
4145 4178
4146#if EV_FORK_ENABLE 4179#if EV_FORK_ENABLE
4147void 4180void
4148ev_fork_start (EV_P_ ev_fork *w) 4181ev_fork_start (EV_P_ ev_fork *w) EV_THROW
4149{ 4182{
4150 if (expect_false (ev_is_active (w))) 4183 if (expect_false (ev_is_active (w)))
4151 return; 4184 return;
4152 4185
4153 EV_FREQUENT_CHECK; 4186 EV_FREQUENT_CHECK;
4158 4191
4159 EV_FREQUENT_CHECK; 4192 EV_FREQUENT_CHECK;
4160} 4193}
4161 4194
4162void 4195void
4163ev_fork_stop (EV_P_ ev_fork *w) 4196ev_fork_stop (EV_P_ ev_fork *w) EV_THROW
4164{ 4197{
4165 clear_pending (EV_A_ (W)w); 4198 clear_pending (EV_A_ (W)w);
4166 if (expect_false (!ev_is_active (w))) 4199 if (expect_false (!ev_is_active (w)))
4167 return; 4200 return;
4168 4201
4181} 4214}
4182#endif 4215#endif
4183 4216
4184#if EV_CLEANUP_ENABLE 4217#if EV_CLEANUP_ENABLE
4185void 4218void
4186ev_cleanup_start (EV_P_ ev_cleanup *w) 4219ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW
4187{ 4220{
4188 if (expect_false (ev_is_active (w))) 4221 if (expect_false (ev_is_active (w)))
4189 return; 4222 return;
4190 4223
4191 EV_FREQUENT_CHECK; 4224 EV_FREQUENT_CHECK;
4198 ev_unref (EV_A); 4231 ev_unref (EV_A);
4199 EV_FREQUENT_CHECK; 4232 EV_FREQUENT_CHECK;
4200} 4233}
4201 4234
4202void 4235void
4203ev_cleanup_stop (EV_P_ ev_cleanup *w) 4236ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW
4204{ 4237{
4205 clear_pending (EV_A_ (W)w); 4238 clear_pending (EV_A_ (W)w);
4206 if (expect_false (!ev_is_active (w))) 4239 if (expect_false (!ev_is_active (w)))
4207 return; 4240 return;
4208 4241
4222} 4255}
4223#endif 4256#endif
4224 4257
4225#if EV_ASYNC_ENABLE 4258#if EV_ASYNC_ENABLE
4226void 4259void
4227ev_async_start (EV_P_ ev_async *w) 4260ev_async_start (EV_P_ ev_async *w) EV_THROW
4228{ 4261{
4229 if (expect_false (ev_is_active (w))) 4262 if (expect_false (ev_is_active (w)))
4230 return; 4263 return;
4231 4264
4232 w->sent = 0; 4265 w->sent = 0;
4241 4274
4242 EV_FREQUENT_CHECK; 4275 EV_FREQUENT_CHECK;
4243} 4276}
4244 4277
4245void 4278void
4246ev_async_stop (EV_P_ ev_async *w) 4279ev_async_stop (EV_P_ ev_async *w) EV_THROW
4247{ 4280{
4248 clear_pending (EV_A_ (W)w); 4281 clear_pending (EV_A_ (W)w);
4249 if (expect_false (!ev_is_active (w))) 4282 if (expect_false (!ev_is_active (w)))
4250 return; 4283 return;
4251 4284
4262 4295
4263 EV_FREQUENT_CHECK; 4296 EV_FREQUENT_CHECK;
4264} 4297}
4265 4298
4266void 4299void
4267ev_async_send (EV_P_ ev_async *w) 4300ev_async_send (EV_P_ ev_async *w) EV_THROW
4268{ 4301{
4269 w->sent = 1; 4302 w->sent = 1;
4270 evpipe_write (EV_A_ &async_pending); 4303 evpipe_write (EV_A_ &async_pending);
4271} 4304}
4272#endif 4305#endif
4309 4342
4310 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); 4343 once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io));
4311} 4344}
4312 4345
4313void 4346void
4314ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) 4347ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW
4315{ 4348{
4316 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); 4349 struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once));
4317 4350
4318 if (expect_false (!once)) 4351 if (expect_false (!once))
4319 { 4352 {
4341 4374
4342/*****************************************************************************/ 4375/*****************************************************************************/
4343 4376
4344#if EV_WALK_ENABLE 4377#if EV_WALK_ENABLE
4345void ecb_cold 4378void ecb_cold
4346ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) 4379ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW
4347{ 4380{
4348 int i, j; 4381 int i, j;
4349 ev_watcher_list *wl, *wn; 4382 ev_watcher_list *wl, *wn;
4350 4383
4351 if (types & (EV_IO | EV_EMBED)) 4384 if (types & (EV_IO | EV_EMBED))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines