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 |
… | |
… | |
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 |
… | |
… | |
219 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | |
221 | |
221 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
222 | |
223 | |
223 | /* try to deduce the maximum number of signals on this platform */ |
224 | /* try to deduce the maximum number of signals on this platform */ |
224 | #if defined (EV_NSIG) |
225 | #if defined EV_NSIG |
225 | /* use what's provided */ |
226 | /* use what's provided */ |
226 | #elif defined (NSIG) |
227 | #elif defined NSIG |
227 | # define EV_NSIG (NSIG) |
228 | # define EV_NSIG (NSIG) |
228 | #elif defined(_NSIG) |
229 | #elif defined _NSIG |
229 | # define EV_NSIG (_NSIG) |
230 | # define EV_NSIG (_NSIG) |
230 | #elif defined (SIGMAX) |
231 | #elif defined SIGMAX |
231 | # define EV_NSIG (SIGMAX+1) |
232 | # define EV_NSIG (SIGMAX+1) |
232 | #elif defined (SIG_MAX) |
233 | #elif defined SIG_MAX |
233 | # define EV_NSIG (SIG_MAX+1) |
234 | # define EV_NSIG (SIG_MAX+1) |
234 | #elif defined (_SIG_MAX) |
235 | #elif defined _SIG_MAX |
235 | # define EV_NSIG (_SIG_MAX+1) |
236 | # define EV_NSIG (_SIG_MAX+1) |
236 | #elif defined (MAXSIG) |
237 | #elif defined MAXSIG |
237 | # define EV_NSIG (MAXSIG+1) |
238 | # define EV_NSIG (MAXSIG+1) |
238 | #elif defined (MAX_SIG) |
239 | #elif defined MAX_SIG |
239 | # define EV_NSIG (MAX_SIG+1) |
240 | # define EV_NSIG (MAX_SIG+1) |
240 | #elif defined (SIGARRAYSIZE) |
241 | #elif defined SIGARRAYSIZE |
241 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | #elif defined (_sys_nsig) |
243 | #elif defined _sys_nsig |
243 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | #else |
245 | #else |
245 | # error "unable to find value for NSIG, please report" |
246 | # error "unable to find value for NSIG, please report" |
246 | /* to make it compile regardless, just remove the above line, */ |
247 | /* to make it compile regardless, just remove the above line, */ |
247 | /* but consider reporting it, too! :) */ |
248 | /* but consider reporting it, too! :) */ |
… | |
… | |
259 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # endif |
261 | # endif |
261 | #endif |
262 | #endif |
262 | |
263 | |
263 | #ifndef EV_USE_MONOTONIC |
264 | #ifndef EV_USE_MONOTONIC |
264 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # else |
267 | # else |
267 | # define EV_USE_MONOTONIC 0 |
268 | # define EV_USE_MONOTONIC 0 |
268 | # endif |
269 | # endif |
269 | #endif |
270 | #endif |
… | |
… | |
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 |
… | |
… | |
395 | # define EV_USE_INOTIFY 0 |
396 | # define EV_USE_INOTIFY 0 |
396 | #endif |
397 | #endif |
397 | |
398 | |
398 | #if !EV_USE_NANOSLEEP |
399 | #if !EV_USE_NANOSLEEP |
399 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
400 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
400 | # if !defined(_WIN32) && !defined(__hpux) |
401 | # if !defined _WIN32 && !defined __hpux |
401 | # include <sys/select.h> |
402 | # include <sys/select.h> |
402 | # endif |
403 | # endif |
403 | #endif |
404 | #endif |
404 | |
405 | |
405 | #if EV_USE_INOTIFY |
406 | #if EV_USE_INOTIFY |
… | |
… | |
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 () |
604 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
603 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
605 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
604 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
605 | #elif __xlC__ |
|
|
606 | #define ECB_MEMORY_FENCE __sync () |
606 | #endif |
607 | #endif |
607 | #endif |
608 | #endif |
608 | |
609 | |
609 | #ifndef ECB_MEMORY_FENCE |
610 | #ifndef ECB_MEMORY_FENCE |
610 | #if !ECB_AVOID_PTHREADS |
611 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
622 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
623 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
623 | #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) |
624 | #endif |
625 | #endif |
625 | #endif |
626 | #endif |
626 | |
627 | |
627 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
628 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
628 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
629 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
629 | #endif |
630 | #endif |
630 | |
631 | |
631 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
632 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
632 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
633 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
633 | #endif |
634 | #endif |
634 | |
635 | |
635 | /*****************************************************************************/ |
636 | /*****************************************************************************/ |
636 | |
637 | |
… | |
… | |
1101 | { |
1102 | { |
1102 | write (STDERR_FILENO, msg, strlen (msg)); |
1103 | write (STDERR_FILENO, msg, strlen (msg)); |
1103 | } |
1104 | } |
1104 | #endif |
1105 | #endif |
1105 | |
1106 | |
1106 | static void (*syserr_cb)(const char *msg); |
1107 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1107 | |
1108 | |
1108 | void ecb_cold |
1109 | void ecb_cold |
1109 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1110 | ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW |
1110 | { |
1111 | { |
1111 | syserr_cb = cb; |
1112 | syserr_cb = cb; |
1112 | } |
1113 | } |
1113 | |
1114 | |
1114 | static void noinline ecb_cold |
1115 | static void noinline ecb_cold |
… | |
… | |
1150 | free (ptr); |
1151 | free (ptr); |
1151 | return 0; |
1152 | return 0; |
1152 | #endif |
1153 | #endif |
1153 | } |
1154 | } |
1154 | |
1155 | |
1155 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1156 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1156 | |
1157 | |
1157 | void ecb_cold |
1158 | void ecb_cold |
1158 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1159 | ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW |
1159 | { |
1160 | { |
1160 | alloc = cb; |
1161 | alloc = cb; |
1161 | } |
1162 | } |
1162 | |
1163 | |
1163 | inline_speed void * |
1164 | inline_speed void * |
… | |
… | |
1280 | |
1281 | |
1281 | /*****************************************************************************/ |
1282 | /*****************************************************************************/ |
1282 | |
1283 | |
1283 | #ifndef EV_HAVE_EV_TIME |
1284 | #ifndef EV_HAVE_EV_TIME |
1284 | ev_tstamp |
1285 | ev_tstamp |
1285 | ev_time (void) |
1286 | ev_time (void) EV_THROW |
1286 | { |
1287 | { |
1287 | #if EV_USE_REALTIME |
1288 | #if EV_USE_REALTIME |
1288 | if (expect_true (have_realtime)) |
1289 | if (expect_true (have_realtime)) |
1289 | { |
1290 | { |
1290 | struct timespec ts; |
1291 | struct timespec ts; |
… | |
… | |
1314 | return ev_time (); |
1315 | return ev_time (); |
1315 | } |
1316 | } |
1316 | |
1317 | |
1317 | #if EV_MULTIPLICITY |
1318 | #if EV_MULTIPLICITY |
1318 | ev_tstamp |
1319 | ev_tstamp |
1319 | ev_now (EV_P) |
1320 | ev_now (EV_P) EV_THROW |
1320 | { |
1321 | { |
1321 | return ev_rt_now; |
1322 | return ev_rt_now; |
1322 | } |
1323 | } |
1323 | #endif |
1324 | #endif |
1324 | |
1325 | |
1325 | void |
1326 | void |
1326 | ev_sleep (ev_tstamp delay) |
1327 | ev_sleep (ev_tstamp delay) EV_THROW |
1327 | { |
1328 | { |
1328 | if (delay > 0.) |
1329 | if (delay > 0.) |
1329 | { |
1330 | { |
1330 | #if EV_USE_NANOSLEEP |
1331 | #if EV_USE_NANOSLEEP |
1331 | struct timespec ts; |
1332 | struct timespec ts; |
1332 | |
1333 | |
1333 | EV_TS_SET (ts, delay); |
1334 | EV_TS_SET (ts, delay); |
1334 | nanosleep (&ts, 0); |
1335 | nanosleep (&ts, 0); |
1335 | #elif defined(_WIN32) |
1336 | #elif defined _WIN32 |
1336 | Sleep ((unsigned long)(delay * 1e3)); |
1337 | Sleep ((unsigned long)(delay * 1e3)); |
1337 | #else |
1338 | #else |
1338 | struct timeval tv; |
1339 | struct timeval tv; |
1339 | |
1340 | |
1340 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1341 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1412 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1413 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1413 | { |
1414 | { |
1414 | } |
1415 | } |
1415 | |
1416 | |
1416 | void noinline |
1417 | void noinline |
1417 | ev_feed_event (EV_P_ void *w, int revents) |
1418 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1418 | { |
1419 | { |
1419 | W w_ = (W)w; |
1420 | W w_ = (W)w; |
1420 | int pri = ABSPRI (w_); |
1421 | int pri = ABSPRI (w_); |
1421 | |
1422 | |
1422 | if (expect_false (w_->pending)) |
1423 | if (expect_false (w_->pending)) |
… | |
… | |
1426 | w_->pending = ++pendingcnt [pri]; |
1427 | w_->pending = ++pendingcnt [pri]; |
1427 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1428 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1428 | pendings [pri][w_->pending - 1].w = w_; |
1429 | pendings [pri][w_->pending - 1].w = w_; |
1429 | pendings [pri][w_->pending - 1].events = revents; |
1430 | pendings [pri][w_->pending - 1].events = revents; |
1430 | } |
1431 | } |
|
|
1432 | |
|
|
1433 | pendingpri = NUMPRI - 1; |
1431 | } |
1434 | } |
1432 | |
1435 | |
1433 | inline_speed void |
1436 | inline_speed void |
1434 | feed_reverse (EV_P_ W w) |
1437 | feed_reverse (EV_P_ W w) |
1435 | { |
1438 | { |
… | |
… | |
1481 | if (expect_true (!anfd->reify)) |
1484 | if (expect_true (!anfd->reify)) |
1482 | fd_event_nocheck (EV_A_ fd, revents); |
1485 | fd_event_nocheck (EV_A_ fd, revents); |
1483 | } |
1486 | } |
1484 | |
1487 | |
1485 | void |
1488 | void |
1486 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1489 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1487 | { |
1490 | { |
1488 | if (fd >= 0 && fd < anfdmax) |
1491 | if (fd >= 0 && fd < anfdmax) |
1489 | fd_event_nocheck (EV_A_ fd, revents); |
1492 | fd_event_nocheck (EV_A_ fd, revents); |
1490 | } |
1493 | } |
1491 | |
1494 | |
… | |
… | |
1840 | } |
1843 | } |
1841 | |
1844 | |
1842 | inline_speed void |
1845 | inline_speed void |
1843 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1846 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1844 | { |
1847 | { |
|
|
1848 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1849 | |
1845 | if (expect_true (*flag)) |
1850 | if (expect_true (*flag)) |
1846 | return; |
1851 | return; |
1847 | |
1852 | |
1848 | *flag = 1; |
1853 | *flag = 1; |
1849 | |
1854 | |
… | |
… | |
1868 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | write (evfd, &counter, sizeof (uint64_t)); |
1869 | } |
1874 | } |
1870 | else |
1875 | else |
1871 | #endif |
1876 | #endif |
1872 | { |
1877 | { |
1873 | /* win32 people keep sending patches that change this write() to send() */ |
1878 | #ifdef _WIN32 |
1874 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1879 | WSABUF buf; |
1875 | /* so when you think this write should be a send instead, please find out */ |
1880 | DWORD sent; |
1876 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1881 | buf.buf = &buf; |
1877 | /* tell me. thank you. */ |
1882 | buf.len = 1; |
1878 | /* 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); |
1879 | /* check the ev documentation on how to use this flag */ |
1884 | #else |
1880 | write (evpipe [1], &(evpipe [1]), 1); |
1885 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1886 | #endif |
1881 | } |
1887 | } |
1882 | |
1888 | |
1883 | errno = old_errno; |
1889 | errno = old_errno; |
1884 | } |
1890 | } |
1885 | } |
1891 | } |
… | |
… | |
1900 | read (evfd, &counter, sizeof (uint64_t)); |
1906 | read (evfd, &counter, sizeof (uint64_t)); |
1901 | } |
1907 | } |
1902 | else |
1908 | else |
1903 | #endif |
1909 | #endif |
1904 | { |
1910 | { |
1905 | char dummy; |
1911 | char dummy[4]; |
1906 | /* 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 |
1907 | read (evpipe [0], &dummy, 1); |
1920 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1921 | #endif |
1908 | } |
1922 | } |
1909 | } |
1923 | } |
1910 | |
1924 | |
1911 | pipe_write_skipped = 0; |
1925 | pipe_write_skipped = 0; |
|
|
1926 | |
|
|
1927 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1912 | |
1928 | |
1913 | #if EV_SIGNAL_ENABLE |
1929 | #if EV_SIGNAL_ENABLE |
1914 | if (sig_pending) |
1930 | if (sig_pending) |
1915 | { |
1931 | { |
1916 | sig_pending = 0; |
1932 | sig_pending = 0; |
|
|
1933 | |
|
|
1934 | ECB_MEMORY_FENCE_RELEASE; |
1917 | |
1935 | |
1918 | for (i = EV_NSIG - 1; i--; ) |
1936 | for (i = EV_NSIG - 1; i--; ) |
1919 | if (expect_false (signals [i].pending)) |
1937 | if (expect_false (signals [i].pending)) |
1920 | ev_feed_signal_event (EV_A_ i + 1); |
1938 | ev_feed_signal_event (EV_A_ i + 1); |
1921 | } |
1939 | } |
… | |
… | |
1923 | |
1941 | |
1924 | #if EV_ASYNC_ENABLE |
1942 | #if EV_ASYNC_ENABLE |
1925 | if (async_pending) |
1943 | if (async_pending) |
1926 | { |
1944 | { |
1927 | async_pending = 0; |
1945 | async_pending = 0; |
|
|
1946 | |
|
|
1947 | ECB_MEMORY_FENCE_RELEASE; |
1928 | |
1948 | |
1929 | for (i = asynccnt; i--; ) |
1949 | for (i = asynccnt; i--; ) |
1930 | if (asyncs [i]->sent) |
1950 | if (asyncs [i]->sent) |
1931 | { |
1951 | { |
1932 | asyncs [i]->sent = 0; |
1952 | asyncs [i]->sent = 0; |
… | |
… | |
1937 | } |
1957 | } |
1938 | |
1958 | |
1939 | /*****************************************************************************/ |
1959 | /*****************************************************************************/ |
1940 | |
1960 | |
1941 | void |
1961 | void |
1942 | ev_feed_signal (int signum) |
1962 | ev_feed_signal (int signum) EV_THROW |
1943 | { |
1963 | { |
1944 | #if EV_MULTIPLICITY |
1964 | #if EV_MULTIPLICITY |
1945 | EV_P = signals [signum - 1].loop; |
1965 | EV_P = signals [signum - 1].loop; |
1946 | |
1966 | |
1947 | if (!EV_A) |
1967 | if (!EV_A) |
… | |
… | |
1964 | |
1984 | |
1965 | ev_feed_signal (signum); |
1985 | ev_feed_signal (signum); |
1966 | } |
1986 | } |
1967 | |
1987 | |
1968 | void noinline |
1988 | void noinline |
1969 | ev_feed_signal_event (EV_P_ int signum) |
1989 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1970 | { |
1990 | { |
1971 | WL w; |
1991 | WL w; |
1972 | |
1992 | |
1973 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1993 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1974 | return; |
1994 | return; |
… | |
… | |
2090 | #if EV_USE_SELECT |
2110 | #if EV_USE_SELECT |
2091 | # include "ev_select.c" |
2111 | # include "ev_select.c" |
2092 | #endif |
2112 | #endif |
2093 | |
2113 | |
2094 | int ecb_cold |
2114 | int ecb_cold |
2095 | ev_version_major (void) |
2115 | ev_version_major (void) EV_THROW |
2096 | { |
2116 | { |
2097 | return EV_VERSION_MAJOR; |
2117 | return EV_VERSION_MAJOR; |
2098 | } |
2118 | } |
2099 | |
2119 | |
2100 | int ecb_cold |
2120 | int ecb_cold |
2101 | ev_version_minor (void) |
2121 | ev_version_minor (void) EV_THROW |
2102 | { |
2122 | { |
2103 | return EV_VERSION_MINOR; |
2123 | return EV_VERSION_MINOR; |
2104 | } |
2124 | } |
2105 | |
2125 | |
2106 | /* 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 */ |
… | |
… | |
2114 | || getgid () != getegid (); |
2134 | || getgid () != getegid (); |
2115 | #endif |
2135 | #endif |
2116 | } |
2136 | } |
2117 | |
2137 | |
2118 | unsigned int ecb_cold |
2138 | unsigned int ecb_cold |
2119 | ev_supported_backends (void) |
2139 | ev_supported_backends (void) EV_THROW |
2120 | { |
2140 | { |
2121 | unsigned int flags = 0; |
2141 | unsigned int flags = 0; |
2122 | |
2142 | |
2123 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2143 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2124 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2144 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2128 | |
2148 | |
2129 | return flags; |
2149 | return flags; |
2130 | } |
2150 | } |
2131 | |
2151 | |
2132 | unsigned int ecb_cold |
2152 | unsigned int ecb_cold |
2133 | ev_recommended_backends (void) |
2153 | ev_recommended_backends (void) EV_THROW |
2134 | { |
2154 | { |
2135 | unsigned int flags = ev_supported_backends (); |
2155 | unsigned int flags = ev_supported_backends (); |
2136 | |
2156 | |
2137 | #ifndef __NetBSD__ |
2157 | #ifndef __NetBSD__ |
2138 | /* kqueue is borked on everything but netbsd apparently */ |
2158 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2150 | |
2170 | |
2151 | return flags; |
2171 | return flags; |
2152 | } |
2172 | } |
2153 | |
2173 | |
2154 | unsigned int ecb_cold |
2174 | unsigned int ecb_cold |
2155 | ev_embeddable_backends (void) |
2175 | ev_embeddable_backends (void) EV_THROW |
2156 | { |
2176 | { |
2157 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2177 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2158 | |
2178 | |
2159 | /* 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 */ |
2160 | 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 */ |
… | |
… | |
2162 | |
2182 | |
2163 | return flags; |
2183 | return flags; |
2164 | } |
2184 | } |
2165 | |
2185 | |
2166 | unsigned int |
2186 | unsigned int |
2167 | ev_backend (EV_P) |
2187 | ev_backend (EV_P) EV_THROW |
2168 | { |
2188 | { |
2169 | return backend; |
2189 | return backend; |
2170 | } |
2190 | } |
2171 | |
2191 | |
2172 | #if EV_FEATURE_API |
2192 | #if EV_FEATURE_API |
2173 | unsigned int |
2193 | unsigned int |
2174 | ev_iteration (EV_P) |
2194 | ev_iteration (EV_P) EV_THROW |
2175 | { |
2195 | { |
2176 | return loop_count; |
2196 | return loop_count; |
2177 | } |
2197 | } |
2178 | |
2198 | |
2179 | unsigned int |
2199 | unsigned int |
2180 | ev_depth (EV_P) |
2200 | ev_depth (EV_P) EV_THROW |
2181 | { |
2201 | { |
2182 | return loop_depth; |
2202 | return loop_depth; |
2183 | } |
2203 | } |
2184 | |
2204 | |
2185 | void |
2205 | void |
2186 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2206 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2187 | { |
2207 | { |
2188 | io_blocktime = interval; |
2208 | io_blocktime = interval; |
2189 | } |
2209 | } |
2190 | |
2210 | |
2191 | void |
2211 | void |
2192 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2212 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2193 | { |
2213 | { |
2194 | timeout_blocktime = interval; |
2214 | timeout_blocktime = interval; |
2195 | } |
2215 | } |
2196 | |
2216 | |
2197 | void |
2217 | void |
2198 | ev_set_userdata (EV_P_ void *data) |
2218 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2199 | { |
2219 | { |
2200 | userdata = data; |
2220 | userdata = data; |
2201 | } |
2221 | } |
2202 | |
2222 | |
2203 | void * |
2223 | void * |
2204 | ev_userdata (EV_P) |
2224 | ev_userdata (EV_P) EV_THROW |
2205 | { |
2225 | { |
2206 | return userdata; |
2226 | return userdata; |
2207 | } |
2227 | } |
2208 | |
2228 | |
2209 | void |
2229 | void |
2210 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2230 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2211 | { |
2231 | { |
2212 | invoke_cb = invoke_pending_cb; |
2232 | invoke_cb = invoke_pending_cb; |
2213 | } |
2233 | } |
2214 | |
2234 | |
2215 | void |
2235 | void |
2216 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2236 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2217 | { |
2237 | { |
2218 | release_cb = release; |
2238 | release_cb = release; |
2219 | acquire_cb = acquire; |
2239 | acquire_cb = acquire; |
2220 | } |
2240 | } |
2221 | #endif |
2241 | #endif |
2222 | |
2242 | |
2223 | /* initialise a loop structure, must be zero-initialised */ |
2243 | /* initialise a loop structure, must be zero-initialised */ |
2224 | static void noinline ecb_cold |
2244 | static void noinline ecb_cold |
2225 | loop_init (EV_P_ unsigned int flags) |
2245 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2226 | { |
2246 | { |
2227 | if (!backend) |
2247 | if (!backend) |
2228 | { |
2248 | { |
2229 | origflags = flags; |
2249 | origflags = flags; |
2230 | |
2250 | |
… | |
… | |
2483 | } |
2503 | } |
2484 | |
2504 | |
2485 | #if EV_MULTIPLICITY |
2505 | #if EV_MULTIPLICITY |
2486 | |
2506 | |
2487 | struct ev_loop * ecb_cold |
2507 | struct ev_loop * ecb_cold |
2488 | ev_loop_new (unsigned int flags) |
2508 | ev_loop_new (unsigned int flags) EV_THROW |
2489 | { |
2509 | { |
2490 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2510 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2491 | |
2511 | |
2492 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2512 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2493 | loop_init (EV_A_ flags); |
2513 | loop_init (EV_A_ flags); |
… | |
… | |
2537 | } |
2557 | } |
2538 | #endif |
2558 | #endif |
2539 | |
2559 | |
2540 | #if EV_FEATURE_API |
2560 | #if EV_FEATURE_API |
2541 | void ecb_cold |
2561 | void ecb_cold |
2542 | ev_verify (EV_P) |
2562 | ev_verify (EV_P) EV_THROW |
2543 | { |
2563 | { |
2544 | #if EV_VERIFY |
2564 | #if EV_VERIFY |
2545 | int i; |
2565 | int i; |
2546 | WL w; |
2566 | WL w, w2; |
2547 | |
2567 | |
2548 | assert (activecnt >= -1); |
2568 | assert (activecnt >= -1); |
2549 | |
2569 | |
2550 | assert (fdchangemax >= fdchangecnt); |
2570 | assert (fdchangemax >= fdchangecnt); |
2551 | for (i = 0; i < fdchangecnt; ++i) |
2571 | for (i = 0; i < fdchangecnt; ++i) |
2552 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2572 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2553 | |
2573 | |
2554 | assert (anfdmax >= 0); |
2574 | assert (anfdmax >= 0); |
2555 | for (i = 0; i < anfdmax; ++i) |
2575 | for (i = 0; i < anfdmax; ++i) |
|
|
2576 | { |
|
|
2577 | int j = 0; |
|
|
2578 | |
2556 | for (w = anfds [i].head; w; w = w->next) |
2579 | for (w = w2 = anfds [i].head; w; w = w->next) |
2557 | { |
2580 | { |
2558 | 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 | |
2559 | 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)); |
2560 | 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)); |
2561 | } |
2591 | } |
|
|
2592 | } |
2562 | |
2593 | |
2563 | assert (timermax >= timercnt); |
2594 | assert (timermax >= timercnt); |
2564 | verify_heap (EV_A_ timers, timercnt); |
2595 | verify_heap (EV_A_ timers, timercnt); |
2565 | |
2596 | |
2566 | #if EV_PERIODIC_ENABLE |
2597 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2616 | #if EV_MULTIPLICITY |
2647 | #if EV_MULTIPLICITY |
2617 | struct ev_loop * ecb_cold |
2648 | struct ev_loop * ecb_cold |
2618 | #else |
2649 | #else |
2619 | int |
2650 | int |
2620 | #endif |
2651 | #endif |
2621 | ev_default_loop (unsigned int flags) |
2652 | ev_default_loop (unsigned int flags) EV_THROW |
2622 | { |
2653 | { |
2623 | if (!ev_default_loop_ptr) |
2654 | if (!ev_default_loop_ptr) |
2624 | { |
2655 | { |
2625 | #if EV_MULTIPLICITY |
2656 | #if EV_MULTIPLICITY |
2626 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2657 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2645 | |
2676 | |
2646 | return ev_default_loop_ptr; |
2677 | return ev_default_loop_ptr; |
2647 | } |
2678 | } |
2648 | |
2679 | |
2649 | void |
2680 | void |
2650 | ev_loop_fork (EV_P) |
2681 | ev_loop_fork (EV_P) EV_THROW |
2651 | { |
2682 | { |
2652 | postfork = 1; /* must be in line with ev_default_fork */ |
2683 | postfork = 1; /* must be in line with ev_default_fork */ |
2653 | } |
2684 | } |
2654 | |
2685 | |
2655 | /*****************************************************************************/ |
2686 | /*****************************************************************************/ |
… | |
… | |
2659 | { |
2690 | { |
2660 | EV_CB_INVOKE ((W)w, revents); |
2691 | EV_CB_INVOKE ((W)w, revents); |
2661 | } |
2692 | } |
2662 | |
2693 | |
2663 | unsigned int |
2694 | unsigned int |
2664 | ev_pending_count (EV_P) |
2695 | ev_pending_count (EV_P) EV_THROW |
2665 | { |
2696 | { |
2666 | int pri; |
2697 | int pri; |
2667 | unsigned int count = 0; |
2698 | unsigned int count = 0; |
2668 | |
2699 | |
2669 | for (pri = NUMPRI; pri--; ) |
2700 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2673 | } |
2704 | } |
2674 | |
2705 | |
2675 | void noinline |
2706 | void noinline |
2676 | ev_invoke_pending (EV_P) |
2707 | ev_invoke_pending (EV_P) |
2677 | { |
2708 | { |
2678 | int pri; |
2709 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2679 | |
|
|
2680 | for (pri = NUMPRI; pri--; ) |
|
|
2681 | while (pendingcnt [pri]) |
2710 | while (pendingcnt [pendingpri]) |
2682 | { |
2711 | { |
2683 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2712 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2684 | |
2713 | |
2685 | p->w->pending = 0; |
2714 | p->w->pending = 0; |
2686 | EV_CB_INVOKE (p->w, p->events); |
2715 | EV_CB_INVOKE (p->w, p->events); |
2687 | EV_FREQUENT_CHECK; |
2716 | EV_FREQUENT_CHECK; |
2688 | } |
2717 | } |
… | |
… | |
2928 | |
2957 | |
2929 | mn_now = ev_rt_now; |
2958 | mn_now = ev_rt_now; |
2930 | } |
2959 | } |
2931 | } |
2960 | } |
2932 | |
2961 | |
2933 | void |
2962 | int |
2934 | ev_run (EV_P_ int flags) |
2963 | ev_run (EV_P_ int flags) |
2935 | { |
2964 | { |
2936 | #if EV_FEATURE_API |
2965 | #if EV_FEATURE_API |
2937 | ++loop_depth; |
2966 | ++loop_depth; |
2938 | #endif |
2967 | #endif |
… | |
… | |
3095 | loop_done = EVBREAK_CANCEL; |
3124 | loop_done = EVBREAK_CANCEL; |
3096 | |
3125 | |
3097 | #if EV_FEATURE_API |
3126 | #if EV_FEATURE_API |
3098 | --loop_depth; |
3127 | --loop_depth; |
3099 | #endif |
3128 | #endif |
|
|
3129 | |
|
|
3130 | return activecnt; |
3100 | } |
3131 | } |
3101 | |
3132 | |
3102 | void |
3133 | void |
3103 | ev_break (EV_P_ int how) |
3134 | ev_break (EV_P_ int how) EV_THROW |
3104 | { |
3135 | { |
3105 | loop_done = how; |
3136 | loop_done = how; |
3106 | } |
3137 | } |
3107 | |
3138 | |
3108 | void |
3139 | void |
3109 | ev_ref (EV_P) |
3140 | ev_ref (EV_P) EV_THROW |
3110 | { |
3141 | { |
3111 | ++activecnt; |
3142 | ++activecnt; |
3112 | } |
3143 | } |
3113 | |
3144 | |
3114 | void |
3145 | void |
3115 | ev_unref (EV_P) |
3146 | ev_unref (EV_P) EV_THROW |
3116 | { |
3147 | { |
3117 | --activecnt; |
3148 | --activecnt; |
3118 | } |
3149 | } |
3119 | |
3150 | |
3120 | void |
3151 | void |
3121 | ev_now_update (EV_P) |
3152 | ev_now_update (EV_P) EV_THROW |
3122 | { |
3153 | { |
3123 | time_update (EV_A_ 1e100); |
3154 | time_update (EV_A_ 1e100); |
3124 | } |
3155 | } |
3125 | |
3156 | |
3126 | void |
3157 | void |
3127 | ev_suspend (EV_P) |
3158 | ev_suspend (EV_P) EV_THROW |
3128 | { |
3159 | { |
3129 | ev_now_update (EV_A); |
3160 | ev_now_update (EV_A); |
3130 | } |
3161 | } |
3131 | |
3162 | |
3132 | void |
3163 | void |
3133 | ev_resume (EV_P) |
3164 | ev_resume (EV_P) EV_THROW |
3134 | { |
3165 | { |
3135 | ev_tstamp mn_prev = mn_now; |
3166 | ev_tstamp mn_prev = mn_now; |
3136 | |
3167 | |
3137 | ev_now_update (EV_A); |
3168 | ev_now_update (EV_A); |
3138 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3169 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3177 | w->pending = 0; |
3208 | w->pending = 0; |
3178 | } |
3209 | } |
3179 | } |
3210 | } |
3180 | |
3211 | |
3181 | int |
3212 | int |
3182 | ev_clear_pending (EV_P_ void *w) |
3213 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3183 | { |
3214 | { |
3184 | W w_ = (W)w; |
3215 | W w_ = (W)w; |
3185 | int pending = w_->pending; |
3216 | int pending = w_->pending; |
3186 | |
3217 | |
3187 | if (expect_true (pending)) |
3218 | if (expect_true (pending)) |
… | |
… | |
3220 | } |
3251 | } |
3221 | |
3252 | |
3222 | /*****************************************************************************/ |
3253 | /*****************************************************************************/ |
3223 | |
3254 | |
3224 | void noinline |
3255 | void noinline |
3225 | ev_io_start (EV_P_ ev_io *w) |
3256 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3226 | { |
3257 | { |
3227 | int fd = w->fd; |
3258 | int fd = w->fd; |
3228 | |
3259 | |
3229 | if (expect_false (ev_is_active (w))) |
3260 | if (expect_false (ev_is_active (w))) |
3230 | return; |
3261 | return; |
… | |
… | |
3236 | |
3267 | |
3237 | ev_start (EV_A_ (W)w, 1); |
3268 | ev_start (EV_A_ (W)w, 1); |
3238 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3269 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3239 | wlist_add (&anfds[fd].head, (WL)w); |
3270 | wlist_add (&anfds[fd].head, (WL)w); |
3240 | |
3271 | |
|
|
3272 | /* common bug, apparently */ |
|
|
3273 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3274 | |
3241 | 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); |
3242 | w->events &= ~EV__IOFDSET; |
3276 | w->events &= ~EV__IOFDSET; |
3243 | |
3277 | |
3244 | EV_FREQUENT_CHECK; |
3278 | EV_FREQUENT_CHECK; |
3245 | } |
3279 | } |
3246 | |
3280 | |
3247 | void noinline |
3281 | void noinline |
3248 | ev_io_stop (EV_P_ ev_io *w) |
3282 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3249 | { |
3283 | { |
3250 | clear_pending (EV_A_ (W)w); |
3284 | clear_pending (EV_A_ (W)w); |
3251 | if (expect_false (!ev_is_active (w))) |
3285 | if (expect_false (!ev_is_active (w))) |
3252 | return; |
3286 | return; |
3253 | |
3287 | |
… | |
… | |
3262 | |
3296 | |
3263 | EV_FREQUENT_CHECK; |
3297 | EV_FREQUENT_CHECK; |
3264 | } |
3298 | } |
3265 | |
3299 | |
3266 | void noinline |
3300 | void noinline |
3267 | ev_timer_start (EV_P_ ev_timer *w) |
3301 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3268 | { |
3302 | { |
3269 | if (expect_false (ev_is_active (w))) |
3303 | if (expect_false (ev_is_active (w))) |
3270 | return; |
3304 | return; |
3271 | |
3305 | |
3272 | ev_at (w) += mn_now; |
3306 | ev_at (w) += mn_now; |
… | |
… | |
3286 | |
3320 | |
3287 | /*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));*/ |
3288 | } |
3322 | } |
3289 | |
3323 | |
3290 | void noinline |
3324 | void noinline |
3291 | ev_timer_stop (EV_P_ ev_timer *w) |
3325 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3292 | { |
3326 | { |
3293 | clear_pending (EV_A_ (W)w); |
3327 | clear_pending (EV_A_ (W)w); |
3294 | if (expect_false (!ev_is_active (w))) |
3328 | if (expect_false (!ev_is_active (w))) |
3295 | return; |
3329 | return; |
3296 | |
3330 | |
… | |
… | |
3316 | |
3350 | |
3317 | EV_FREQUENT_CHECK; |
3351 | EV_FREQUENT_CHECK; |
3318 | } |
3352 | } |
3319 | |
3353 | |
3320 | void noinline |
3354 | void noinline |
3321 | ev_timer_again (EV_P_ ev_timer *w) |
3355 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3322 | { |
3356 | { |
3323 | EV_FREQUENT_CHECK; |
3357 | EV_FREQUENT_CHECK; |
3324 | |
3358 | |
3325 | clear_pending (EV_A_ (W)w); |
3359 | clear_pending (EV_A_ (W)w); |
3326 | |
3360 | |
… | |
… | |
3343 | |
3377 | |
3344 | EV_FREQUENT_CHECK; |
3378 | EV_FREQUENT_CHECK; |
3345 | } |
3379 | } |
3346 | |
3380 | |
3347 | ev_tstamp |
3381 | ev_tstamp |
3348 | ev_timer_remaining (EV_P_ ev_timer *w) |
3382 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3349 | { |
3383 | { |
3350 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3384 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3351 | } |
3385 | } |
3352 | |
3386 | |
3353 | #if EV_PERIODIC_ENABLE |
3387 | #if EV_PERIODIC_ENABLE |
3354 | void noinline |
3388 | void noinline |
3355 | ev_periodic_start (EV_P_ ev_periodic *w) |
3389 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3356 | { |
3390 | { |
3357 | if (expect_false (ev_is_active (w))) |
3391 | if (expect_false (ev_is_active (w))) |
3358 | return; |
3392 | return; |
3359 | |
3393 | |
3360 | if (w->reschedule_cb) |
3394 | if (w->reschedule_cb) |
… | |
… | |
3380 | |
3414 | |
3381 | /*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));*/ |
3382 | } |
3416 | } |
3383 | |
3417 | |
3384 | void noinline |
3418 | void noinline |
3385 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3419 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3386 | { |
3420 | { |
3387 | clear_pending (EV_A_ (W)w); |
3421 | clear_pending (EV_A_ (W)w); |
3388 | if (expect_false (!ev_is_active (w))) |
3422 | if (expect_false (!ev_is_active (w))) |
3389 | return; |
3423 | return; |
3390 | |
3424 | |
… | |
… | |
3408 | |
3442 | |
3409 | EV_FREQUENT_CHECK; |
3443 | EV_FREQUENT_CHECK; |
3410 | } |
3444 | } |
3411 | |
3445 | |
3412 | void noinline |
3446 | void noinline |
3413 | ev_periodic_again (EV_P_ ev_periodic *w) |
3447 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3414 | { |
3448 | { |
3415 | /* TODO: use adjustheap and recalculation */ |
3449 | /* TODO: use adjustheap and recalculation */ |
3416 | ev_periodic_stop (EV_A_ w); |
3450 | ev_periodic_stop (EV_A_ w); |
3417 | ev_periodic_start (EV_A_ w); |
3451 | ev_periodic_start (EV_A_ w); |
3418 | } |
3452 | } |
… | |
… | |
3423 | #endif |
3457 | #endif |
3424 | |
3458 | |
3425 | #if EV_SIGNAL_ENABLE |
3459 | #if EV_SIGNAL_ENABLE |
3426 | |
3460 | |
3427 | void noinline |
3461 | void noinline |
3428 | ev_signal_start (EV_P_ ev_signal *w) |
3462 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3429 | { |
3463 | { |
3430 | if (expect_false (ev_is_active (w))) |
3464 | if (expect_false (ev_is_active (w))) |
3431 | return; |
3465 | return; |
3432 | |
3466 | |
3433 | 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)); |
… | |
… | |
3504 | |
3538 | |
3505 | EV_FREQUENT_CHECK; |
3539 | EV_FREQUENT_CHECK; |
3506 | } |
3540 | } |
3507 | |
3541 | |
3508 | void noinline |
3542 | void noinline |
3509 | ev_signal_stop (EV_P_ ev_signal *w) |
3543 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3510 | { |
3544 | { |
3511 | clear_pending (EV_A_ (W)w); |
3545 | clear_pending (EV_A_ (W)w); |
3512 | if (expect_false (!ev_is_active (w))) |
3546 | if (expect_false (!ev_is_active (w))) |
3513 | return; |
3547 | return; |
3514 | |
3548 | |
… | |
… | |
3545 | #endif |
3579 | #endif |
3546 | |
3580 | |
3547 | #if EV_CHILD_ENABLE |
3581 | #if EV_CHILD_ENABLE |
3548 | |
3582 | |
3549 | void |
3583 | void |
3550 | ev_child_start (EV_P_ ev_child *w) |
3584 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3551 | { |
3585 | { |
3552 | #if EV_MULTIPLICITY |
3586 | #if EV_MULTIPLICITY |
3553 | 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)); |
3554 | #endif |
3588 | #endif |
3555 | if (expect_false (ev_is_active (w))) |
3589 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3562 | |
3596 | |
3563 | EV_FREQUENT_CHECK; |
3597 | EV_FREQUENT_CHECK; |
3564 | } |
3598 | } |
3565 | |
3599 | |
3566 | void |
3600 | void |
3567 | ev_child_stop (EV_P_ ev_child *w) |
3601 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3568 | { |
3602 | { |
3569 | clear_pending (EV_A_ (W)w); |
3603 | clear_pending (EV_A_ (W)w); |
3570 | if (expect_false (!ev_is_active (w))) |
3604 | if (expect_false (!ev_is_active (w))) |
3571 | return; |
3605 | return; |
3572 | |
3606 | |
… | |
… | |
3739 | } |
3773 | } |
3740 | |
3774 | |
3741 | inline_size int |
3775 | inline_size int |
3742 | infy_newfd (void) |
3776 | infy_newfd (void) |
3743 | { |
3777 | { |
3744 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3778 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3745 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3779 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3746 | if (fd >= 0) |
3780 | if (fd >= 0) |
3747 | return fd; |
3781 | return fd; |
3748 | #endif |
3782 | #endif |
3749 | return inotify_init (); |
3783 | return inotify_init (); |
… | |
… | |
3824 | #else |
3858 | #else |
3825 | # define EV_LSTAT(p,b) lstat (p, b) |
3859 | # define EV_LSTAT(p,b) lstat (p, b) |
3826 | #endif |
3860 | #endif |
3827 | |
3861 | |
3828 | void |
3862 | void |
3829 | ev_stat_stat (EV_P_ ev_stat *w) |
3863 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3830 | { |
3864 | { |
3831 | if (lstat (w->path, &w->attr) < 0) |
3865 | if (lstat (w->path, &w->attr) < 0) |
3832 | w->attr.st_nlink = 0; |
3866 | w->attr.st_nlink = 0; |
3833 | else if (!w->attr.st_nlink) |
3867 | else if (!w->attr.st_nlink) |
3834 | w->attr.st_nlink = 1; |
3868 | w->attr.st_nlink = 1; |
… | |
… | |
3873 | ev_feed_event (EV_A_ w, EV_STAT); |
3907 | ev_feed_event (EV_A_ w, EV_STAT); |
3874 | } |
3908 | } |
3875 | } |
3909 | } |
3876 | |
3910 | |
3877 | void |
3911 | void |
3878 | ev_stat_start (EV_P_ ev_stat *w) |
3912 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3879 | { |
3913 | { |
3880 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3881 | return; |
3915 | return; |
3882 | |
3916 | |
3883 | ev_stat_stat (EV_A_ w); |
3917 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3904 | |
3938 | |
3905 | EV_FREQUENT_CHECK; |
3939 | EV_FREQUENT_CHECK; |
3906 | } |
3940 | } |
3907 | |
3941 | |
3908 | void |
3942 | void |
3909 | ev_stat_stop (EV_P_ ev_stat *w) |
3943 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3910 | { |
3944 | { |
3911 | clear_pending (EV_A_ (W)w); |
3945 | clear_pending (EV_A_ (W)w); |
3912 | if (expect_false (!ev_is_active (w))) |
3946 | if (expect_false (!ev_is_active (w))) |
3913 | return; |
3947 | return; |
3914 | |
3948 | |
… | |
… | |
3930 | } |
3964 | } |
3931 | #endif |
3965 | #endif |
3932 | |
3966 | |
3933 | #if EV_IDLE_ENABLE |
3967 | #if EV_IDLE_ENABLE |
3934 | void |
3968 | void |
3935 | ev_idle_start (EV_P_ ev_idle *w) |
3969 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3936 | { |
3970 | { |
3937 | if (expect_false (ev_is_active (w))) |
3971 | if (expect_false (ev_is_active (w))) |
3938 | return; |
3972 | return; |
3939 | |
3973 | |
3940 | pri_adjust (EV_A_ (W)w); |
3974 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3953 | |
3987 | |
3954 | EV_FREQUENT_CHECK; |
3988 | EV_FREQUENT_CHECK; |
3955 | } |
3989 | } |
3956 | |
3990 | |
3957 | void |
3991 | void |
3958 | ev_idle_stop (EV_P_ ev_idle *w) |
3992 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3959 | { |
3993 | { |
3960 | clear_pending (EV_A_ (W)w); |
3994 | clear_pending (EV_A_ (W)w); |
3961 | if (expect_false (!ev_is_active (w))) |
3995 | if (expect_false (!ev_is_active (w))) |
3962 | return; |
3996 | return; |
3963 | |
3997 | |
… | |
… | |
3977 | } |
4011 | } |
3978 | #endif |
4012 | #endif |
3979 | |
4013 | |
3980 | #if EV_PREPARE_ENABLE |
4014 | #if EV_PREPARE_ENABLE |
3981 | void |
4015 | void |
3982 | ev_prepare_start (EV_P_ ev_prepare *w) |
4016 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3983 | { |
4017 | { |
3984 | if (expect_false (ev_is_active (w))) |
4018 | if (expect_false (ev_is_active (w))) |
3985 | return; |
4019 | return; |
3986 | |
4020 | |
3987 | EV_FREQUENT_CHECK; |
4021 | EV_FREQUENT_CHECK; |
… | |
… | |
3992 | |
4026 | |
3993 | EV_FREQUENT_CHECK; |
4027 | EV_FREQUENT_CHECK; |
3994 | } |
4028 | } |
3995 | |
4029 | |
3996 | void |
4030 | void |
3997 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4031 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3998 | { |
4032 | { |
3999 | clear_pending (EV_A_ (W)w); |
4033 | clear_pending (EV_A_ (W)w); |
4000 | if (expect_false (!ev_is_active (w))) |
4034 | if (expect_false (!ev_is_active (w))) |
4001 | return; |
4035 | return; |
4002 | |
4036 | |
… | |
… | |
4015 | } |
4049 | } |
4016 | #endif |
4050 | #endif |
4017 | |
4051 | |
4018 | #if EV_CHECK_ENABLE |
4052 | #if EV_CHECK_ENABLE |
4019 | void |
4053 | void |
4020 | ev_check_start (EV_P_ ev_check *w) |
4054 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4021 | { |
4055 | { |
4022 | if (expect_false (ev_is_active (w))) |
4056 | if (expect_false (ev_is_active (w))) |
4023 | return; |
4057 | return; |
4024 | |
4058 | |
4025 | EV_FREQUENT_CHECK; |
4059 | EV_FREQUENT_CHECK; |
… | |
… | |
4030 | |
4064 | |
4031 | EV_FREQUENT_CHECK; |
4065 | EV_FREQUENT_CHECK; |
4032 | } |
4066 | } |
4033 | |
4067 | |
4034 | void |
4068 | void |
4035 | ev_check_stop (EV_P_ ev_check *w) |
4069 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4036 | { |
4070 | { |
4037 | clear_pending (EV_A_ (W)w); |
4071 | clear_pending (EV_A_ (W)w); |
4038 | if (expect_false (!ev_is_active (w))) |
4072 | if (expect_false (!ev_is_active (w))) |
4039 | return; |
4073 | return; |
4040 | |
4074 | |
… | |
… | |
4053 | } |
4087 | } |
4054 | #endif |
4088 | #endif |
4055 | |
4089 | |
4056 | #if EV_EMBED_ENABLE |
4090 | #if EV_EMBED_ENABLE |
4057 | void noinline |
4091 | void noinline |
4058 | ev_embed_sweep (EV_P_ ev_embed *w) |
4092 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4059 | { |
4093 | { |
4060 | ev_run (w->other, EVRUN_NOWAIT); |
4094 | ev_run (w->other, EVRUN_NOWAIT); |
4061 | } |
4095 | } |
4062 | |
4096 | |
4063 | static void |
4097 | static void |
… | |
… | |
4111 | ev_idle_stop (EV_A_ idle); |
4145 | ev_idle_stop (EV_A_ idle); |
4112 | } |
4146 | } |
4113 | #endif |
4147 | #endif |
4114 | |
4148 | |
4115 | void |
4149 | void |
4116 | ev_embed_start (EV_P_ ev_embed *w) |
4150 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4117 | { |
4151 | { |
4118 | if (expect_false (ev_is_active (w))) |
4152 | if (expect_false (ev_is_active (w))) |
4119 | return; |
4153 | return; |
4120 | |
4154 | |
4121 | { |
4155 | { |
… | |
… | |
4142 | |
4176 | |
4143 | EV_FREQUENT_CHECK; |
4177 | EV_FREQUENT_CHECK; |
4144 | } |
4178 | } |
4145 | |
4179 | |
4146 | void |
4180 | void |
4147 | ev_embed_stop (EV_P_ ev_embed *w) |
4181 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4148 | { |
4182 | { |
4149 | clear_pending (EV_A_ (W)w); |
4183 | clear_pending (EV_A_ (W)w); |
4150 | if (expect_false (!ev_is_active (w))) |
4184 | if (expect_false (!ev_is_active (w))) |
4151 | return; |
4185 | return; |
4152 | |
4186 | |
… | |
… | |
4162 | } |
4196 | } |
4163 | #endif |
4197 | #endif |
4164 | |
4198 | |
4165 | #if EV_FORK_ENABLE |
4199 | #if EV_FORK_ENABLE |
4166 | void |
4200 | void |
4167 | ev_fork_start (EV_P_ ev_fork *w) |
4201 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4168 | { |
4202 | { |
4169 | if (expect_false (ev_is_active (w))) |
4203 | if (expect_false (ev_is_active (w))) |
4170 | return; |
4204 | return; |
4171 | |
4205 | |
4172 | EV_FREQUENT_CHECK; |
4206 | EV_FREQUENT_CHECK; |
… | |
… | |
4177 | |
4211 | |
4178 | EV_FREQUENT_CHECK; |
4212 | EV_FREQUENT_CHECK; |
4179 | } |
4213 | } |
4180 | |
4214 | |
4181 | void |
4215 | void |
4182 | ev_fork_stop (EV_P_ ev_fork *w) |
4216 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4183 | { |
4217 | { |
4184 | clear_pending (EV_A_ (W)w); |
4218 | clear_pending (EV_A_ (W)w); |
4185 | if (expect_false (!ev_is_active (w))) |
4219 | if (expect_false (!ev_is_active (w))) |
4186 | return; |
4220 | return; |
4187 | |
4221 | |
… | |
… | |
4200 | } |
4234 | } |
4201 | #endif |
4235 | #endif |
4202 | |
4236 | |
4203 | #if EV_CLEANUP_ENABLE |
4237 | #if EV_CLEANUP_ENABLE |
4204 | void |
4238 | void |
4205 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4239 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4206 | { |
4240 | { |
4207 | if (expect_false (ev_is_active (w))) |
4241 | if (expect_false (ev_is_active (w))) |
4208 | return; |
4242 | return; |
4209 | |
4243 | |
4210 | EV_FREQUENT_CHECK; |
4244 | EV_FREQUENT_CHECK; |
… | |
… | |
4217 | ev_unref (EV_A); |
4251 | ev_unref (EV_A); |
4218 | EV_FREQUENT_CHECK; |
4252 | EV_FREQUENT_CHECK; |
4219 | } |
4253 | } |
4220 | |
4254 | |
4221 | void |
4255 | void |
4222 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4256 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4223 | { |
4257 | { |
4224 | clear_pending (EV_A_ (W)w); |
4258 | clear_pending (EV_A_ (W)w); |
4225 | if (expect_false (!ev_is_active (w))) |
4259 | if (expect_false (!ev_is_active (w))) |
4226 | return; |
4260 | return; |
4227 | |
4261 | |
… | |
… | |
4241 | } |
4275 | } |
4242 | #endif |
4276 | #endif |
4243 | |
4277 | |
4244 | #if EV_ASYNC_ENABLE |
4278 | #if EV_ASYNC_ENABLE |
4245 | void |
4279 | void |
4246 | ev_async_start (EV_P_ ev_async *w) |
4280 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4247 | { |
4281 | { |
4248 | if (expect_false (ev_is_active (w))) |
4282 | if (expect_false (ev_is_active (w))) |
4249 | return; |
4283 | return; |
4250 | |
4284 | |
4251 | w->sent = 0; |
4285 | w->sent = 0; |
… | |
… | |
4260 | |
4294 | |
4261 | EV_FREQUENT_CHECK; |
4295 | EV_FREQUENT_CHECK; |
4262 | } |
4296 | } |
4263 | |
4297 | |
4264 | void |
4298 | void |
4265 | ev_async_stop (EV_P_ ev_async *w) |
4299 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4266 | { |
4300 | { |
4267 | clear_pending (EV_A_ (W)w); |
4301 | clear_pending (EV_A_ (W)w); |
4268 | if (expect_false (!ev_is_active (w))) |
4302 | if (expect_false (!ev_is_active (w))) |
4269 | return; |
4303 | return; |
4270 | |
4304 | |
… | |
… | |
4281 | |
4315 | |
4282 | EV_FREQUENT_CHECK; |
4316 | EV_FREQUENT_CHECK; |
4283 | } |
4317 | } |
4284 | |
4318 | |
4285 | void |
4319 | void |
4286 | ev_async_send (EV_P_ ev_async *w) |
4320 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4287 | { |
4321 | { |
4288 | w->sent = 1; |
4322 | w->sent = 1; |
4289 | evpipe_write (EV_A_ &async_pending); |
4323 | evpipe_write (EV_A_ &async_pending); |
4290 | } |
4324 | } |
4291 | #endif |
4325 | #endif |
… | |
… | |
4328 | |
4362 | |
4329 | 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)); |
4330 | } |
4364 | } |
4331 | |
4365 | |
4332 | void |
4366 | void |
4333 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4367 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4334 | { |
4368 | { |
4335 | 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)); |
4336 | |
4370 | |
4337 | if (expect_false (!once)) |
4371 | if (expect_false (!once)) |
4338 | { |
4372 | { |
… | |
… | |
4360 | |
4394 | |
4361 | /*****************************************************************************/ |
4395 | /*****************************************************************************/ |
4362 | |
4396 | |
4363 | #if EV_WALK_ENABLE |
4397 | #if EV_WALK_ENABLE |
4364 | void ecb_cold |
4398 | void ecb_cold |
4365 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4399 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4366 | { |
4400 | { |
4367 | int i, j; |
4401 | int i, j; |
4368 | ev_watcher_list *wl, *wn; |
4402 | ev_watcher_list *wl, *wn; |
4369 | |
4403 | |
4370 | if (types & (EV_IO | EV_EMBED)) |
4404 | if (types & (EV_IO | EV_EMBED)) |