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> |
… | |
… | |
507 | */ |
504 | */ |
508 | |
505 | |
509 | #ifndef ECB_H |
506 | #ifndef ECB_H |
510 | #define ECB_H |
507 | #define ECB_H |
511 | |
508 | |
|
|
509 | /* 16 bits major, 16 bits minor */ |
|
|
510 | #define ECB_VERSION 0x00010002 |
|
|
511 | |
512 | #ifdef _WIN32 |
512 | #ifdef _WIN32 |
513 | typedef signed char int8_t; |
513 | typedef signed char int8_t; |
514 | typedef unsigned char uint8_t; |
514 | typedef unsigned char uint8_t; |
515 | typedef signed short int16_t; |
515 | typedef signed short int16_t; |
516 | typedef unsigned short uint16_t; |
516 | typedef unsigned short uint16_t; |
… | |
… | |
521 | typedef unsigned long long uint64_t; |
521 | typedef unsigned long long uint64_t; |
522 | #else /* _MSC_VER || __BORLANDC__ */ |
522 | #else /* _MSC_VER || __BORLANDC__ */ |
523 | typedef signed __int64 int64_t; |
523 | typedef signed __int64 int64_t; |
524 | typedef unsigned __int64 uint64_t; |
524 | typedef unsigned __int64 uint64_t; |
525 | #endif |
525 | #endif |
|
|
526 | #ifdef _WIN64 |
|
|
527 | #define ECB_PTRSIZE 8 |
|
|
528 | typedef uint64_t uintptr_t; |
|
|
529 | typedef int64_t intptr_t; |
|
|
530 | #else |
|
|
531 | #define ECB_PTRSIZE 4 |
|
|
532 | typedef uint32_t uintptr_t; |
|
|
533 | typedef int32_t intptr_t; |
|
|
534 | #endif |
526 | #else |
535 | #else |
527 | #include <inttypes.h> |
536 | #include <inttypes.h> |
|
|
537 | #if UINTMAX_MAX > 0xffffffffU |
|
|
538 | #define ECB_PTRSIZE 8 |
|
|
539 | #else |
|
|
540 | #define ECB_PTRSIZE 4 |
|
|
541 | #endif |
528 | #endif |
542 | #endif |
529 | |
543 | |
530 | /* many compilers define _GNUC_ to some versions but then only implement |
544 | /* many compilers define _GNUC_ to some versions but then only implement |
531 | * what their idiot authors think are the "more important" extensions, |
545 | * what their idiot authors think are the "more important" extensions, |
532 | * causing enormous grief in return for some better fake benchmark numbers. |
546 | * causing enormous grief in return for some better fake benchmark numbers. |
533 | * or so. |
547 | * or so. |
534 | * we try to detect these and simply assume they are not gcc - if they have |
548 | * 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. |
549 | * an issue with that they should have done it right in the first place. |
536 | */ |
550 | */ |
537 | #ifndef ECB_GCC_VERSION |
551 | #ifndef ECB_GCC_VERSION |
538 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
552 | #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 |
553 | #define ECB_GCC_VERSION(major,minor) 0 |
540 | #else |
554 | #else |
541 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
555 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
542 | #endif |
556 | #endif |
543 | #endif |
557 | #endif |
544 | |
558 | |
|
|
559 | #define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ |
|
|
560 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
561 | #define ECB_C11 (__STDC_VERSION__ >= 201112L) |
|
|
562 | #define ECB_CPP (__cplusplus+0) |
|
|
563 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
564 | |
|
|
565 | #if ECB_CPP |
|
|
566 | #define ECB_EXTERN_C extern "C" |
|
|
567 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
|
|
568 | #define ECB_EXTERN_C_END } |
|
|
569 | #else |
|
|
570 | #define ECB_EXTERN_C extern |
|
|
571 | #define ECB_EXTERN_C_BEG |
|
|
572 | #define ECB_EXTERN_C_END |
|
|
573 | #endif |
|
|
574 | |
545 | /*****************************************************************************/ |
575 | /*****************************************************************************/ |
546 | |
576 | |
547 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
577 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
548 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
578 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
549 | |
579 | |
550 | #if ECB_NO_THREADS |
580 | #if ECB_NO_THREADS |
551 | # define ECB_NO_SMP 1 |
581 | #define ECB_NO_SMP 1 |
552 | #endif |
582 | #endif |
553 | |
583 | |
554 | #if ECB_NO_THREADS || ECB_NO_SMP |
584 | #if ECB_NO_SMP |
555 | #define ECB_MEMORY_FENCE do { } while (0) |
585 | #define ECB_MEMORY_FENCE do { } while (0) |
556 | #endif |
586 | #endif |
557 | |
587 | |
558 | #ifndef ECB_MEMORY_FENCE |
588 | #ifndef ECB_MEMORY_FENCE |
559 | #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
589 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
560 | #if __i386 || __i386__ |
590 | #if __i386 || __i386__ |
561 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
591 | #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 */ |
592 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
563 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
593 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
564 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
594 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
565 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
595 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
566 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
596 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
567 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
597 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
568 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
598 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
599 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
570 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
600 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
571 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
601 | || 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") |
602 | #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__ ) \ |
603 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
574 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
604 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
575 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
605 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
576 | #elif __sparc || __sparc__ |
606 | #elif __sparc || __sparc__ |
577 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
607 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
578 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
608 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
579 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
609 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
580 | #elif defined(__s390__) || defined(__s390x__) |
610 | #elif defined __s390__ || defined __s390x__ |
581 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
611 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
582 | #elif defined(__mips__) |
612 | #elif defined __mips__ |
583 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
613 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
614 | #elif defined __alpha__ |
|
|
615 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
|
|
616 | #elif defined __hppa__ |
|
|
617 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory") |
|
|
618 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
|
|
619 | #elif defined __ia64__ |
|
|
620 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory") |
584 | #endif |
621 | #endif |
585 | #endif |
622 | #endif |
586 | #endif |
623 | #endif |
587 | |
624 | |
588 | #ifndef ECB_MEMORY_FENCE |
625 | #ifndef ECB_MEMORY_FENCE |
|
|
626 | #if ECB_GCC_VERSION(4,7) |
|
|
627 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
|
|
628 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
|
|
629 | |
|
|
630 | /* The __has_feature syntax from clang is so misdesigned that we cannot use it |
|
|
631 | * without risking compile time errors with other compilers. We *could* |
|
|
632 | * define our own ecb_clang_has_feature, but I just can't be bothered to work |
|
|
633 | * around this shit time and again. |
|
|
634 | * #elif defined __clang && __has_feature (cxx_atomic) |
|
|
635 | * // see comment below (stdatomic.h) about the C11 memory model. |
|
|
636 | * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
|
|
637 | */ |
|
|
638 | |
589 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) |
639 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
590 | #define ECB_MEMORY_FENCE __sync_synchronize () |
640 | #define ECB_MEMORY_FENCE __sync_synchronize () |
591 | /*#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 ); }) */ |
|
|
593 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
641 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
594 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
642 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
595 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
643 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
596 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
644 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
597 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
645 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
598 | #elif defined(_WIN32) |
646 | #elif defined _WIN32 |
599 | #include <WinNT.h> |
647 | #include <WinNT.h> |
600 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
648 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
601 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
649 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
602 | #include <mbarrier.h> |
650 | #include <mbarrier.h> |
603 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
651 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
604 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
652 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
605 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
653 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
606 | #elif __xlC__ |
654 | #elif __xlC__ |
607 | #define ECB_MEMORY_FENCE __sync () |
655 | #define ECB_MEMORY_FENCE __sync () |
|
|
656 | #endif |
|
|
657 | #endif |
|
|
658 | |
|
|
659 | #ifndef ECB_MEMORY_FENCE |
|
|
660 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
|
|
661 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
|
|
662 | /* not just C11 atomics and atomic accesses */ |
|
|
663 | #include <stdatomic.h> |
|
|
664 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
665 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
666 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
667 | /* for most usages, or gcc and clang have a bug */ |
|
|
668 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
669 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
670 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
608 | #endif |
671 | #endif |
609 | #endif |
672 | #endif |
610 | |
673 | |
611 | #ifndef ECB_MEMORY_FENCE |
674 | #ifndef ECB_MEMORY_FENCE |
612 | #if !ECB_AVOID_PTHREADS |
675 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
624 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
687 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
625 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
688 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
626 | #endif |
689 | #endif |
627 | #endif |
690 | #endif |
628 | |
691 | |
629 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
692 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
630 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
693 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
631 | #endif |
694 | #endif |
632 | |
695 | |
633 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
696 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
634 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
697 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
635 | #endif |
698 | #endif |
636 | |
699 | |
637 | /*****************************************************************************/ |
700 | /*****************************************************************************/ |
638 | |
|
|
639 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
640 | |
701 | |
641 | #if __cplusplus |
702 | #if __cplusplus |
642 | #define ecb_inline static inline |
703 | #define ecb_inline static inline |
643 | #elif ECB_GCC_VERSION(2,5) |
704 | #elif ECB_GCC_VERSION(2,5) |
644 | #define ecb_inline static __inline__ |
705 | #define ecb_inline static __inline__ |
… | |
… | |
683 | #elif ECB_GCC_VERSION(3,0) |
744 | #elif ECB_GCC_VERSION(3,0) |
684 | #define ecb_decltype(x) __typeof(x) |
745 | #define ecb_decltype(x) __typeof(x) |
685 | #endif |
746 | #endif |
686 | |
747 | |
687 | #define ecb_noinline ecb_attribute ((__noinline__)) |
748 | #define ecb_noinline ecb_attribute ((__noinline__)) |
688 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
689 | #define ecb_unused ecb_attribute ((__unused__)) |
749 | #define ecb_unused ecb_attribute ((__unused__)) |
690 | #define ecb_const ecb_attribute ((__const__)) |
750 | #define ecb_const ecb_attribute ((__const__)) |
691 | #define ecb_pure ecb_attribute ((__pure__)) |
751 | #define ecb_pure ecb_attribute ((__pure__)) |
|
|
752 | |
|
|
753 | #if ECB_C11 |
|
|
754 | #define ecb_noreturn _Noreturn |
|
|
755 | #else |
|
|
756 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
757 | #endif |
692 | |
758 | |
693 | #if ECB_GCC_VERSION(4,3) |
759 | #if ECB_GCC_VERSION(4,3) |
694 | #define ecb_artificial ecb_attribute ((__artificial__)) |
760 | #define ecb_artificial ecb_attribute ((__artificial__)) |
695 | #define ecb_hot ecb_attribute ((__hot__)) |
761 | #define ecb_hot ecb_attribute ((__hot__)) |
696 | #define ecb_cold ecb_attribute ((__cold__)) |
762 | #define ecb_cold ecb_attribute ((__cold__)) |
… | |
… | |
787 | |
853 | |
788 | return r + ecb_ld32 (x); |
854 | return r + ecb_ld32 (x); |
789 | } |
855 | } |
790 | #endif |
856 | #endif |
791 | |
857 | |
|
|
858 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) ecb_const; |
|
|
859 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); } |
|
|
860 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) ecb_const; |
|
|
861 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); } |
|
|
862 | |
792 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
863 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
793 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
864 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
794 | { |
865 | { |
795 | return ( (x * 0x0802U & 0x22110U) |
866 | return ( (x * 0x0802U & 0x22110U) |
796 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
867 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
… | |
… | |
880 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
951 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
881 | ecb_inline void ecb_unreachable (void) { } |
952 | ecb_inline void ecb_unreachable (void) { } |
882 | #endif |
953 | #endif |
883 | |
954 | |
884 | /* try to tell the compiler that some condition is definitely true */ |
955 | /* try to tell the compiler that some condition is definitely true */ |
885 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
956 | #define ecb_assume(cond) if (!(cond)) ecb_unreachable (); else 0 |
886 | |
957 | |
887 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
958 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
888 | ecb_inline unsigned char |
959 | ecb_inline unsigned char |
889 | ecb_byteorder_helper (void) |
960 | ecb_byteorder_helper (void) |
890 | { |
961 | { |
891 | const uint32_t u = 0x11223344; |
962 | /* the union code still generates code under pressure in gcc, */ |
892 | return *(unsigned char *)&u; |
963 | /* but less than using pointers, and always seems to */ |
|
|
964 | /* successfully return a constant. */ |
|
|
965 | /* the reason why we have this horrible preprocessor mess */ |
|
|
966 | /* is to avoid it in all cases, at least on common architectures */ |
|
|
967 | /* or when using a recent enough gcc version (>= 4.6) */ |
|
|
968 | #if __i386 || __i386__ || _M_X86 || __amd64 || __amd64__ || _M_X64 |
|
|
969 | return 0x44; |
|
|
970 | #elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ |
|
|
971 | return 0x44; |
|
|
972 | #elif __BYTE_ORDER__ && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ |
|
|
973 | return 0x11; |
|
|
974 | #else |
|
|
975 | union |
|
|
976 | { |
|
|
977 | uint32_t i; |
|
|
978 | uint8_t c; |
|
|
979 | } u = { 0x11223344 }; |
|
|
980 | return u.c; |
|
|
981 | #endif |
893 | } |
982 | } |
894 | |
983 | |
895 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
984 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
896 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
985 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
897 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
986 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
… | |
… | |
928 | } |
1017 | } |
929 | #else |
1018 | #else |
930 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
1019 | #define ecb_array_length(name) (sizeof (name) / sizeof (name [0])) |
931 | #endif |
1020 | #endif |
932 | |
1021 | |
|
|
1022 | /*******************************************************************************/ |
|
|
1023 | /* floating point stuff, can be disabled by defining ECB_NO_LIBM */ |
|
|
1024 | |
|
|
1025 | /* basically, everything uses "ieee pure-endian" floating point numbers */ |
|
|
1026 | /* the only noteworthy exception is ancient armle, which uses order 43218765 */ |
|
|
1027 | #if 0 \ |
|
|
1028 | || __i386 || __i386__ \ |
|
|
1029 | || __amd64 || __amd64__ || __x86_64 || __x86_64__ \ |
|
|
1030 | || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \ |
|
|
1031 | || defined __arm__ && defined __ARM_EABI__ \ |
|
|
1032 | || defined __s390__ || defined __s390x__ \ |
|
|
1033 | || defined __mips__ \ |
|
|
1034 | || defined __alpha__ \ |
|
|
1035 | || defined __hppa__ \ |
|
|
1036 | || defined __ia64__ \ |
|
|
1037 | || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 |
|
|
1038 | #define ECB_STDFP 1 |
|
|
1039 | #include <string.h> /* for memcpy */ |
|
|
1040 | #else |
|
|
1041 | #define ECB_STDFP 0 |
|
|
1042 | #include <math.h> /* for frexp*, ldexp* */ |
|
|
1043 | #endif |
|
|
1044 | |
|
|
1045 | #ifndef ECB_NO_LIBM |
|
|
1046 | |
|
|
1047 | /* convert a float to ieee single/binary32 */ |
|
|
1048 | ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const; |
|
|
1049 | ecb_function_ uint32_t |
|
|
1050 | ecb_float_to_binary32 (float x) |
|
|
1051 | { |
|
|
1052 | uint32_t r; |
|
|
1053 | |
|
|
1054 | #if ECB_STDFP |
|
|
1055 | memcpy (&r, &x, 4); |
|
|
1056 | #else |
|
|
1057 | /* slow emulation, works for anything but -0 */ |
|
|
1058 | uint32_t m; |
|
|
1059 | int e; |
|
|
1060 | |
|
|
1061 | if (x == 0e0f ) return 0x00000000U; |
|
|
1062 | if (x > +3.40282346638528860e+38f) return 0x7f800000U; |
|
|
1063 | if (x < -3.40282346638528860e+38f) return 0xff800000U; |
|
|
1064 | if (x != x ) return 0x7fbfffffU; |
|
|
1065 | |
|
|
1066 | m = frexpf (x, &e) * 0x1000000U; |
|
|
1067 | |
|
|
1068 | r = m & 0x80000000U; |
|
|
1069 | |
|
|
1070 | if (r) |
|
|
1071 | m = -m; |
|
|
1072 | |
|
|
1073 | if (e <= -126) |
|
|
1074 | { |
|
|
1075 | m &= 0xffffffU; |
|
|
1076 | m >>= (-125 - e); |
|
|
1077 | e = -126; |
|
|
1078 | } |
|
|
1079 | |
|
|
1080 | r |= (e + 126) << 23; |
|
|
1081 | r |= m & 0x7fffffU; |
|
|
1082 | #endif |
|
|
1083 | |
|
|
1084 | return r; |
|
|
1085 | } |
|
|
1086 | |
|
|
1087 | /* converts an ieee single/binary32 to a float */ |
|
|
1088 | ecb_function_ float ecb_binary32_to_float (uint32_t x) ecb_const; |
|
|
1089 | ecb_function_ float |
|
|
1090 | ecb_binary32_to_float (uint32_t x) |
|
|
1091 | { |
|
|
1092 | float r; |
|
|
1093 | |
|
|
1094 | #if ECB_STDFP |
|
|
1095 | memcpy (&r, &x, 4); |
|
|
1096 | #else |
|
|
1097 | /* emulation, only works for normals and subnormals and +0 */ |
|
|
1098 | int neg = x >> 31; |
|
|
1099 | int e = (x >> 23) & 0xffU; |
|
|
1100 | |
|
|
1101 | x &= 0x7fffffU; |
|
|
1102 | |
|
|
1103 | if (e) |
|
|
1104 | x |= 0x800000U; |
|
|
1105 | else |
|
|
1106 | e = 1; |
|
|
1107 | |
|
|
1108 | /* we distrust ldexpf a bit and do the 2**-24 scaling by an extra multiply */ |
|
|
1109 | r = ldexpf (x * (0.5f / 0x800000U), e - 126); |
|
|
1110 | |
|
|
1111 | r = neg ? -r : r; |
|
|
1112 | #endif |
|
|
1113 | |
|
|
1114 | return r; |
|
|
1115 | } |
|
|
1116 | |
|
|
1117 | /* convert a double to ieee double/binary64 */ |
|
|
1118 | ecb_function_ uint64_t ecb_double_to_binary64 (double x) ecb_const; |
|
|
1119 | ecb_function_ uint64_t |
|
|
1120 | ecb_double_to_binary64 (double x) |
|
|
1121 | { |
|
|
1122 | uint64_t r; |
|
|
1123 | |
|
|
1124 | #if ECB_STDFP |
|
|
1125 | memcpy (&r, &x, 8); |
|
|
1126 | #else |
|
|
1127 | /* slow emulation, works for anything but -0 */ |
|
|
1128 | uint64_t m; |
|
|
1129 | int e; |
|
|
1130 | |
|
|
1131 | if (x == 0e0 ) return 0x0000000000000000U; |
|
|
1132 | if (x > +1.79769313486231470e+308) return 0x7ff0000000000000U; |
|
|
1133 | if (x < -1.79769313486231470e+308) return 0xfff0000000000000U; |
|
|
1134 | if (x != x ) return 0X7ff7ffffffffffffU; |
|
|
1135 | |
|
|
1136 | m = frexp (x, &e) * 0x20000000000000U; |
|
|
1137 | |
|
|
1138 | r = m & 0x8000000000000000;; |
|
|
1139 | |
|
|
1140 | if (r) |
|
|
1141 | m = -m; |
|
|
1142 | |
|
|
1143 | if (e <= -1022) |
|
|
1144 | { |
|
|
1145 | m &= 0x1fffffffffffffU; |
|
|
1146 | m >>= (-1021 - e); |
|
|
1147 | e = -1022; |
|
|
1148 | } |
|
|
1149 | |
|
|
1150 | r |= ((uint64_t)(e + 1022)) << 52; |
|
|
1151 | r |= m & 0xfffffffffffffU; |
|
|
1152 | #endif |
|
|
1153 | |
|
|
1154 | return r; |
|
|
1155 | } |
|
|
1156 | |
|
|
1157 | /* converts an ieee double/binary64 to a double */ |
|
|
1158 | ecb_function_ double ecb_binary64_to_double (uint64_t x) ecb_const; |
|
|
1159 | ecb_function_ double |
|
|
1160 | ecb_binary64_to_double (uint64_t x) |
|
|
1161 | { |
|
|
1162 | double r; |
|
|
1163 | |
|
|
1164 | #if ECB_STDFP |
|
|
1165 | memcpy (&r, &x, 8); |
|
|
1166 | #else |
|
|
1167 | /* emulation, only works for normals and subnormals and +0 */ |
|
|
1168 | int neg = x >> 63; |
|
|
1169 | int e = (x >> 52) & 0x7ffU; |
|
|
1170 | |
|
|
1171 | x &= 0xfffffffffffffU; |
|
|
1172 | |
|
|
1173 | if (e) |
|
|
1174 | x |= 0x10000000000000U; |
|
|
1175 | else |
|
|
1176 | e = 1; |
|
|
1177 | |
|
|
1178 | /* we distrust ldexp a bit and do the 2**-53 scaling by an extra multiply */ |
|
|
1179 | r = ldexp (x * (0.5 / 0x10000000000000U), e - 1022); |
|
|
1180 | |
|
|
1181 | r = neg ? -r : r; |
|
|
1182 | #endif |
|
|
1183 | |
|
|
1184 | return r; |
|
|
1185 | } |
|
|
1186 | |
|
|
1187 | #endif |
|
|
1188 | |
933 | #endif |
1189 | #endif |
934 | |
1190 | |
935 | /* ECB.H END */ |
1191 | /* ECB.H END */ |
936 | |
1192 | |
937 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1193 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
… | |
… | |
1103 | { |
1359 | { |
1104 | write (STDERR_FILENO, msg, strlen (msg)); |
1360 | write (STDERR_FILENO, msg, strlen (msg)); |
1105 | } |
1361 | } |
1106 | #endif |
1362 | #endif |
1107 | |
1363 | |
1108 | static void (*syserr_cb)(const char *msg); |
1364 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1109 | |
1365 | |
1110 | void ecb_cold |
1366 | void ecb_cold |
1111 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1367 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1112 | { |
1368 | { |
1113 | syserr_cb = cb; |
1369 | syserr_cb = cb; |
1114 | } |
1370 | } |
1115 | |
1371 | |
1116 | static void noinline ecb_cold |
1372 | static void noinline ecb_cold |
… | |
… | |
1134 | abort (); |
1390 | abort (); |
1135 | } |
1391 | } |
1136 | } |
1392 | } |
1137 | |
1393 | |
1138 | static void * |
1394 | static void * |
1139 | ev_realloc_emul (void *ptr, long size) |
1395 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1140 | { |
1396 | { |
1141 | #if __GLIBC__ |
|
|
1142 | return realloc (ptr, size); |
|
|
1143 | #else |
|
|
1144 | /* some systems, notably openbsd and darwin, fail to properly |
1397 | /* some systems, notably openbsd and darwin, fail to properly |
1145 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1398 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1146 | * the single unix specification, so work around them here. |
1399 | * the single unix specification, so work around them here. |
|
|
1400 | * recently, also (at least) fedora and debian started breaking it, |
|
|
1401 | * despite documenting it otherwise. |
1147 | */ |
1402 | */ |
1148 | |
1403 | |
1149 | if (size) |
1404 | if (size) |
1150 | return realloc (ptr, size); |
1405 | return realloc (ptr, size); |
1151 | |
1406 | |
1152 | free (ptr); |
1407 | free (ptr); |
1153 | return 0; |
1408 | return 0; |
1154 | #endif |
|
|
1155 | } |
1409 | } |
1156 | |
1410 | |
1157 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1411 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1158 | |
1412 | |
1159 | void ecb_cold |
1413 | void ecb_cold |
1160 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1414 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1161 | { |
1415 | { |
1162 | alloc = cb; |
1416 | alloc = cb; |
1163 | } |
1417 | } |
1164 | |
1418 | |
1165 | inline_speed void * |
1419 | inline_speed void * |
… | |
… | |
1282 | |
1536 | |
1283 | /*****************************************************************************/ |
1537 | /*****************************************************************************/ |
1284 | |
1538 | |
1285 | #ifndef EV_HAVE_EV_TIME |
1539 | #ifndef EV_HAVE_EV_TIME |
1286 | ev_tstamp |
1540 | ev_tstamp |
1287 | ev_time (void) |
1541 | ev_time (void) EV_THROW |
1288 | { |
1542 | { |
1289 | #if EV_USE_REALTIME |
1543 | #if EV_USE_REALTIME |
1290 | if (expect_true (have_realtime)) |
1544 | if (expect_true (have_realtime)) |
1291 | { |
1545 | { |
1292 | struct timespec ts; |
1546 | struct timespec ts; |
… | |
… | |
1316 | return ev_time (); |
1570 | return ev_time (); |
1317 | } |
1571 | } |
1318 | |
1572 | |
1319 | #if EV_MULTIPLICITY |
1573 | #if EV_MULTIPLICITY |
1320 | ev_tstamp |
1574 | ev_tstamp |
1321 | ev_now (EV_P) |
1575 | ev_now (EV_P) EV_THROW |
1322 | { |
1576 | { |
1323 | return ev_rt_now; |
1577 | return ev_rt_now; |
1324 | } |
1578 | } |
1325 | #endif |
1579 | #endif |
1326 | |
1580 | |
1327 | void |
1581 | void |
1328 | ev_sleep (ev_tstamp delay) |
1582 | ev_sleep (ev_tstamp delay) EV_THROW |
1329 | { |
1583 | { |
1330 | if (delay > 0.) |
1584 | if (delay > 0.) |
1331 | { |
1585 | { |
1332 | #if EV_USE_NANOSLEEP |
1586 | #if EV_USE_NANOSLEEP |
1333 | struct timespec ts; |
1587 | struct timespec ts; |
1334 | |
1588 | |
1335 | EV_TS_SET (ts, delay); |
1589 | EV_TS_SET (ts, delay); |
1336 | nanosleep (&ts, 0); |
1590 | nanosleep (&ts, 0); |
1337 | #elif defined(_WIN32) |
1591 | #elif defined _WIN32 |
1338 | Sleep ((unsigned long)(delay * 1e3)); |
1592 | Sleep ((unsigned long)(delay * 1e3)); |
1339 | #else |
1593 | #else |
1340 | struct timeval tv; |
1594 | struct timeval tv; |
1341 | |
1595 | |
1342 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1596 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1414 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1668 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1415 | { |
1669 | { |
1416 | } |
1670 | } |
1417 | |
1671 | |
1418 | void noinline |
1672 | void noinline |
1419 | ev_feed_event (EV_P_ void *w, int revents) |
1673 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1420 | { |
1674 | { |
1421 | W w_ = (W)w; |
1675 | W w_ = (W)w; |
1422 | int pri = ABSPRI (w_); |
1676 | int pri = ABSPRI (w_); |
1423 | |
1677 | |
1424 | if (expect_false (w_->pending)) |
1678 | if (expect_false (w_->pending)) |
… | |
… | |
1428 | w_->pending = ++pendingcnt [pri]; |
1682 | w_->pending = ++pendingcnt [pri]; |
1429 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1683 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1430 | pendings [pri][w_->pending - 1].w = w_; |
1684 | pendings [pri][w_->pending - 1].w = w_; |
1431 | pendings [pri][w_->pending - 1].events = revents; |
1685 | pendings [pri][w_->pending - 1].events = revents; |
1432 | } |
1686 | } |
|
|
1687 | |
|
|
1688 | pendingpri = NUMPRI - 1; |
1433 | } |
1689 | } |
1434 | |
1690 | |
1435 | inline_speed void |
1691 | inline_speed void |
1436 | feed_reverse (EV_P_ W w) |
1692 | feed_reverse (EV_P_ W w) |
1437 | { |
1693 | { |
… | |
… | |
1483 | if (expect_true (!anfd->reify)) |
1739 | if (expect_true (!anfd->reify)) |
1484 | fd_event_nocheck (EV_A_ fd, revents); |
1740 | fd_event_nocheck (EV_A_ fd, revents); |
1485 | } |
1741 | } |
1486 | |
1742 | |
1487 | void |
1743 | void |
1488 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1744 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1489 | { |
1745 | { |
1490 | if (fd >= 0 && fd < anfdmax) |
1746 | if (fd >= 0 && fd < anfdmax) |
1491 | fd_event_nocheck (EV_A_ fd, revents); |
1747 | fd_event_nocheck (EV_A_ fd, revents); |
1492 | } |
1748 | } |
1493 | |
1749 | |
… | |
… | |
1812 | static void noinline ecb_cold |
2068 | static void noinline ecb_cold |
1813 | evpipe_init (EV_P) |
2069 | evpipe_init (EV_P) |
1814 | { |
2070 | { |
1815 | if (!ev_is_active (&pipe_w)) |
2071 | if (!ev_is_active (&pipe_w)) |
1816 | { |
2072 | { |
|
|
2073 | int fds [2]; |
|
|
2074 | |
1817 | # if EV_USE_EVENTFD |
2075 | # if EV_USE_EVENTFD |
|
|
2076 | fds [0] = -1; |
1818 | evfd = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
2077 | fds [1] = eventfd (0, EFD_NONBLOCK | EFD_CLOEXEC); |
1819 | if (evfd < 0 && errno == EINVAL) |
2078 | if (fds [1] < 0 && errno == EINVAL) |
1820 | evfd = eventfd (0, 0); |
2079 | fds [1] = eventfd (0, 0); |
1821 | |
2080 | |
1822 | if (evfd >= 0) |
2081 | if (fds [1] < 0) |
|
|
2082 | # endif |
1823 | { |
2083 | { |
|
|
2084 | while (pipe (fds)) |
|
|
2085 | ev_syserr ("(libev) error creating signal/async pipe"); |
|
|
2086 | |
|
|
2087 | fd_intern (fds [0]); |
|
|
2088 | } |
|
|
2089 | |
|
|
2090 | fd_intern (fds [1]); |
|
|
2091 | |
1824 | evpipe [0] = -1; |
2092 | evpipe [0] = fds [0]; |
1825 | fd_intern (evfd); /* doing it twice doesn't hurt */ |
2093 | |
1826 | ev_io_set (&pipe_w, evfd, EV_READ); |
2094 | if (evpipe [1] < 0) |
|
|
2095 | evpipe [1] = fds [1]; /* first call, set write fd */ |
|
|
2096 | else |
|
|
2097 | { |
|
|
2098 | /* on subsequent calls, do not change evpipe [1] */ |
|
|
2099 | /* so that evpipe_write can always rely on its value. */ |
|
|
2100 | /* this branch does not do anything sensible on windows, */ |
|
|
2101 | /* so must not be executed on windows */ |
|
|
2102 | |
|
|
2103 | dup2 (fds [1], evpipe [1]); |
|
|
2104 | close (fds [1]); |
|
|
2105 | } |
|
|
2106 | |
|
|
2107 | ev_io_set (&pipe_w, evpipe [0] < 0 ? evpipe [1] : evpipe [0], EV_READ); |
|
|
2108 | ev_io_start (EV_A_ &pipe_w); |
|
|
2109 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
|
|
2110 | } |
|
|
2111 | } |
|
|
2112 | |
|
|
2113 | inline_speed void |
|
|
2114 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
|
|
2115 | { |
|
|
2116 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
2117 | |
|
|
2118 | if (expect_true (*flag)) |
|
|
2119 | return; |
|
|
2120 | |
|
|
2121 | *flag = 1; |
|
|
2122 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
|
|
2123 | |
|
|
2124 | pipe_write_skipped = 1; |
|
|
2125 | |
|
|
2126 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
|
|
2127 | |
|
|
2128 | if (pipe_write_wanted) |
|
|
2129 | { |
|
|
2130 | int old_errno; |
|
|
2131 | |
|
|
2132 | pipe_write_skipped = 0; |
|
|
2133 | ECB_MEMORY_FENCE_RELEASE; |
|
|
2134 | |
|
|
2135 | old_errno = errno; /* save errno because write will clobber it */ |
|
|
2136 | |
|
|
2137 | #if EV_USE_EVENTFD |
|
|
2138 | if (evpipe [0] < 0) |
|
|
2139 | { |
|
|
2140 | uint64_t counter = 1; |
|
|
2141 | write (evpipe [1], &counter, sizeof (uint64_t)); |
1827 | } |
2142 | } |
1828 | else |
2143 | else |
1829 | # endif |
2144 | #endif |
1830 | { |
2145 | { |
1831 | while (pipe (evpipe)) |
2146 | #ifdef _WIN32 |
1832 | ev_syserr ("(libev) error creating signal/async pipe"); |
2147 | WSABUF buf; |
1833 | |
2148 | DWORD sent; |
1834 | fd_intern (evpipe [0]); |
2149 | buf.buf = &buf; |
1835 | fd_intern (evpipe [1]); |
2150 | buf.len = 1; |
1836 | ev_io_set (&pipe_w, evpipe [0], EV_READ); |
2151 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
1837 | } |
2152 | #else |
1838 | |
|
|
1839 | ev_io_start (EV_A_ &pipe_w); |
|
|
1840 | ev_unref (EV_A); /* watcher should not keep loop alive */ |
|
|
1841 | } |
|
|
1842 | } |
|
|
1843 | |
|
|
1844 | inline_speed void |
|
|
1845 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
|
|
1846 | { |
|
|
1847 | if (expect_true (*flag)) |
|
|
1848 | return; |
|
|
1849 | |
|
|
1850 | *flag = 1; |
|
|
1851 | |
|
|
1852 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
|
|
1853 | |
|
|
1854 | pipe_write_skipped = 1; |
|
|
1855 | |
|
|
1856 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
|
|
1857 | |
|
|
1858 | if (pipe_write_wanted) |
|
|
1859 | { |
|
|
1860 | int old_errno; |
|
|
1861 | |
|
|
1862 | pipe_write_skipped = 0; /* just an optimisation, no fence needed */ |
|
|
1863 | |
|
|
1864 | old_errno = errno; /* save errno because write will clobber it */ |
|
|
1865 | |
|
|
1866 | #if EV_USE_EVENTFD |
|
|
1867 | if (evfd >= 0) |
|
|
1868 | { |
|
|
1869 | uint64_t counter = 1; |
|
|
1870 | write (evfd, &counter, sizeof (uint64_t)); |
|
|
1871 | } |
|
|
1872 | else |
|
|
1873 | #endif |
|
|
1874 | { |
|
|
1875 | /* win32 people keep sending patches that change this write() to send() */ |
|
|
1876 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
|
|
1877 | /* so when you think this write should be a send instead, please find out */ |
|
|
1878 | /* where your send() is from - it's definitely not the microsoft send, and */ |
|
|
1879 | /* tell me. thank you. */ |
|
|
1880 | /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ |
|
|
1881 | /* check the ev documentation on how to use this flag */ |
|
|
1882 | write (evpipe [1], &(evpipe [1]), 1); |
2153 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
2154 | #endif |
1883 | } |
2155 | } |
1884 | |
2156 | |
1885 | errno = old_errno; |
2157 | errno = old_errno; |
1886 | } |
2158 | } |
1887 | } |
2159 | } |
… | |
… | |
1894 | int i; |
2166 | int i; |
1895 | |
2167 | |
1896 | if (revents & EV_READ) |
2168 | if (revents & EV_READ) |
1897 | { |
2169 | { |
1898 | #if EV_USE_EVENTFD |
2170 | #if EV_USE_EVENTFD |
1899 | if (evfd >= 0) |
2171 | if (evpipe [0] < 0) |
1900 | { |
2172 | { |
1901 | uint64_t counter; |
2173 | uint64_t counter; |
1902 | read (evfd, &counter, sizeof (uint64_t)); |
2174 | read (evpipe [1], &counter, sizeof (uint64_t)); |
1903 | } |
2175 | } |
1904 | else |
2176 | else |
1905 | #endif |
2177 | #endif |
1906 | { |
2178 | { |
1907 | char dummy; |
2179 | char dummy[4]; |
1908 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
2180 | #ifdef _WIN32 |
|
|
2181 | WSABUF buf; |
|
|
2182 | DWORD recvd; |
|
|
2183 | DWORD flags = 0; |
|
|
2184 | buf.buf = dummy; |
|
|
2185 | buf.len = sizeof (dummy); |
|
|
2186 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0); |
|
|
2187 | #else |
1909 | read (evpipe [0], &dummy, 1); |
2188 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
2189 | #endif |
1910 | } |
2190 | } |
1911 | } |
2191 | } |
1912 | |
2192 | |
1913 | pipe_write_skipped = 0; |
2193 | pipe_write_skipped = 0; |
|
|
2194 | |
|
|
2195 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1914 | |
2196 | |
1915 | #if EV_SIGNAL_ENABLE |
2197 | #if EV_SIGNAL_ENABLE |
1916 | if (sig_pending) |
2198 | if (sig_pending) |
1917 | { |
2199 | { |
1918 | sig_pending = 0; |
2200 | sig_pending = 0; |
|
|
2201 | |
|
|
2202 | ECB_MEMORY_FENCE; |
1919 | |
2203 | |
1920 | for (i = EV_NSIG - 1; i--; ) |
2204 | for (i = EV_NSIG - 1; i--; ) |
1921 | if (expect_false (signals [i].pending)) |
2205 | if (expect_false (signals [i].pending)) |
1922 | ev_feed_signal_event (EV_A_ i + 1); |
2206 | ev_feed_signal_event (EV_A_ i + 1); |
1923 | } |
2207 | } |
… | |
… | |
1925 | |
2209 | |
1926 | #if EV_ASYNC_ENABLE |
2210 | #if EV_ASYNC_ENABLE |
1927 | if (async_pending) |
2211 | if (async_pending) |
1928 | { |
2212 | { |
1929 | async_pending = 0; |
2213 | async_pending = 0; |
|
|
2214 | |
|
|
2215 | ECB_MEMORY_FENCE; |
1930 | |
2216 | |
1931 | for (i = asynccnt; i--; ) |
2217 | for (i = asynccnt; i--; ) |
1932 | if (asyncs [i]->sent) |
2218 | if (asyncs [i]->sent) |
1933 | { |
2219 | { |
1934 | asyncs [i]->sent = 0; |
2220 | asyncs [i]->sent = 0; |
|
|
2221 | ECB_MEMORY_FENCE_RELEASE; |
1935 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
2222 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
1936 | } |
2223 | } |
1937 | } |
2224 | } |
1938 | #endif |
2225 | #endif |
1939 | } |
2226 | } |
1940 | |
2227 | |
1941 | /*****************************************************************************/ |
2228 | /*****************************************************************************/ |
1942 | |
2229 | |
1943 | void |
2230 | void |
1944 | ev_feed_signal (int signum) |
2231 | ev_feed_signal (int signum) EV_THROW |
1945 | { |
2232 | { |
1946 | #if EV_MULTIPLICITY |
2233 | #if EV_MULTIPLICITY |
|
|
2234 | ECB_MEMORY_FENCE_ACQUIRE; |
1947 | EV_P = signals [signum - 1].loop; |
2235 | EV_P = signals [signum - 1].loop; |
1948 | |
2236 | |
1949 | if (!EV_A) |
2237 | if (!EV_A) |
1950 | return; |
2238 | return; |
1951 | #endif |
2239 | #endif |
1952 | |
2240 | |
1953 | if (!ev_active (&pipe_w)) |
|
|
1954 | return; |
|
|
1955 | |
|
|
1956 | signals [signum - 1].pending = 1; |
2241 | signals [signum - 1].pending = 1; |
1957 | evpipe_write (EV_A_ &sig_pending); |
2242 | evpipe_write (EV_A_ &sig_pending); |
1958 | } |
2243 | } |
1959 | |
2244 | |
1960 | static void |
2245 | static void |
… | |
… | |
1966 | |
2251 | |
1967 | ev_feed_signal (signum); |
2252 | ev_feed_signal (signum); |
1968 | } |
2253 | } |
1969 | |
2254 | |
1970 | void noinline |
2255 | void noinline |
1971 | ev_feed_signal_event (EV_P_ int signum) |
2256 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1972 | { |
2257 | { |
1973 | WL w; |
2258 | WL w; |
1974 | |
2259 | |
1975 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
2260 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
1976 | return; |
2261 | return; |
1977 | |
2262 | |
1978 | --signum; |
2263 | --signum; |
1979 | |
2264 | |
1980 | #if EV_MULTIPLICITY |
2265 | #if EV_MULTIPLICITY |
… | |
… | |
1984 | if (expect_false (signals [signum].loop != EV_A)) |
2269 | if (expect_false (signals [signum].loop != EV_A)) |
1985 | return; |
2270 | return; |
1986 | #endif |
2271 | #endif |
1987 | |
2272 | |
1988 | signals [signum].pending = 0; |
2273 | signals [signum].pending = 0; |
|
|
2274 | ECB_MEMORY_FENCE_RELEASE; |
1989 | |
2275 | |
1990 | for (w = signals [signum].head; w; w = w->next) |
2276 | for (w = signals [signum].head; w; w = w->next) |
1991 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
2277 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1992 | } |
2278 | } |
1993 | |
2279 | |
… | |
… | |
2092 | #if EV_USE_SELECT |
2378 | #if EV_USE_SELECT |
2093 | # include "ev_select.c" |
2379 | # include "ev_select.c" |
2094 | #endif |
2380 | #endif |
2095 | |
2381 | |
2096 | int ecb_cold |
2382 | int ecb_cold |
2097 | ev_version_major (void) |
2383 | ev_version_major (void) EV_THROW |
2098 | { |
2384 | { |
2099 | return EV_VERSION_MAJOR; |
2385 | return EV_VERSION_MAJOR; |
2100 | } |
2386 | } |
2101 | |
2387 | |
2102 | int ecb_cold |
2388 | int ecb_cold |
2103 | ev_version_minor (void) |
2389 | ev_version_minor (void) EV_THROW |
2104 | { |
2390 | { |
2105 | return EV_VERSION_MINOR; |
2391 | return EV_VERSION_MINOR; |
2106 | } |
2392 | } |
2107 | |
2393 | |
2108 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2394 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2116 | || getgid () != getegid (); |
2402 | || getgid () != getegid (); |
2117 | #endif |
2403 | #endif |
2118 | } |
2404 | } |
2119 | |
2405 | |
2120 | unsigned int ecb_cold |
2406 | unsigned int ecb_cold |
2121 | ev_supported_backends (void) |
2407 | ev_supported_backends (void) EV_THROW |
2122 | { |
2408 | { |
2123 | unsigned int flags = 0; |
2409 | unsigned int flags = 0; |
2124 | |
2410 | |
2125 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2411 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2126 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2412 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2130 | |
2416 | |
2131 | return flags; |
2417 | return flags; |
2132 | } |
2418 | } |
2133 | |
2419 | |
2134 | unsigned int ecb_cold |
2420 | unsigned int ecb_cold |
2135 | ev_recommended_backends (void) |
2421 | ev_recommended_backends (void) EV_THROW |
2136 | { |
2422 | { |
2137 | unsigned int flags = ev_supported_backends (); |
2423 | unsigned int flags = ev_supported_backends (); |
2138 | |
2424 | |
2139 | #ifndef __NetBSD__ |
2425 | #ifndef __NetBSD__ |
2140 | /* kqueue is borked on everything but netbsd apparently */ |
2426 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2152 | |
2438 | |
2153 | return flags; |
2439 | return flags; |
2154 | } |
2440 | } |
2155 | |
2441 | |
2156 | unsigned int ecb_cold |
2442 | unsigned int ecb_cold |
2157 | ev_embeddable_backends (void) |
2443 | ev_embeddable_backends (void) EV_THROW |
2158 | { |
2444 | { |
2159 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2445 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2160 | |
2446 | |
2161 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2447 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2162 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2448 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2164 | |
2450 | |
2165 | return flags; |
2451 | return flags; |
2166 | } |
2452 | } |
2167 | |
2453 | |
2168 | unsigned int |
2454 | unsigned int |
2169 | ev_backend (EV_P) |
2455 | ev_backend (EV_P) EV_THROW |
2170 | { |
2456 | { |
2171 | return backend; |
2457 | return backend; |
2172 | } |
2458 | } |
2173 | |
2459 | |
2174 | #if EV_FEATURE_API |
2460 | #if EV_FEATURE_API |
2175 | unsigned int |
2461 | unsigned int |
2176 | ev_iteration (EV_P) |
2462 | ev_iteration (EV_P) EV_THROW |
2177 | { |
2463 | { |
2178 | return loop_count; |
2464 | return loop_count; |
2179 | } |
2465 | } |
2180 | |
2466 | |
2181 | unsigned int |
2467 | unsigned int |
2182 | ev_depth (EV_P) |
2468 | ev_depth (EV_P) EV_THROW |
2183 | { |
2469 | { |
2184 | return loop_depth; |
2470 | return loop_depth; |
2185 | } |
2471 | } |
2186 | |
2472 | |
2187 | void |
2473 | void |
2188 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2474 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2189 | { |
2475 | { |
2190 | io_blocktime = interval; |
2476 | io_blocktime = interval; |
2191 | } |
2477 | } |
2192 | |
2478 | |
2193 | void |
2479 | void |
2194 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2480 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2195 | { |
2481 | { |
2196 | timeout_blocktime = interval; |
2482 | timeout_blocktime = interval; |
2197 | } |
2483 | } |
2198 | |
2484 | |
2199 | void |
2485 | void |
2200 | ev_set_userdata (EV_P_ void *data) |
2486 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2201 | { |
2487 | { |
2202 | userdata = data; |
2488 | userdata = data; |
2203 | } |
2489 | } |
2204 | |
2490 | |
2205 | void * |
2491 | void * |
2206 | ev_userdata (EV_P) |
2492 | ev_userdata (EV_P) EV_THROW |
2207 | { |
2493 | { |
2208 | return userdata; |
2494 | return userdata; |
2209 | } |
2495 | } |
2210 | |
2496 | |
2211 | void |
2497 | void |
2212 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2498 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2213 | { |
2499 | { |
2214 | invoke_cb = invoke_pending_cb; |
2500 | invoke_cb = invoke_pending_cb; |
2215 | } |
2501 | } |
2216 | |
2502 | |
2217 | void |
2503 | void |
2218 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2504 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2219 | { |
2505 | { |
2220 | release_cb = release; |
2506 | release_cb = release; |
2221 | acquire_cb = acquire; |
2507 | acquire_cb = acquire; |
2222 | } |
2508 | } |
2223 | #endif |
2509 | #endif |
2224 | |
2510 | |
2225 | /* initialise a loop structure, must be zero-initialised */ |
2511 | /* initialise a loop structure, must be zero-initialised */ |
2226 | static void noinline ecb_cold |
2512 | static void noinline ecb_cold |
2227 | loop_init (EV_P_ unsigned int flags) |
2513 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2228 | { |
2514 | { |
2229 | if (!backend) |
2515 | if (!backend) |
2230 | { |
2516 | { |
2231 | origflags = flags; |
2517 | origflags = flags; |
2232 | |
2518 | |
… | |
… | |
2277 | #if EV_ASYNC_ENABLE |
2563 | #if EV_ASYNC_ENABLE |
2278 | async_pending = 0; |
2564 | async_pending = 0; |
2279 | #endif |
2565 | #endif |
2280 | pipe_write_skipped = 0; |
2566 | pipe_write_skipped = 0; |
2281 | pipe_write_wanted = 0; |
2567 | pipe_write_wanted = 0; |
|
|
2568 | evpipe [0] = -1; |
|
|
2569 | evpipe [1] = -1; |
2282 | #if EV_USE_INOTIFY |
2570 | #if EV_USE_INOTIFY |
2283 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
2571 | fs_fd = flags & EVFLAG_NOINOTIFY ? -1 : -2; |
2284 | #endif |
2572 | #endif |
2285 | #if EV_USE_SIGNALFD |
2573 | #if EV_USE_SIGNALFD |
2286 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
2574 | sigfd = flags & EVFLAG_SIGNALFD ? -2 : -1; |
… | |
… | |
2337 | EV_INVOKE_PENDING; |
2625 | EV_INVOKE_PENDING; |
2338 | } |
2626 | } |
2339 | #endif |
2627 | #endif |
2340 | |
2628 | |
2341 | #if EV_CHILD_ENABLE |
2629 | #if EV_CHILD_ENABLE |
2342 | if (ev_is_active (&childev)) |
2630 | if (ev_is_default_loop (EV_A) && ev_is_active (&childev)) |
2343 | { |
2631 | { |
2344 | ev_ref (EV_A); /* child watcher */ |
2632 | ev_ref (EV_A); /* child watcher */ |
2345 | ev_signal_stop (EV_A_ &childev); |
2633 | ev_signal_stop (EV_A_ &childev); |
2346 | } |
2634 | } |
2347 | #endif |
2635 | #endif |
… | |
… | |
2349 | if (ev_is_active (&pipe_w)) |
2637 | if (ev_is_active (&pipe_w)) |
2350 | { |
2638 | { |
2351 | /*ev_ref (EV_A);*/ |
2639 | /*ev_ref (EV_A);*/ |
2352 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
2640 | /*ev_io_stop (EV_A_ &pipe_w);*/ |
2353 | |
2641 | |
2354 | #if EV_USE_EVENTFD |
|
|
2355 | if (evfd >= 0) |
|
|
2356 | close (evfd); |
|
|
2357 | #endif |
|
|
2358 | |
|
|
2359 | if (evpipe [0] >= 0) |
|
|
2360 | { |
|
|
2361 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2642 | if (evpipe [0] >= 0) EV_WIN32_CLOSE_FD (evpipe [0]); |
2362 | EV_WIN32_CLOSE_FD (evpipe [1]); |
2643 | if (evpipe [1] >= 0) EV_WIN32_CLOSE_FD (evpipe [1]); |
2363 | } |
|
|
2364 | } |
2644 | } |
2365 | |
2645 | |
2366 | #if EV_USE_SIGNALFD |
2646 | #if EV_USE_SIGNALFD |
2367 | if (ev_is_active (&sigfd_w)) |
2647 | if (ev_is_active (&sigfd_w)) |
2368 | close (sigfd); |
2648 | close (sigfd); |
… | |
… | |
2454 | #endif |
2734 | #endif |
2455 | #if EV_USE_INOTIFY |
2735 | #if EV_USE_INOTIFY |
2456 | infy_fork (EV_A); |
2736 | infy_fork (EV_A); |
2457 | #endif |
2737 | #endif |
2458 | |
2738 | |
|
|
2739 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2459 | if (ev_is_active (&pipe_w)) |
2740 | if (ev_is_active (&pipe_w)) |
2460 | { |
2741 | { |
2461 | /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ |
2742 | /* pipe_write_wanted must be false now, so modifying fd vars should be safe */ |
2462 | |
2743 | |
2463 | ev_ref (EV_A); |
2744 | ev_ref (EV_A); |
2464 | ev_io_stop (EV_A_ &pipe_w); |
2745 | ev_io_stop (EV_A_ &pipe_w); |
2465 | |
2746 | |
2466 | #if EV_USE_EVENTFD |
|
|
2467 | if (evfd >= 0) |
|
|
2468 | close (evfd); |
|
|
2469 | #endif |
|
|
2470 | |
|
|
2471 | if (evpipe [0] >= 0) |
2747 | if (evpipe [0] >= 0) |
2472 | { |
|
|
2473 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2748 | EV_WIN32_CLOSE_FD (evpipe [0]); |
2474 | EV_WIN32_CLOSE_FD (evpipe [1]); |
|
|
2475 | } |
|
|
2476 | |
2749 | |
2477 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
|
|
2478 | evpipe_init (EV_A); |
2750 | evpipe_init (EV_A); |
2479 | /* now iterate over everything, in case we missed something */ |
2751 | /* iterate over everything, in case we missed something before */ |
2480 | pipecb (EV_A_ &pipe_w, EV_READ); |
2752 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
2481 | #endif |
|
|
2482 | } |
2753 | } |
|
|
2754 | #endif |
2483 | |
2755 | |
2484 | postfork = 0; |
2756 | postfork = 0; |
2485 | } |
2757 | } |
2486 | |
2758 | |
2487 | #if EV_MULTIPLICITY |
2759 | #if EV_MULTIPLICITY |
2488 | |
2760 | |
2489 | struct ev_loop * ecb_cold |
2761 | struct ev_loop * ecb_cold |
2490 | ev_loop_new (unsigned int flags) |
2762 | ev_loop_new (unsigned int flags) EV_THROW |
2491 | { |
2763 | { |
2492 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2764 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2493 | |
2765 | |
2494 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2766 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2495 | loop_init (EV_A_ flags); |
2767 | loop_init (EV_A_ flags); |
… | |
… | |
2539 | } |
2811 | } |
2540 | #endif |
2812 | #endif |
2541 | |
2813 | |
2542 | #if EV_FEATURE_API |
2814 | #if EV_FEATURE_API |
2543 | void ecb_cold |
2815 | void ecb_cold |
2544 | ev_verify (EV_P) |
2816 | ev_verify (EV_P) EV_THROW |
2545 | { |
2817 | { |
2546 | #if EV_VERIFY |
2818 | #if EV_VERIFY |
2547 | int i; |
2819 | int i; |
2548 | WL w; |
2820 | WL w, w2; |
2549 | |
2821 | |
2550 | assert (activecnt >= -1); |
2822 | assert (activecnt >= -1); |
2551 | |
2823 | |
2552 | assert (fdchangemax >= fdchangecnt); |
2824 | assert (fdchangemax >= fdchangecnt); |
2553 | for (i = 0; i < fdchangecnt; ++i) |
2825 | for (i = 0; i < fdchangecnt; ++i) |
2554 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2826 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2555 | |
2827 | |
2556 | assert (anfdmax >= 0); |
2828 | assert (anfdmax >= 0); |
2557 | for (i = 0; i < anfdmax; ++i) |
2829 | for (i = 0; i < anfdmax; ++i) |
|
|
2830 | { |
|
|
2831 | int j = 0; |
|
|
2832 | |
2558 | for (w = anfds [i].head; w; w = w->next) |
2833 | for (w = w2 = anfds [i].head; w; w = w->next) |
2559 | { |
2834 | { |
2560 | verify_watcher (EV_A_ (W)w); |
2835 | verify_watcher (EV_A_ (W)w); |
|
|
2836 | |
|
|
2837 | if (j++ & 1) |
|
|
2838 | { |
|
|
2839 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2840 | w2 = w2->next; |
|
|
2841 | } |
|
|
2842 | |
2561 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2843 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2562 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2844 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2563 | } |
2845 | } |
|
|
2846 | } |
2564 | |
2847 | |
2565 | assert (timermax >= timercnt); |
2848 | assert (timermax >= timercnt); |
2566 | verify_heap (EV_A_ timers, timercnt); |
2849 | verify_heap (EV_A_ timers, timercnt); |
2567 | |
2850 | |
2568 | #if EV_PERIODIC_ENABLE |
2851 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2618 | #if EV_MULTIPLICITY |
2901 | #if EV_MULTIPLICITY |
2619 | struct ev_loop * ecb_cold |
2902 | struct ev_loop * ecb_cold |
2620 | #else |
2903 | #else |
2621 | int |
2904 | int |
2622 | #endif |
2905 | #endif |
2623 | ev_default_loop (unsigned int flags) |
2906 | ev_default_loop (unsigned int flags) EV_THROW |
2624 | { |
2907 | { |
2625 | if (!ev_default_loop_ptr) |
2908 | if (!ev_default_loop_ptr) |
2626 | { |
2909 | { |
2627 | #if EV_MULTIPLICITY |
2910 | #if EV_MULTIPLICITY |
2628 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2911 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2647 | |
2930 | |
2648 | return ev_default_loop_ptr; |
2931 | return ev_default_loop_ptr; |
2649 | } |
2932 | } |
2650 | |
2933 | |
2651 | void |
2934 | void |
2652 | ev_loop_fork (EV_P) |
2935 | ev_loop_fork (EV_P) EV_THROW |
2653 | { |
2936 | { |
2654 | postfork = 1; /* must be in line with ev_default_fork */ |
2937 | postfork = 1; |
2655 | } |
2938 | } |
2656 | |
2939 | |
2657 | /*****************************************************************************/ |
2940 | /*****************************************************************************/ |
2658 | |
2941 | |
2659 | void |
2942 | void |
… | |
… | |
2661 | { |
2944 | { |
2662 | EV_CB_INVOKE ((W)w, revents); |
2945 | EV_CB_INVOKE ((W)w, revents); |
2663 | } |
2946 | } |
2664 | |
2947 | |
2665 | unsigned int |
2948 | unsigned int |
2666 | ev_pending_count (EV_P) |
2949 | ev_pending_count (EV_P) EV_THROW |
2667 | { |
2950 | { |
2668 | int pri; |
2951 | int pri; |
2669 | unsigned int count = 0; |
2952 | unsigned int count = 0; |
2670 | |
2953 | |
2671 | for (pri = NUMPRI; pri--; ) |
2954 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2675 | } |
2958 | } |
2676 | |
2959 | |
2677 | void noinline |
2960 | void noinline |
2678 | ev_invoke_pending (EV_P) |
2961 | ev_invoke_pending (EV_P) |
2679 | { |
2962 | { |
2680 | int pri; |
2963 | pendingpri = NUMPRI; |
2681 | |
2964 | |
2682 | for (pri = NUMPRI; pri--; ) |
2965 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
|
|
2966 | { |
|
|
2967 | --pendingpri; |
|
|
2968 | |
2683 | while (pendingcnt [pri]) |
2969 | while (pendingcnt [pendingpri]) |
2684 | { |
2970 | { |
2685 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2971 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2686 | |
2972 | |
2687 | p->w->pending = 0; |
2973 | p->w->pending = 0; |
2688 | EV_CB_INVOKE (p->w, p->events); |
2974 | EV_CB_INVOKE (p->w, p->events); |
2689 | EV_FREQUENT_CHECK; |
2975 | EV_FREQUENT_CHECK; |
2690 | } |
2976 | } |
|
|
2977 | } |
2691 | } |
2978 | } |
2692 | |
2979 | |
2693 | #if EV_IDLE_ENABLE |
2980 | #if EV_IDLE_ENABLE |
2694 | /* make idle watchers pending. this handles the "call-idle */ |
2981 | /* make idle watchers pending. this handles the "call-idle */ |
2695 | /* only when higher priorities are idle" logic */ |
2982 | /* only when higher priorities are idle" logic */ |
… | |
… | |
2785 | { |
3072 | { |
2786 | EV_FREQUENT_CHECK; |
3073 | EV_FREQUENT_CHECK; |
2787 | |
3074 | |
2788 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
3075 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2789 | { |
3076 | { |
2790 | int feed_count = 0; |
|
|
2791 | |
|
|
2792 | do |
3077 | do |
2793 | { |
3078 | { |
2794 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
3079 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2795 | |
3080 | |
2796 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
3081 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
2930 | |
3215 | |
2931 | mn_now = ev_rt_now; |
3216 | mn_now = ev_rt_now; |
2932 | } |
3217 | } |
2933 | } |
3218 | } |
2934 | |
3219 | |
2935 | void |
3220 | int |
2936 | ev_run (EV_P_ int flags) |
3221 | ev_run (EV_P_ int flags) |
2937 | { |
3222 | { |
2938 | #if EV_FEATURE_API |
3223 | #if EV_FEATURE_API |
2939 | ++loop_depth; |
3224 | ++loop_depth; |
2940 | #endif |
3225 | #endif |
… | |
… | |
3055 | backend_poll (EV_A_ waittime); |
3340 | backend_poll (EV_A_ waittime); |
3056 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3341 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3057 | |
3342 | |
3058 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3343 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3059 | |
3344 | |
|
|
3345 | ECB_MEMORY_FENCE_ACQUIRE; |
3060 | if (pipe_write_skipped) |
3346 | if (pipe_write_skipped) |
3061 | { |
3347 | { |
3062 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3348 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3063 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3349 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3064 | } |
3350 | } |
… | |
… | |
3097 | loop_done = EVBREAK_CANCEL; |
3383 | loop_done = EVBREAK_CANCEL; |
3098 | |
3384 | |
3099 | #if EV_FEATURE_API |
3385 | #if EV_FEATURE_API |
3100 | --loop_depth; |
3386 | --loop_depth; |
3101 | #endif |
3387 | #endif |
|
|
3388 | |
|
|
3389 | return activecnt; |
3102 | } |
3390 | } |
3103 | |
3391 | |
3104 | void |
3392 | void |
3105 | ev_break (EV_P_ int how) |
3393 | ev_break (EV_P_ int how) EV_THROW |
3106 | { |
3394 | { |
3107 | loop_done = how; |
3395 | loop_done = how; |
3108 | } |
3396 | } |
3109 | |
3397 | |
3110 | void |
3398 | void |
3111 | ev_ref (EV_P) |
3399 | ev_ref (EV_P) EV_THROW |
3112 | { |
3400 | { |
3113 | ++activecnt; |
3401 | ++activecnt; |
3114 | } |
3402 | } |
3115 | |
3403 | |
3116 | void |
3404 | void |
3117 | ev_unref (EV_P) |
3405 | ev_unref (EV_P) EV_THROW |
3118 | { |
3406 | { |
3119 | --activecnt; |
3407 | --activecnt; |
3120 | } |
3408 | } |
3121 | |
3409 | |
3122 | void |
3410 | void |
3123 | ev_now_update (EV_P) |
3411 | ev_now_update (EV_P) EV_THROW |
3124 | { |
3412 | { |
3125 | time_update (EV_A_ 1e100); |
3413 | time_update (EV_A_ 1e100); |
3126 | } |
3414 | } |
3127 | |
3415 | |
3128 | void |
3416 | void |
3129 | ev_suspend (EV_P) |
3417 | ev_suspend (EV_P) EV_THROW |
3130 | { |
3418 | { |
3131 | ev_now_update (EV_A); |
3419 | ev_now_update (EV_A); |
3132 | } |
3420 | } |
3133 | |
3421 | |
3134 | void |
3422 | void |
3135 | ev_resume (EV_P) |
3423 | ev_resume (EV_P) EV_THROW |
3136 | { |
3424 | { |
3137 | ev_tstamp mn_prev = mn_now; |
3425 | ev_tstamp mn_prev = mn_now; |
3138 | |
3426 | |
3139 | ev_now_update (EV_A); |
3427 | ev_now_update (EV_A); |
3140 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3428 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3179 | w->pending = 0; |
3467 | w->pending = 0; |
3180 | } |
3468 | } |
3181 | } |
3469 | } |
3182 | |
3470 | |
3183 | int |
3471 | int |
3184 | ev_clear_pending (EV_P_ void *w) |
3472 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3185 | { |
3473 | { |
3186 | W w_ = (W)w; |
3474 | W w_ = (W)w; |
3187 | int pending = w_->pending; |
3475 | int pending = w_->pending; |
3188 | |
3476 | |
3189 | if (expect_true (pending)) |
3477 | if (expect_true (pending)) |
… | |
… | |
3222 | } |
3510 | } |
3223 | |
3511 | |
3224 | /*****************************************************************************/ |
3512 | /*****************************************************************************/ |
3225 | |
3513 | |
3226 | void noinline |
3514 | void noinline |
3227 | ev_io_start (EV_P_ ev_io *w) |
3515 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3228 | { |
3516 | { |
3229 | int fd = w->fd; |
3517 | int fd = w->fd; |
3230 | |
3518 | |
3231 | if (expect_false (ev_is_active (w))) |
3519 | if (expect_false (ev_is_active (w))) |
3232 | return; |
3520 | return; |
… | |
… | |
3238 | |
3526 | |
3239 | ev_start (EV_A_ (W)w, 1); |
3527 | ev_start (EV_A_ (W)w, 1); |
3240 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3528 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3241 | wlist_add (&anfds[fd].head, (WL)w); |
3529 | wlist_add (&anfds[fd].head, (WL)w); |
3242 | |
3530 | |
|
|
3531 | /* common bug, apparently */ |
|
|
3532 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3533 | |
3243 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3534 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3244 | w->events &= ~EV__IOFDSET; |
3535 | w->events &= ~EV__IOFDSET; |
3245 | |
3536 | |
3246 | EV_FREQUENT_CHECK; |
3537 | EV_FREQUENT_CHECK; |
3247 | } |
3538 | } |
3248 | |
3539 | |
3249 | void noinline |
3540 | void noinline |
3250 | ev_io_stop (EV_P_ ev_io *w) |
3541 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3251 | { |
3542 | { |
3252 | clear_pending (EV_A_ (W)w); |
3543 | clear_pending (EV_A_ (W)w); |
3253 | if (expect_false (!ev_is_active (w))) |
3544 | if (expect_false (!ev_is_active (w))) |
3254 | return; |
3545 | return; |
3255 | |
3546 | |
… | |
… | |
3264 | |
3555 | |
3265 | EV_FREQUENT_CHECK; |
3556 | EV_FREQUENT_CHECK; |
3266 | } |
3557 | } |
3267 | |
3558 | |
3268 | void noinline |
3559 | void noinline |
3269 | ev_timer_start (EV_P_ ev_timer *w) |
3560 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3270 | { |
3561 | { |
3271 | if (expect_false (ev_is_active (w))) |
3562 | if (expect_false (ev_is_active (w))) |
3272 | return; |
3563 | return; |
3273 | |
3564 | |
3274 | ev_at (w) += mn_now; |
3565 | ev_at (w) += mn_now; |
… | |
… | |
3288 | |
3579 | |
3289 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3580 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3290 | } |
3581 | } |
3291 | |
3582 | |
3292 | void noinline |
3583 | void noinline |
3293 | ev_timer_stop (EV_P_ ev_timer *w) |
3584 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3294 | { |
3585 | { |
3295 | clear_pending (EV_A_ (W)w); |
3586 | clear_pending (EV_A_ (W)w); |
3296 | if (expect_false (!ev_is_active (w))) |
3587 | if (expect_false (!ev_is_active (w))) |
3297 | return; |
3588 | return; |
3298 | |
3589 | |
… | |
… | |
3318 | |
3609 | |
3319 | EV_FREQUENT_CHECK; |
3610 | EV_FREQUENT_CHECK; |
3320 | } |
3611 | } |
3321 | |
3612 | |
3322 | void noinline |
3613 | void noinline |
3323 | ev_timer_again (EV_P_ ev_timer *w) |
3614 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3324 | { |
3615 | { |
3325 | EV_FREQUENT_CHECK; |
3616 | EV_FREQUENT_CHECK; |
3326 | |
3617 | |
3327 | clear_pending (EV_A_ (W)w); |
3618 | clear_pending (EV_A_ (W)w); |
3328 | |
3619 | |
… | |
… | |
3345 | |
3636 | |
3346 | EV_FREQUENT_CHECK; |
3637 | EV_FREQUENT_CHECK; |
3347 | } |
3638 | } |
3348 | |
3639 | |
3349 | ev_tstamp |
3640 | ev_tstamp |
3350 | ev_timer_remaining (EV_P_ ev_timer *w) |
3641 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3351 | { |
3642 | { |
3352 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3643 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3353 | } |
3644 | } |
3354 | |
3645 | |
3355 | #if EV_PERIODIC_ENABLE |
3646 | #if EV_PERIODIC_ENABLE |
3356 | void noinline |
3647 | void noinline |
3357 | ev_periodic_start (EV_P_ ev_periodic *w) |
3648 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3358 | { |
3649 | { |
3359 | if (expect_false (ev_is_active (w))) |
3650 | if (expect_false (ev_is_active (w))) |
3360 | return; |
3651 | return; |
3361 | |
3652 | |
3362 | if (w->reschedule_cb) |
3653 | if (w->reschedule_cb) |
… | |
… | |
3382 | |
3673 | |
3383 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3674 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3384 | } |
3675 | } |
3385 | |
3676 | |
3386 | void noinline |
3677 | void noinline |
3387 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3678 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3388 | { |
3679 | { |
3389 | clear_pending (EV_A_ (W)w); |
3680 | clear_pending (EV_A_ (W)w); |
3390 | if (expect_false (!ev_is_active (w))) |
3681 | if (expect_false (!ev_is_active (w))) |
3391 | return; |
3682 | return; |
3392 | |
3683 | |
… | |
… | |
3410 | |
3701 | |
3411 | EV_FREQUENT_CHECK; |
3702 | EV_FREQUENT_CHECK; |
3412 | } |
3703 | } |
3413 | |
3704 | |
3414 | void noinline |
3705 | void noinline |
3415 | ev_periodic_again (EV_P_ ev_periodic *w) |
3706 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3416 | { |
3707 | { |
3417 | /* TODO: use adjustheap and recalculation */ |
3708 | /* TODO: use adjustheap and recalculation */ |
3418 | ev_periodic_stop (EV_A_ w); |
3709 | ev_periodic_stop (EV_A_ w); |
3419 | ev_periodic_start (EV_A_ w); |
3710 | ev_periodic_start (EV_A_ w); |
3420 | } |
3711 | } |
… | |
… | |
3425 | #endif |
3716 | #endif |
3426 | |
3717 | |
3427 | #if EV_SIGNAL_ENABLE |
3718 | #if EV_SIGNAL_ENABLE |
3428 | |
3719 | |
3429 | void noinline |
3720 | void noinline |
3430 | ev_signal_start (EV_P_ ev_signal *w) |
3721 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3431 | { |
3722 | { |
3432 | if (expect_false (ev_is_active (w))) |
3723 | if (expect_false (ev_is_active (w))) |
3433 | return; |
3724 | return; |
3434 | |
3725 | |
3435 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3726 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3437 | #if EV_MULTIPLICITY |
3728 | #if EV_MULTIPLICITY |
3438 | assert (("libev: a signal must not be attached to two different loops", |
3729 | assert (("libev: a signal must not be attached to two different loops", |
3439 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
3730 | !signals [w->signum - 1].loop || signals [w->signum - 1].loop == loop)); |
3440 | |
3731 | |
3441 | signals [w->signum - 1].loop = EV_A; |
3732 | signals [w->signum - 1].loop = EV_A; |
|
|
3733 | ECB_MEMORY_FENCE_RELEASE; |
3442 | #endif |
3734 | #endif |
3443 | |
3735 | |
3444 | EV_FREQUENT_CHECK; |
3736 | EV_FREQUENT_CHECK; |
3445 | |
3737 | |
3446 | #if EV_USE_SIGNALFD |
3738 | #if EV_USE_SIGNALFD |
… | |
… | |
3506 | |
3798 | |
3507 | EV_FREQUENT_CHECK; |
3799 | EV_FREQUENT_CHECK; |
3508 | } |
3800 | } |
3509 | |
3801 | |
3510 | void noinline |
3802 | void noinline |
3511 | ev_signal_stop (EV_P_ ev_signal *w) |
3803 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3512 | { |
3804 | { |
3513 | clear_pending (EV_A_ (W)w); |
3805 | clear_pending (EV_A_ (W)w); |
3514 | if (expect_false (!ev_is_active (w))) |
3806 | if (expect_false (!ev_is_active (w))) |
3515 | return; |
3807 | return; |
3516 | |
3808 | |
… | |
… | |
3547 | #endif |
3839 | #endif |
3548 | |
3840 | |
3549 | #if EV_CHILD_ENABLE |
3841 | #if EV_CHILD_ENABLE |
3550 | |
3842 | |
3551 | void |
3843 | void |
3552 | ev_child_start (EV_P_ ev_child *w) |
3844 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3553 | { |
3845 | { |
3554 | #if EV_MULTIPLICITY |
3846 | #if EV_MULTIPLICITY |
3555 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3847 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3556 | #endif |
3848 | #endif |
3557 | if (expect_false (ev_is_active (w))) |
3849 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3564 | |
3856 | |
3565 | EV_FREQUENT_CHECK; |
3857 | EV_FREQUENT_CHECK; |
3566 | } |
3858 | } |
3567 | |
3859 | |
3568 | void |
3860 | void |
3569 | ev_child_stop (EV_P_ ev_child *w) |
3861 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3570 | { |
3862 | { |
3571 | clear_pending (EV_A_ (W)w); |
3863 | clear_pending (EV_A_ (W)w); |
3572 | if (expect_false (!ev_is_active (w))) |
3864 | if (expect_false (!ev_is_active (w))) |
3573 | return; |
3865 | return; |
3574 | |
3866 | |
… | |
… | |
3601 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
3893 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
3602 | |
3894 | |
3603 | static void noinline |
3895 | static void noinline |
3604 | infy_add (EV_P_ ev_stat *w) |
3896 | infy_add (EV_P_ ev_stat *w) |
3605 | { |
3897 | { |
3606 | w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); |
3898 | w->wd = inotify_add_watch (fs_fd, w->path, |
|
|
3899 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
|
|
3900 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
|
|
3901 | | IN_DONT_FOLLOW | IN_MASK_ADD); |
3607 | |
3902 | |
3608 | if (w->wd >= 0) |
3903 | if (w->wd >= 0) |
3609 | { |
3904 | { |
3610 | struct statfs sfs; |
3905 | struct statfs sfs; |
3611 | |
3906 | |
… | |
… | |
3615 | |
3910 | |
3616 | if (!fs_2625) |
3911 | if (!fs_2625) |
3617 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
3912 | w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; |
3618 | else if (!statfs (w->path, &sfs) |
3913 | else if (!statfs (w->path, &sfs) |
3619 | && (sfs.f_type == 0x1373 /* devfs */ |
3914 | && (sfs.f_type == 0x1373 /* devfs */ |
|
|
3915 | || sfs.f_type == 0x4006 /* fat */ |
|
|
3916 | || sfs.f_type == 0x4d44 /* msdos */ |
3620 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
3917 | || sfs.f_type == 0xEF53 /* ext2/3 */ |
|
|
3918 | || sfs.f_type == 0x72b6 /* jffs2 */ |
|
|
3919 | || sfs.f_type == 0x858458f6 /* ramfs */ |
|
|
3920 | || sfs.f_type == 0x5346544e /* ntfs */ |
3621 | || sfs.f_type == 0x3153464a /* jfs */ |
3921 | || sfs.f_type == 0x3153464a /* jfs */ |
|
|
3922 | || sfs.f_type == 0x9123683e /* btrfs */ |
3622 | || sfs.f_type == 0x52654973 /* reiser3 */ |
3923 | || sfs.f_type == 0x52654973 /* reiser3 */ |
3623 | || sfs.f_type == 0x01021994 /* tempfs */ |
3924 | || sfs.f_type == 0x01021994 /* tmpfs */ |
3624 | || sfs.f_type == 0x58465342 /* xfs */)) |
3925 | || sfs.f_type == 0x58465342 /* xfs */)) |
3625 | w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ |
3926 | w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ |
3626 | else |
3927 | else |
3627 | w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ |
3928 | w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ |
3628 | } |
3929 | } |
… | |
… | |
3741 | } |
4042 | } |
3742 | |
4043 | |
3743 | inline_size int |
4044 | inline_size int |
3744 | infy_newfd (void) |
4045 | infy_newfd (void) |
3745 | { |
4046 | { |
3746 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
4047 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3747 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
4048 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3748 | if (fd >= 0) |
4049 | if (fd >= 0) |
3749 | return fd; |
4050 | return fd; |
3750 | #endif |
4051 | #endif |
3751 | return inotify_init (); |
4052 | return inotify_init (); |
… | |
… | |
3826 | #else |
4127 | #else |
3827 | # define EV_LSTAT(p,b) lstat (p, b) |
4128 | # define EV_LSTAT(p,b) lstat (p, b) |
3828 | #endif |
4129 | #endif |
3829 | |
4130 | |
3830 | void |
4131 | void |
3831 | ev_stat_stat (EV_P_ ev_stat *w) |
4132 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3832 | { |
4133 | { |
3833 | if (lstat (w->path, &w->attr) < 0) |
4134 | if (lstat (w->path, &w->attr) < 0) |
3834 | w->attr.st_nlink = 0; |
4135 | w->attr.st_nlink = 0; |
3835 | else if (!w->attr.st_nlink) |
4136 | else if (!w->attr.st_nlink) |
3836 | w->attr.st_nlink = 1; |
4137 | w->attr.st_nlink = 1; |
… | |
… | |
3875 | ev_feed_event (EV_A_ w, EV_STAT); |
4176 | ev_feed_event (EV_A_ w, EV_STAT); |
3876 | } |
4177 | } |
3877 | } |
4178 | } |
3878 | |
4179 | |
3879 | void |
4180 | void |
3880 | ev_stat_start (EV_P_ ev_stat *w) |
4181 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3881 | { |
4182 | { |
3882 | if (expect_false (ev_is_active (w))) |
4183 | if (expect_false (ev_is_active (w))) |
3883 | return; |
4184 | return; |
3884 | |
4185 | |
3885 | ev_stat_stat (EV_A_ w); |
4186 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3906 | |
4207 | |
3907 | EV_FREQUENT_CHECK; |
4208 | EV_FREQUENT_CHECK; |
3908 | } |
4209 | } |
3909 | |
4210 | |
3910 | void |
4211 | void |
3911 | ev_stat_stop (EV_P_ ev_stat *w) |
4212 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3912 | { |
4213 | { |
3913 | clear_pending (EV_A_ (W)w); |
4214 | clear_pending (EV_A_ (W)w); |
3914 | if (expect_false (!ev_is_active (w))) |
4215 | if (expect_false (!ev_is_active (w))) |
3915 | return; |
4216 | return; |
3916 | |
4217 | |
… | |
… | |
3932 | } |
4233 | } |
3933 | #endif |
4234 | #endif |
3934 | |
4235 | |
3935 | #if EV_IDLE_ENABLE |
4236 | #if EV_IDLE_ENABLE |
3936 | void |
4237 | void |
3937 | ev_idle_start (EV_P_ ev_idle *w) |
4238 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3938 | { |
4239 | { |
3939 | if (expect_false (ev_is_active (w))) |
4240 | if (expect_false (ev_is_active (w))) |
3940 | return; |
4241 | return; |
3941 | |
4242 | |
3942 | pri_adjust (EV_A_ (W)w); |
4243 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3955 | |
4256 | |
3956 | EV_FREQUENT_CHECK; |
4257 | EV_FREQUENT_CHECK; |
3957 | } |
4258 | } |
3958 | |
4259 | |
3959 | void |
4260 | void |
3960 | ev_idle_stop (EV_P_ ev_idle *w) |
4261 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3961 | { |
4262 | { |
3962 | clear_pending (EV_A_ (W)w); |
4263 | clear_pending (EV_A_ (W)w); |
3963 | if (expect_false (!ev_is_active (w))) |
4264 | if (expect_false (!ev_is_active (w))) |
3964 | return; |
4265 | return; |
3965 | |
4266 | |
… | |
… | |
3979 | } |
4280 | } |
3980 | #endif |
4281 | #endif |
3981 | |
4282 | |
3982 | #if EV_PREPARE_ENABLE |
4283 | #if EV_PREPARE_ENABLE |
3983 | void |
4284 | void |
3984 | ev_prepare_start (EV_P_ ev_prepare *w) |
4285 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3985 | { |
4286 | { |
3986 | if (expect_false (ev_is_active (w))) |
4287 | if (expect_false (ev_is_active (w))) |
3987 | return; |
4288 | return; |
3988 | |
4289 | |
3989 | EV_FREQUENT_CHECK; |
4290 | EV_FREQUENT_CHECK; |
… | |
… | |
3994 | |
4295 | |
3995 | EV_FREQUENT_CHECK; |
4296 | EV_FREQUENT_CHECK; |
3996 | } |
4297 | } |
3997 | |
4298 | |
3998 | void |
4299 | void |
3999 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4300 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4000 | { |
4301 | { |
4001 | clear_pending (EV_A_ (W)w); |
4302 | clear_pending (EV_A_ (W)w); |
4002 | if (expect_false (!ev_is_active (w))) |
4303 | if (expect_false (!ev_is_active (w))) |
4003 | return; |
4304 | return; |
4004 | |
4305 | |
… | |
… | |
4017 | } |
4318 | } |
4018 | #endif |
4319 | #endif |
4019 | |
4320 | |
4020 | #if EV_CHECK_ENABLE |
4321 | #if EV_CHECK_ENABLE |
4021 | void |
4322 | void |
4022 | ev_check_start (EV_P_ ev_check *w) |
4323 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4023 | { |
4324 | { |
4024 | if (expect_false (ev_is_active (w))) |
4325 | if (expect_false (ev_is_active (w))) |
4025 | return; |
4326 | return; |
4026 | |
4327 | |
4027 | EV_FREQUENT_CHECK; |
4328 | EV_FREQUENT_CHECK; |
… | |
… | |
4032 | |
4333 | |
4033 | EV_FREQUENT_CHECK; |
4334 | EV_FREQUENT_CHECK; |
4034 | } |
4335 | } |
4035 | |
4336 | |
4036 | void |
4337 | void |
4037 | ev_check_stop (EV_P_ ev_check *w) |
4338 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4038 | { |
4339 | { |
4039 | clear_pending (EV_A_ (W)w); |
4340 | clear_pending (EV_A_ (W)w); |
4040 | if (expect_false (!ev_is_active (w))) |
4341 | if (expect_false (!ev_is_active (w))) |
4041 | return; |
4342 | return; |
4042 | |
4343 | |
… | |
… | |
4055 | } |
4356 | } |
4056 | #endif |
4357 | #endif |
4057 | |
4358 | |
4058 | #if EV_EMBED_ENABLE |
4359 | #if EV_EMBED_ENABLE |
4059 | void noinline |
4360 | void noinline |
4060 | ev_embed_sweep (EV_P_ ev_embed *w) |
4361 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4061 | { |
4362 | { |
4062 | ev_run (w->other, EVRUN_NOWAIT); |
4363 | ev_run (w->other, EVRUN_NOWAIT); |
4063 | } |
4364 | } |
4064 | |
4365 | |
4065 | static void |
4366 | static void |
… | |
… | |
4113 | ev_idle_stop (EV_A_ idle); |
4414 | ev_idle_stop (EV_A_ idle); |
4114 | } |
4415 | } |
4115 | #endif |
4416 | #endif |
4116 | |
4417 | |
4117 | void |
4418 | void |
4118 | ev_embed_start (EV_P_ ev_embed *w) |
4419 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4119 | { |
4420 | { |
4120 | if (expect_false (ev_is_active (w))) |
4421 | if (expect_false (ev_is_active (w))) |
4121 | return; |
4422 | return; |
4122 | |
4423 | |
4123 | { |
4424 | { |
… | |
… | |
4144 | |
4445 | |
4145 | EV_FREQUENT_CHECK; |
4446 | EV_FREQUENT_CHECK; |
4146 | } |
4447 | } |
4147 | |
4448 | |
4148 | void |
4449 | void |
4149 | ev_embed_stop (EV_P_ ev_embed *w) |
4450 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4150 | { |
4451 | { |
4151 | clear_pending (EV_A_ (W)w); |
4452 | clear_pending (EV_A_ (W)w); |
4152 | if (expect_false (!ev_is_active (w))) |
4453 | if (expect_false (!ev_is_active (w))) |
4153 | return; |
4454 | return; |
4154 | |
4455 | |
… | |
… | |
4164 | } |
4465 | } |
4165 | #endif |
4466 | #endif |
4166 | |
4467 | |
4167 | #if EV_FORK_ENABLE |
4468 | #if EV_FORK_ENABLE |
4168 | void |
4469 | void |
4169 | ev_fork_start (EV_P_ ev_fork *w) |
4470 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4170 | { |
4471 | { |
4171 | if (expect_false (ev_is_active (w))) |
4472 | if (expect_false (ev_is_active (w))) |
4172 | return; |
4473 | return; |
4173 | |
4474 | |
4174 | EV_FREQUENT_CHECK; |
4475 | EV_FREQUENT_CHECK; |
… | |
… | |
4179 | |
4480 | |
4180 | EV_FREQUENT_CHECK; |
4481 | EV_FREQUENT_CHECK; |
4181 | } |
4482 | } |
4182 | |
4483 | |
4183 | void |
4484 | void |
4184 | ev_fork_stop (EV_P_ ev_fork *w) |
4485 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4185 | { |
4486 | { |
4186 | clear_pending (EV_A_ (W)w); |
4487 | clear_pending (EV_A_ (W)w); |
4187 | if (expect_false (!ev_is_active (w))) |
4488 | if (expect_false (!ev_is_active (w))) |
4188 | return; |
4489 | return; |
4189 | |
4490 | |
… | |
… | |
4202 | } |
4503 | } |
4203 | #endif |
4504 | #endif |
4204 | |
4505 | |
4205 | #if EV_CLEANUP_ENABLE |
4506 | #if EV_CLEANUP_ENABLE |
4206 | void |
4507 | void |
4207 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4508 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4208 | { |
4509 | { |
4209 | if (expect_false (ev_is_active (w))) |
4510 | if (expect_false (ev_is_active (w))) |
4210 | return; |
4511 | return; |
4211 | |
4512 | |
4212 | EV_FREQUENT_CHECK; |
4513 | EV_FREQUENT_CHECK; |
… | |
… | |
4219 | ev_unref (EV_A); |
4520 | ev_unref (EV_A); |
4220 | EV_FREQUENT_CHECK; |
4521 | EV_FREQUENT_CHECK; |
4221 | } |
4522 | } |
4222 | |
4523 | |
4223 | void |
4524 | void |
4224 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4525 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4225 | { |
4526 | { |
4226 | clear_pending (EV_A_ (W)w); |
4527 | clear_pending (EV_A_ (W)w); |
4227 | if (expect_false (!ev_is_active (w))) |
4528 | if (expect_false (!ev_is_active (w))) |
4228 | return; |
4529 | return; |
4229 | |
4530 | |
… | |
… | |
4243 | } |
4544 | } |
4244 | #endif |
4545 | #endif |
4245 | |
4546 | |
4246 | #if EV_ASYNC_ENABLE |
4547 | #if EV_ASYNC_ENABLE |
4247 | void |
4548 | void |
4248 | ev_async_start (EV_P_ ev_async *w) |
4549 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4249 | { |
4550 | { |
4250 | if (expect_false (ev_is_active (w))) |
4551 | if (expect_false (ev_is_active (w))) |
4251 | return; |
4552 | return; |
4252 | |
4553 | |
4253 | w->sent = 0; |
4554 | w->sent = 0; |
… | |
… | |
4262 | |
4563 | |
4263 | EV_FREQUENT_CHECK; |
4564 | EV_FREQUENT_CHECK; |
4264 | } |
4565 | } |
4265 | |
4566 | |
4266 | void |
4567 | void |
4267 | ev_async_stop (EV_P_ ev_async *w) |
4568 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4268 | { |
4569 | { |
4269 | clear_pending (EV_A_ (W)w); |
4570 | clear_pending (EV_A_ (W)w); |
4270 | if (expect_false (!ev_is_active (w))) |
4571 | if (expect_false (!ev_is_active (w))) |
4271 | return; |
4572 | return; |
4272 | |
4573 | |
… | |
… | |
4283 | |
4584 | |
4284 | EV_FREQUENT_CHECK; |
4585 | EV_FREQUENT_CHECK; |
4285 | } |
4586 | } |
4286 | |
4587 | |
4287 | void |
4588 | void |
4288 | ev_async_send (EV_P_ ev_async *w) |
4589 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4289 | { |
4590 | { |
4290 | w->sent = 1; |
4591 | w->sent = 1; |
4291 | evpipe_write (EV_A_ &async_pending); |
4592 | evpipe_write (EV_A_ &async_pending); |
4292 | } |
4593 | } |
4293 | #endif |
4594 | #endif |
… | |
… | |
4330 | |
4631 | |
4331 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4632 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4332 | } |
4633 | } |
4333 | |
4634 | |
4334 | void |
4635 | void |
4335 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4636 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4336 | { |
4637 | { |
4337 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4638 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4338 | |
4639 | |
4339 | if (expect_false (!once)) |
4640 | if (expect_false (!once)) |
4340 | { |
4641 | { |
… | |
… | |
4362 | |
4663 | |
4363 | /*****************************************************************************/ |
4664 | /*****************************************************************************/ |
4364 | |
4665 | |
4365 | #if EV_WALK_ENABLE |
4666 | #if EV_WALK_ENABLE |
4366 | void ecb_cold |
4667 | void ecb_cold |
4367 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4668 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4368 | { |
4669 | { |
4369 | int i, j; |
4670 | int i, j; |
4370 | ev_watcher_list *wl, *wn; |
4671 | ev_watcher_list *wl, *wn; |
4371 | |
4672 | |
4372 | if (types & (EV_IO | EV_EMBED)) |
4673 | if (types & (EV_IO | EV_EMBED)) |