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 0x00010001 |
|
|
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 |
|
|
535 | typedef intptr_t ptrdiff_t; |
526 | #else |
536 | #else |
527 | #include <inttypes.h> |
537 | #include <inttypes.h> |
|
|
538 | #if UINTMAX_MAX > 0xffffffffU |
|
|
539 | #define ECB_PTRSIZE 8 |
|
|
540 | #else |
|
|
541 | #define ECB_PTRSIZE 4 |
|
|
542 | #endif |
528 | #endif |
543 | #endif |
529 | |
544 | |
530 | /* many compilers define _GNUC_ to some versions but then only implement |
545 | /* many compilers define _GNUC_ to some versions but then only implement |
531 | * what their idiot authors think are the "more important" extensions, |
546 | * what their idiot authors think are the "more important" extensions, |
532 | * causing enormous grief in return for some better fake benchmark numbers. |
547 | * causing enormous grief in return for some better fake benchmark numbers. |
533 | * or so. |
548 | * or so. |
534 | * we try to detect these and simply assume they are not gcc - if they have |
549 | * 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. |
550 | * an issue with that they should have done it right in the first place. |
536 | */ |
551 | */ |
537 | #ifndef ECB_GCC_VERSION |
552 | #ifndef ECB_GCC_VERSION |
538 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
553 | #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 |
554 | #define ECB_GCC_VERSION(major,minor) 0 |
540 | #else |
555 | #else |
541 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
556 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
542 | #endif |
557 | #endif |
543 | #endif |
558 | #endif |
544 | |
559 | |
|
|
560 | #define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ |
|
|
561 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
562 | #define ECB_C11 (__STDC_VERSION__ >= 201112L) |
|
|
563 | #define ECB_CPP (__cplusplus+0) |
|
|
564 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
565 | |
545 | /*****************************************************************************/ |
566 | /*****************************************************************************/ |
546 | |
567 | |
547 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
568 | /* 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 */ |
569 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
549 | |
570 | |
550 | #if ECB_NO_THREADS |
571 | #if ECB_NO_THREADS |
551 | # define ECB_NO_SMP 1 |
572 | #define ECB_NO_SMP 1 |
552 | #endif |
573 | #endif |
553 | |
574 | |
554 | #if ECB_NO_THREADS || ECB_NO_SMP |
575 | #if ECB_NO_SMP |
555 | #define ECB_MEMORY_FENCE do { } while (0) |
576 | #define ECB_MEMORY_FENCE do { } while (0) |
556 | #endif |
577 | #endif |
557 | |
578 | |
558 | #ifndef ECB_MEMORY_FENCE |
579 | #ifndef ECB_MEMORY_FENCE |
559 | #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
580 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
560 | #if __i386 || __i386__ |
581 | #if __i386 || __i386__ |
561 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
582 | #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 */ |
583 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
563 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
584 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
564 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
585 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
565 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
586 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
566 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
587 | #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 */ |
588 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
568 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
589 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
590 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
570 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
591 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
571 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
592 | || 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") |
593 | #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__ ) \ |
594 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
574 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
595 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
575 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
596 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
576 | #elif __sparc || __sparc__ |
597 | #elif __sparc || __sparc__ |
577 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
598 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
578 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
599 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
579 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
600 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
580 | #elif defined(__s390__) || defined(__s390x__) |
601 | #elif defined __s390__ || defined __s390x__ |
581 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
602 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
|
|
603 | #elif defined __mips__ |
|
|
604 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
605 | #elif defined __alpha__ |
|
|
606 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
|
|
607 | #elif defined __hppa__ |
|
|
608 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory") |
|
|
609 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
|
|
610 | #elif defined __ia64__ |
|
|
611 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory") |
582 | #endif |
612 | #endif |
583 | #endif |
613 | #endif |
584 | #endif |
614 | #endif |
585 | |
615 | |
586 | #ifndef ECB_MEMORY_FENCE |
616 | #ifndef ECB_MEMORY_FENCE |
|
|
617 | #if ECB_GCC_VERSION(4,7) |
|
|
618 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
|
|
619 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
|
|
620 | #elif defined __clang && __has_feature (cxx_atomic) |
|
|
621 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
|
|
622 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
587 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) |
623 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
588 | #define ECB_MEMORY_FENCE __sync_synchronize () |
624 | #define ECB_MEMORY_FENCE __sync_synchronize () |
589 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
|
|
590 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
|
|
591 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
625 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
592 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
626 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
593 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
627 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
594 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
628 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
595 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
629 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
596 | #elif defined(_WIN32) |
630 | #elif defined _WIN32 |
597 | #include <WinNT.h> |
631 | #include <WinNT.h> |
598 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
632 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
599 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
633 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
600 | #include <mbarrier.h> |
634 | #include <mbarrier.h> |
601 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
635 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
602 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
636 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
603 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
637 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
638 | #elif __xlC__ |
|
|
639 | #define ECB_MEMORY_FENCE __sync () |
|
|
640 | #endif |
|
|
641 | #endif |
|
|
642 | |
|
|
643 | #ifndef ECB_MEMORY_FENCE |
|
|
644 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
|
|
645 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
|
|
646 | /* not just C11 atomics and atomic accesses */ |
|
|
647 | #include <stdatomic.h> |
|
|
648 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
649 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
650 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
651 | /* for most usages, or gcc and clang have a bug */ |
|
|
652 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
653 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
654 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
604 | #endif |
655 | #endif |
605 | #endif |
656 | #endif |
606 | |
657 | |
607 | #ifndef ECB_MEMORY_FENCE |
658 | #ifndef ECB_MEMORY_FENCE |
608 | #if !ECB_AVOID_PTHREADS |
659 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
620 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
671 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
621 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
672 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
622 | #endif |
673 | #endif |
623 | #endif |
674 | #endif |
624 | |
675 | |
625 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
676 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
626 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
677 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
627 | #endif |
678 | #endif |
628 | |
679 | |
629 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
680 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
630 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
681 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
631 | #endif |
682 | #endif |
632 | |
683 | |
633 | /*****************************************************************************/ |
684 | /*****************************************************************************/ |
634 | |
|
|
635 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
636 | |
685 | |
637 | #if __cplusplus |
686 | #if __cplusplus |
638 | #define ecb_inline static inline |
687 | #define ecb_inline static inline |
639 | #elif ECB_GCC_VERSION(2,5) |
688 | #elif ECB_GCC_VERSION(2,5) |
640 | #define ecb_inline static __inline__ |
689 | #define ecb_inline static __inline__ |
… | |
… | |
679 | #elif ECB_GCC_VERSION(3,0) |
728 | #elif ECB_GCC_VERSION(3,0) |
680 | #define ecb_decltype(x) __typeof(x) |
729 | #define ecb_decltype(x) __typeof(x) |
681 | #endif |
730 | #endif |
682 | |
731 | |
683 | #define ecb_noinline ecb_attribute ((__noinline__)) |
732 | #define ecb_noinline ecb_attribute ((__noinline__)) |
684 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
685 | #define ecb_unused ecb_attribute ((__unused__)) |
733 | #define ecb_unused ecb_attribute ((__unused__)) |
686 | #define ecb_const ecb_attribute ((__const__)) |
734 | #define ecb_const ecb_attribute ((__const__)) |
687 | #define ecb_pure ecb_attribute ((__pure__)) |
735 | #define ecb_pure ecb_attribute ((__pure__)) |
|
|
736 | |
|
|
737 | #if ECB_C11 |
|
|
738 | #define ecb_noreturn _Noreturn |
|
|
739 | #else |
|
|
740 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
|
|
741 | #endif |
688 | |
742 | |
689 | #if ECB_GCC_VERSION(4,3) |
743 | #if ECB_GCC_VERSION(4,3) |
690 | #define ecb_artificial ecb_attribute ((__artificial__)) |
744 | #define ecb_artificial ecb_attribute ((__artificial__)) |
691 | #define ecb_hot ecb_attribute ((__hot__)) |
745 | #define ecb_hot ecb_attribute ((__hot__)) |
692 | #define ecb_cold ecb_attribute ((__cold__)) |
746 | #define ecb_cold ecb_attribute ((__cold__)) |
… | |
… | |
783 | |
837 | |
784 | return r + ecb_ld32 (x); |
838 | return r + ecb_ld32 (x); |
785 | } |
839 | } |
786 | #endif |
840 | #endif |
787 | |
841 | |
|
|
842 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) ecb_const; |
|
|
843 | ecb_function_ ecb_bool ecb_is_pot32 (uint32_t x) { return !(x & (x - 1)); } |
|
|
844 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) ecb_const; |
|
|
845 | ecb_function_ ecb_bool ecb_is_pot64 (uint64_t x) { return !(x & (x - 1)); } |
|
|
846 | |
788 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
847 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
789 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
848 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
790 | { |
849 | { |
791 | return ( (x * 0x0802U & 0x22110U) |
850 | return ( (x * 0x0802U & 0x22110U) |
792 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
851 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
… | |
… | |
1099 | { |
1158 | { |
1100 | write (STDERR_FILENO, msg, strlen (msg)); |
1159 | write (STDERR_FILENO, msg, strlen (msg)); |
1101 | } |
1160 | } |
1102 | #endif |
1161 | #endif |
1103 | |
1162 | |
1104 | static void (*syserr_cb)(const char *msg); |
1163 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1105 | |
1164 | |
1106 | void ecb_cold |
1165 | void ecb_cold |
1107 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1166 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1108 | { |
1167 | { |
1109 | syserr_cb = cb; |
1168 | syserr_cb = cb; |
1110 | } |
1169 | } |
1111 | |
1170 | |
1112 | static void noinline ecb_cold |
1171 | static void noinline ecb_cold |
… | |
… | |
1130 | abort (); |
1189 | abort (); |
1131 | } |
1190 | } |
1132 | } |
1191 | } |
1133 | |
1192 | |
1134 | static void * |
1193 | static void * |
1135 | ev_realloc_emul (void *ptr, long size) |
1194 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1136 | { |
1195 | { |
1137 | #if __GLIBC__ |
1196 | #if __GLIBC__ |
1138 | return realloc (ptr, size); |
1197 | return realloc (ptr, size); |
1139 | #else |
1198 | #else |
1140 | /* some systems, notably openbsd and darwin, fail to properly |
1199 | /* some systems, notably openbsd and darwin, fail to properly |
… | |
… | |
1148 | free (ptr); |
1207 | free (ptr); |
1149 | return 0; |
1208 | return 0; |
1150 | #endif |
1209 | #endif |
1151 | } |
1210 | } |
1152 | |
1211 | |
1153 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1212 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1154 | |
1213 | |
1155 | void ecb_cold |
1214 | void ecb_cold |
1156 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1215 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1157 | { |
1216 | { |
1158 | alloc = cb; |
1217 | alloc = cb; |
1159 | } |
1218 | } |
1160 | |
1219 | |
1161 | inline_speed void * |
1220 | inline_speed void * |
… | |
… | |
1278 | |
1337 | |
1279 | /*****************************************************************************/ |
1338 | /*****************************************************************************/ |
1280 | |
1339 | |
1281 | #ifndef EV_HAVE_EV_TIME |
1340 | #ifndef EV_HAVE_EV_TIME |
1282 | ev_tstamp |
1341 | ev_tstamp |
1283 | ev_time (void) |
1342 | ev_time (void) EV_THROW |
1284 | { |
1343 | { |
1285 | #if EV_USE_REALTIME |
1344 | #if EV_USE_REALTIME |
1286 | if (expect_true (have_realtime)) |
1345 | if (expect_true (have_realtime)) |
1287 | { |
1346 | { |
1288 | struct timespec ts; |
1347 | struct timespec ts; |
… | |
… | |
1312 | return ev_time (); |
1371 | return ev_time (); |
1313 | } |
1372 | } |
1314 | |
1373 | |
1315 | #if EV_MULTIPLICITY |
1374 | #if EV_MULTIPLICITY |
1316 | ev_tstamp |
1375 | ev_tstamp |
1317 | ev_now (EV_P) |
1376 | ev_now (EV_P) EV_THROW |
1318 | { |
1377 | { |
1319 | return ev_rt_now; |
1378 | return ev_rt_now; |
1320 | } |
1379 | } |
1321 | #endif |
1380 | #endif |
1322 | |
1381 | |
1323 | void |
1382 | void |
1324 | ev_sleep (ev_tstamp delay) |
1383 | ev_sleep (ev_tstamp delay) EV_THROW |
1325 | { |
1384 | { |
1326 | if (delay > 0.) |
1385 | if (delay > 0.) |
1327 | { |
1386 | { |
1328 | #if EV_USE_NANOSLEEP |
1387 | #if EV_USE_NANOSLEEP |
1329 | struct timespec ts; |
1388 | struct timespec ts; |
1330 | |
1389 | |
1331 | EV_TS_SET (ts, delay); |
1390 | EV_TS_SET (ts, delay); |
1332 | nanosleep (&ts, 0); |
1391 | nanosleep (&ts, 0); |
1333 | #elif defined(_WIN32) |
1392 | #elif defined _WIN32 |
1334 | Sleep ((unsigned long)(delay * 1e3)); |
1393 | Sleep ((unsigned long)(delay * 1e3)); |
1335 | #else |
1394 | #else |
1336 | struct timeval tv; |
1395 | struct timeval tv; |
1337 | |
1396 | |
1338 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1397 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1410 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1469 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1411 | { |
1470 | { |
1412 | } |
1471 | } |
1413 | |
1472 | |
1414 | void noinline |
1473 | void noinline |
1415 | ev_feed_event (EV_P_ void *w, int revents) |
1474 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1416 | { |
1475 | { |
1417 | W w_ = (W)w; |
1476 | W w_ = (W)w; |
1418 | int pri = ABSPRI (w_); |
1477 | int pri = ABSPRI (w_); |
1419 | |
1478 | |
1420 | if (expect_false (w_->pending)) |
1479 | if (expect_false (w_->pending)) |
… | |
… | |
1424 | w_->pending = ++pendingcnt [pri]; |
1483 | w_->pending = ++pendingcnt [pri]; |
1425 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1484 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1426 | pendings [pri][w_->pending - 1].w = w_; |
1485 | pendings [pri][w_->pending - 1].w = w_; |
1427 | pendings [pri][w_->pending - 1].events = revents; |
1486 | pendings [pri][w_->pending - 1].events = revents; |
1428 | } |
1487 | } |
|
|
1488 | |
|
|
1489 | pendingpri = NUMPRI - 1; |
1429 | } |
1490 | } |
1430 | |
1491 | |
1431 | inline_speed void |
1492 | inline_speed void |
1432 | feed_reverse (EV_P_ W w) |
1493 | feed_reverse (EV_P_ W w) |
1433 | { |
1494 | { |
… | |
… | |
1479 | if (expect_true (!anfd->reify)) |
1540 | if (expect_true (!anfd->reify)) |
1480 | fd_event_nocheck (EV_A_ fd, revents); |
1541 | fd_event_nocheck (EV_A_ fd, revents); |
1481 | } |
1542 | } |
1482 | |
1543 | |
1483 | void |
1544 | void |
1484 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1545 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1485 | { |
1546 | { |
1486 | if (fd >= 0 && fd < anfdmax) |
1547 | if (fd >= 0 && fd < anfdmax) |
1487 | fd_event_nocheck (EV_A_ fd, revents); |
1548 | fd_event_nocheck (EV_A_ fd, revents); |
1488 | } |
1549 | } |
1489 | |
1550 | |
… | |
… | |
1838 | } |
1899 | } |
1839 | |
1900 | |
1840 | inline_speed void |
1901 | inline_speed void |
1841 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1902 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1842 | { |
1903 | { |
|
|
1904 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1905 | |
1843 | if (expect_true (*flag)) |
1906 | if (expect_true (*flag)) |
1844 | return; |
1907 | return; |
1845 | |
1908 | |
1846 | *flag = 1; |
1909 | *flag = 1; |
1847 | |
|
|
1848 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
1910 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
1849 | |
1911 | |
1850 | pipe_write_skipped = 1; |
1912 | pipe_write_skipped = 1; |
1851 | |
1913 | |
1852 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
1914 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
1853 | |
1915 | |
1854 | if (pipe_write_wanted) |
1916 | if (pipe_write_wanted) |
1855 | { |
1917 | { |
1856 | int old_errno; |
1918 | int old_errno; |
1857 | |
1919 | |
1858 | pipe_write_skipped = 0; /* just an optimisation, no fence needed */ |
1920 | pipe_write_skipped = 0; |
|
|
1921 | ECB_MEMORY_FENCE_RELEASE; |
1859 | |
1922 | |
1860 | old_errno = errno; /* save errno because write will clobber it */ |
1923 | old_errno = errno; /* save errno because write will clobber it */ |
1861 | |
1924 | |
1862 | #if EV_USE_EVENTFD |
1925 | #if EV_USE_EVENTFD |
1863 | if (evfd >= 0) |
1926 | if (evfd >= 0) |
… | |
… | |
1866 | write (evfd, &counter, sizeof (uint64_t)); |
1929 | write (evfd, &counter, sizeof (uint64_t)); |
1867 | } |
1930 | } |
1868 | else |
1931 | else |
1869 | #endif |
1932 | #endif |
1870 | { |
1933 | { |
1871 | /* win32 people keep sending patches that change this write() to send() */ |
1934 | #ifdef _WIN32 |
1872 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1935 | WSABUF buf; |
1873 | /* so when you think this write should be a send instead, please find out */ |
1936 | DWORD sent; |
1874 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1937 | buf.buf = &buf; |
1875 | /* tell me. thank you. */ |
1938 | buf.len = 1; |
1876 | /* it might be that your problem is that your environment needs EV_USE_WSASOCKET */ |
1939 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
1877 | /* check the ev documentation on how to use this flag */ |
1940 | #else |
1878 | write (evpipe [1], &(evpipe [1]), 1); |
1941 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1942 | #endif |
1879 | } |
1943 | } |
1880 | |
1944 | |
1881 | errno = old_errno; |
1945 | errno = old_errno; |
1882 | } |
1946 | } |
1883 | } |
1947 | } |
… | |
… | |
1898 | read (evfd, &counter, sizeof (uint64_t)); |
1962 | read (evfd, &counter, sizeof (uint64_t)); |
1899 | } |
1963 | } |
1900 | else |
1964 | else |
1901 | #endif |
1965 | #endif |
1902 | { |
1966 | { |
1903 | char dummy; |
1967 | char dummy[4]; |
1904 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1968 | #ifdef _WIN32 |
|
|
1969 | WSABUF buf; |
|
|
1970 | DWORD recvd; |
|
|
1971 | DWORD flags = 0; |
|
|
1972 | buf.buf = dummy; |
|
|
1973 | buf.len = sizeof (dummy); |
|
|
1974 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0); |
|
|
1975 | #else |
1905 | read (evpipe [0], &dummy, 1); |
1976 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1977 | #endif |
1906 | } |
1978 | } |
1907 | } |
1979 | } |
1908 | |
1980 | |
1909 | pipe_write_skipped = 0; |
1981 | pipe_write_skipped = 0; |
|
|
1982 | |
|
|
1983 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1910 | |
1984 | |
1911 | #if EV_SIGNAL_ENABLE |
1985 | #if EV_SIGNAL_ENABLE |
1912 | if (sig_pending) |
1986 | if (sig_pending) |
1913 | { |
1987 | { |
1914 | sig_pending = 0; |
1988 | sig_pending = 0; |
|
|
1989 | |
|
|
1990 | ECB_MEMORY_FENCE; |
1915 | |
1991 | |
1916 | for (i = EV_NSIG - 1; i--; ) |
1992 | for (i = EV_NSIG - 1; i--; ) |
1917 | if (expect_false (signals [i].pending)) |
1993 | if (expect_false (signals [i].pending)) |
1918 | ev_feed_signal_event (EV_A_ i + 1); |
1994 | ev_feed_signal_event (EV_A_ i + 1); |
1919 | } |
1995 | } |
… | |
… | |
1921 | |
1997 | |
1922 | #if EV_ASYNC_ENABLE |
1998 | #if EV_ASYNC_ENABLE |
1923 | if (async_pending) |
1999 | if (async_pending) |
1924 | { |
2000 | { |
1925 | async_pending = 0; |
2001 | async_pending = 0; |
|
|
2002 | |
|
|
2003 | ECB_MEMORY_FENCE; |
1926 | |
2004 | |
1927 | for (i = asynccnt; i--; ) |
2005 | for (i = asynccnt; i--; ) |
1928 | if (asyncs [i]->sent) |
2006 | if (asyncs [i]->sent) |
1929 | { |
2007 | { |
1930 | asyncs [i]->sent = 0; |
2008 | asyncs [i]->sent = 0; |
|
|
2009 | ECB_MEMORY_FENCE_RELEASE; |
1931 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
2010 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
1932 | } |
2011 | } |
1933 | } |
2012 | } |
1934 | #endif |
2013 | #endif |
1935 | } |
2014 | } |
1936 | |
2015 | |
1937 | /*****************************************************************************/ |
2016 | /*****************************************************************************/ |
1938 | |
2017 | |
1939 | void |
2018 | void |
1940 | ev_feed_signal (int signum) |
2019 | ev_feed_signal (int signum) EV_THROW |
1941 | { |
2020 | { |
1942 | #if EV_MULTIPLICITY |
2021 | #if EV_MULTIPLICITY |
1943 | EV_P = signals [signum - 1].loop; |
2022 | EV_P = signals [signum - 1].loop; |
1944 | |
2023 | |
1945 | if (!EV_A) |
2024 | if (!EV_A) |
… | |
… | |
1962 | |
2041 | |
1963 | ev_feed_signal (signum); |
2042 | ev_feed_signal (signum); |
1964 | } |
2043 | } |
1965 | |
2044 | |
1966 | void noinline |
2045 | void noinline |
1967 | ev_feed_signal_event (EV_P_ int signum) |
2046 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1968 | { |
2047 | { |
1969 | WL w; |
2048 | WL w; |
1970 | |
2049 | |
1971 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
2050 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1972 | return; |
2051 | return; |
… | |
… | |
1980 | if (expect_false (signals [signum].loop != EV_A)) |
2059 | if (expect_false (signals [signum].loop != EV_A)) |
1981 | return; |
2060 | return; |
1982 | #endif |
2061 | #endif |
1983 | |
2062 | |
1984 | signals [signum].pending = 0; |
2063 | signals [signum].pending = 0; |
|
|
2064 | ECB_MEMORY_FENCE_RELEASE; |
1985 | |
2065 | |
1986 | for (w = signals [signum].head; w; w = w->next) |
2066 | for (w = signals [signum].head; w; w = w->next) |
1987 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
2067 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1988 | } |
2068 | } |
1989 | |
2069 | |
… | |
… | |
2088 | #if EV_USE_SELECT |
2168 | #if EV_USE_SELECT |
2089 | # include "ev_select.c" |
2169 | # include "ev_select.c" |
2090 | #endif |
2170 | #endif |
2091 | |
2171 | |
2092 | int ecb_cold |
2172 | int ecb_cold |
2093 | ev_version_major (void) |
2173 | ev_version_major (void) EV_THROW |
2094 | { |
2174 | { |
2095 | return EV_VERSION_MAJOR; |
2175 | return EV_VERSION_MAJOR; |
2096 | } |
2176 | } |
2097 | |
2177 | |
2098 | int ecb_cold |
2178 | int ecb_cold |
2099 | ev_version_minor (void) |
2179 | ev_version_minor (void) EV_THROW |
2100 | { |
2180 | { |
2101 | return EV_VERSION_MINOR; |
2181 | return EV_VERSION_MINOR; |
2102 | } |
2182 | } |
2103 | |
2183 | |
2104 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2184 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2112 | || getgid () != getegid (); |
2192 | || getgid () != getegid (); |
2113 | #endif |
2193 | #endif |
2114 | } |
2194 | } |
2115 | |
2195 | |
2116 | unsigned int ecb_cold |
2196 | unsigned int ecb_cold |
2117 | ev_supported_backends (void) |
2197 | ev_supported_backends (void) EV_THROW |
2118 | { |
2198 | { |
2119 | unsigned int flags = 0; |
2199 | unsigned int flags = 0; |
2120 | |
2200 | |
2121 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2201 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2122 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2202 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2126 | |
2206 | |
2127 | return flags; |
2207 | return flags; |
2128 | } |
2208 | } |
2129 | |
2209 | |
2130 | unsigned int ecb_cold |
2210 | unsigned int ecb_cold |
2131 | ev_recommended_backends (void) |
2211 | ev_recommended_backends (void) EV_THROW |
2132 | { |
2212 | { |
2133 | unsigned int flags = ev_supported_backends (); |
2213 | unsigned int flags = ev_supported_backends (); |
2134 | |
2214 | |
2135 | #ifndef __NetBSD__ |
2215 | #ifndef __NetBSD__ |
2136 | /* kqueue is borked on everything but netbsd apparently */ |
2216 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2148 | |
2228 | |
2149 | return flags; |
2229 | return flags; |
2150 | } |
2230 | } |
2151 | |
2231 | |
2152 | unsigned int ecb_cold |
2232 | unsigned int ecb_cold |
2153 | ev_embeddable_backends (void) |
2233 | ev_embeddable_backends (void) EV_THROW |
2154 | { |
2234 | { |
2155 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2235 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2156 | |
2236 | |
2157 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2237 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2158 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2238 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2160 | |
2240 | |
2161 | return flags; |
2241 | return flags; |
2162 | } |
2242 | } |
2163 | |
2243 | |
2164 | unsigned int |
2244 | unsigned int |
2165 | ev_backend (EV_P) |
2245 | ev_backend (EV_P) EV_THROW |
2166 | { |
2246 | { |
2167 | return backend; |
2247 | return backend; |
2168 | } |
2248 | } |
2169 | |
2249 | |
2170 | #if EV_FEATURE_API |
2250 | #if EV_FEATURE_API |
2171 | unsigned int |
2251 | unsigned int |
2172 | ev_iteration (EV_P) |
2252 | ev_iteration (EV_P) EV_THROW |
2173 | { |
2253 | { |
2174 | return loop_count; |
2254 | return loop_count; |
2175 | } |
2255 | } |
2176 | |
2256 | |
2177 | unsigned int |
2257 | unsigned int |
2178 | ev_depth (EV_P) |
2258 | ev_depth (EV_P) EV_THROW |
2179 | { |
2259 | { |
2180 | return loop_depth; |
2260 | return loop_depth; |
2181 | } |
2261 | } |
2182 | |
2262 | |
2183 | void |
2263 | void |
2184 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2264 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2185 | { |
2265 | { |
2186 | io_blocktime = interval; |
2266 | io_blocktime = interval; |
2187 | } |
2267 | } |
2188 | |
2268 | |
2189 | void |
2269 | void |
2190 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2270 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2191 | { |
2271 | { |
2192 | timeout_blocktime = interval; |
2272 | timeout_blocktime = interval; |
2193 | } |
2273 | } |
2194 | |
2274 | |
2195 | void |
2275 | void |
2196 | ev_set_userdata (EV_P_ void *data) |
2276 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2197 | { |
2277 | { |
2198 | userdata = data; |
2278 | userdata = data; |
2199 | } |
2279 | } |
2200 | |
2280 | |
2201 | void * |
2281 | void * |
2202 | ev_userdata (EV_P) |
2282 | ev_userdata (EV_P) EV_THROW |
2203 | { |
2283 | { |
2204 | return userdata; |
2284 | return userdata; |
2205 | } |
2285 | } |
2206 | |
2286 | |
2207 | void |
2287 | void |
2208 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2288 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2209 | { |
2289 | { |
2210 | invoke_cb = invoke_pending_cb; |
2290 | invoke_cb = invoke_pending_cb; |
2211 | } |
2291 | } |
2212 | |
2292 | |
2213 | void |
2293 | void |
2214 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2294 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2215 | { |
2295 | { |
2216 | release_cb = release; |
2296 | release_cb = release; |
2217 | acquire_cb = acquire; |
2297 | acquire_cb = acquire; |
2218 | } |
2298 | } |
2219 | #endif |
2299 | #endif |
2220 | |
2300 | |
2221 | /* initialise a loop structure, must be zero-initialised */ |
2301 | /* initialise a loop structure, must be zero-initialised */ |
2222 | static void noinline ecb_cold |
2302 | static void noinline ecb_cold |
2223 | loop_init (EV_P_ unsigned int flags) |
2303 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2224 | { |
2304 | { |
2225 | if (!backend) |
2305 | if (!backend) |
2226 | { |
2306 | { |
2227 | origflags = flags; |
2307 | origflags = flags; |
2228 | |
2308 | |
… | |
… | |
2333 | EV_INVOKE_PENDING; |
2413 | EV_INVOKE_PENDING; |
2334 | } |
2414 | } |
2335 | #endif |
2415 | #endif |
2336 | |
2416 | |
2337 | #if EV_CHILD_ENABLE |
2417 | #if EV_CHILD_ENABLE |
2338 | if (ev_is_active (&childev)) |
2418 | if (ev_is_default_loop (EV_A) && ev_is_active (&childev)) |
2339 | { |
2419 | { |
2340 | ev_ref (EV_A); /* child watcher */ |
2420 | ev_ref (EV_A); /* child watcher */ |
2341 | ev_signal_stop (EV_A_ &childev); |
2421 | ev_signal_stop (EV_A_ &childev); |
2342 | } |
2422 | } |
2343 | #endif |
2423 | #endif |
… | |
… | |
2470 | EV_WIN32_CLOSE_FD (evpipe [1]); |
2550 | EV_WIN32_CLOSE_FD (evpipe [1]); |
2471 | } |
2551 | } |
2472 | |
2552 | |
2473 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2553 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2474 | evpipe_init (EV_A); |
2554 | evpipe_init (EV_A); |
2475 | /* now iterate over everything, in case we missed something */ |
2555 | /* iterate over everything, in case we missed something before */ |
2476 | pipecb (EV_A_ &pipe_w, EV_READ); |
2556 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
2477 | #endif |
2557 | #endif |
2478 | } |
2558 | } |
2479 | |
2559 | |
2480 | postfork = 0; |
2560 | postfork = 0; |
2481 | } |
2561 | } |
2482 | |
2562 | |
2483 | #if EV_MULTIPLICITY |
2563 | #if EV_MULTIPLICITY |
2484 | |
2564 | |
2485 | struct ev_loop * ecb_cold |
2565 | struct ev_loop * ecb_cold |
2486 | ev_loop_new (unsigned int flags) |
2566 | ev_loop_new (unsigned int flags) EV_THROW |
2487 | { |
2567 | { |
2488 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2568 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2489 | |
2569 | |
2490 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2570 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2491 | loop_init (EV_A_ flags); |
2571 | loop_init (EV_A_ flags); |
… | |
… | |
2535 | } |
2615 | } |
2536 | #endif |
2616 | #endif |
2537 | |
2617 | |
2538 | #if EV_FEATURE_API |
2618 | #if EV_FEATURE_API |
2539 | void ecb_cold |
2619 | void ecb_cold |
2540 | ev_verify (EV_P) |
2620 | ev_verify (EV_P) EV_THROW |
2541 | { |
2621 | { |
2542 | #if EV_VERIFY |
2622 | #if EV_VERIFY |
2543 | int i; |
2623 | int i; |
2544 | WL w; |
2624 | WL w, w2; |
2545 | |
2625 | |
2546 | assert (activecnt >= -1); |
2626 | assert (activecnt >= -1); |
2547 | |
2627 | |
2548 | assert (fdchangemax >= fdchangecnt); |
2628 | assert (fdchangemax >= fdchangecnt); |
2549 | for (i = 0; i < fdchangecnt; ++i) |
2629 | for (i = 0; i < fdchangecnt; ++i) |
2550 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2630 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2551 | |
2631 | |
2552 | assert (anfdmax >= 0); |
2632 | assert (anfdmax >= 0); |
2553 | for (i = 0; i < anfdmax; ++i) |
2633 | for (i = 0; i < anfdmax; ++i) |
|
|
2634 | { |
|
|
2635 | int j = 0; |
|
|
2636 | |
2554 | for (w = anfds [i].head; w; w = w->next) |
2637 | for (w = w2 = anfds [i].head; w; w = w->next) |
2555 | { |
2638 | { |
2556 | verify_watcher (EV_A_ (W)w); |
2639 | verify_watcher (EV_A_ (W)w); |
|
|
2640 | |
|
|
2641 | if (j++ & 1) |
|
|
2642 | { |
|
|
2643 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2644 | w2 = w2->next; |
|
|
2645 | } |
|
|
2646 | |
2557 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2647 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2558 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2648 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2559 | } |
2649 | } |
|
|
2650 | } |
2560 | |
2651 | |
2561 | assert (timermax >= timercnt); |
2652 | assert (timermax >= timercnt); |
2562 | verify_heap (EV_A_ timers, timercnt); |
2653 | verify_heap (EV_A_ timers, timercnt); |
2563 | |
2654 | |
2564 | #if EV_PERIODIC_ENABLE |
2655 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2614 | #if EV_MULTIPLICITY |
2705 | #if EV_MULTIPLICITY |
2615 | struct ev_loop * ecb_cold |
2706 | struct ev_loop * ecb_cold |
2616 | #else |
2707 | #else |
2617 | int |
2708 | int |
2618 | #endif |
2709 | #endif |
2619 | ev_default_loop (unsigned int flags) |
2710 | ev_default_loop (unsigned int flags) EV_THROW |
2620 | { |
2711 | { |
2621 | if (!ev_default_loop_ptr) |
2712 | if (!ev_default_loop_ptr) |
2622 | { |
2713 | { |
2623 | #if EV_MULTIPLICITY |
2714 | #if EV_MULTIPLICITY |
2624 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2715 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2643 | |
2734 | |
2644 | return ev_default_loop_ptr; |
2735 | return ev_default_loop_ptr; |
2645 | } |
2736 | } |
2646 | |
2737 | |
2647 | void |
2738 | void |
2648 | ev_loop_fork (EV_P) |
2739 | ev_loop_fork (EV_P) EV_THROW |
2649 | { |
2740 | { |
2650 | postfork = 1; /* must be in line with ev_default_fork */ |
2741 | postfork = 1; |
2651 | } |
2742 | } |
2652 | |
2743 | |
2653 | /*****************************************************************************/ |
2744 | /*****************************************************************************/ |
2654 | |
2745 | |
2655 | void |
2746 | void |
… | |
… | |
2657 | { |
2748 | { |
2658 | EV_CB_INVOKE ((W)w, revents); |
2749 | EV_CB_INVOKE ((W)w, revents); |
2659 | } |
2750 | } |
2660 | |
2751 | |
2661 | unsigned int |
2752 | unsigned int |
2662 | ev_pending_count (EV_P) |
2753 | ev_pending_count (EV_P) EV_THROW |
2663 | { |
2754 | { |
2664 | int pri; |
2755 | int pri; |
2665 | unsigned int count = 0; |
2756 | unsigned int count = 0; |
2666 | |
2757 | |
2667 | for (pri = NUMPRI; pri--; ) |
2758 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2671 | } |
2762 | } |
2672 | |
2763 | |
2673 | void noinline |
2764 | void noinline |
2674 | ev_invoke_pending (EV_P) |
2765 | ev_invoke_pending (EV_P) |
2675 | { |
2766 | { |
2676 | int pri; |
2767 | pendingpri = NUMPRI; |
2677 | |
2768 | |
2678 | for (pri = NUMPRI; pri--; ) |
2769 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
|
|
2770 | { |
|
|
2771 | --pendingpri; |
|
|
2772 | |
2679 | while (pendingcnt [pri]) |
2773 | while (pendingcnt [pendingpri]) |
2680 | { |
2774 | { |
2681 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2775 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2682 | |
2776 | |
2683 | p->w->pending = 0; |
2777 | p->w->pending = 0; |
2684 | EV_CB_INVOKE (p->w, p->events); |
2778 | EV_CB_INVOKE (p->w, p->events); |
2685 | EV_FREQUENT_CHECK; |
2779 | EV_FREQUENT_CHECK; |
2686 | } |
2780 | } |
|
|
2781 | } |
2687 | } |
2782 | } |
2688 | |
2783 | |
2689 | #if EV_IDLE_ENABLE |
2784 | #if EV_IDLE_ENABLE |
2690 | /* make idle watchers pending. this handles the "call-idle */ |
2785 | /* make idle watchers pending. this handles the "call-idle */ |
2691 | /* only when higher priorities are idle" logic */ |
2786 | /* only when higher priorities are idle" logic */ |
… | |
… | |
2781 | { |
2876 | { |
2782 | EV_FREQUENT_CHECK; |
2877 | EV_FREQUENT_CHECK; |
2783 | |
2878 | |
2784 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2879 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2785 | { |
2880 | { |
2786 | int feed_count = 0; |
|
|
2787 | |
|
|
2788 | do |
2881 | do |
2789 | { |
2882 | { |
2790 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2883 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2791 | |
2884 | |
2792 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
2885 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
2926 | |
3019 | |
2927 | mn_now = ev_rt_now; |
3020 | mn_now = ev_rt_now; |
2928 | } |
3021 | } |
2929 | } |
3022 | } |
2930 | |
3023 | |
2931 | void |
3024 | int |
2932 | ev_run (EV_P_ int flags) |
3025 | ev_run (EV_P_ int flags) |
2933 | { |
3026 | { |
2934 | #if EV_FEATURE_API |
3027 | #if EV_FEATURE_API |
2935 | ++loop_depth; |
3028 | ++loop_depth; |
2936 | #endif |
3029 | #endif |
… | |
… | |
3051 | backend_poll (EV_A_ waittime); |
3144 | backend_poll (EV_A_ waittime); |
3052 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3145 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3053 | |
3146 | |
3054 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3147 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3055 | |
3148 | |
|
|
3149 | ECB_MEMORY_FENCE_ACQUIRE; |
3056 | if (pipe_write_skipped) |
3150 | if (pipe_write_skipped) |
3057 | { |
3151 | { |
3058 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3152 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3059 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3153 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3060 | } |
3154 | } |
… | |
… | |
3093 | loop_done = EVBREAK_CANCEL; |
3187 | loop_done = EVBREAK_CANCEL; |
3094 | |
3188 | |
3095 | #if EV_FEATURE_API |
3189 | #if EV_FEATURE_API |
3096 | --loop_depth; |
3190 | --loop_depth; |
3097 | #endif |
3191 | #endif |
|
|
3192 | |
|
|
3193 | return activecnt; |
3098 | } |
3194 | } |
3099 | |
3195 | |
3100 | void |
3196 | void |
3101 | ev_break (EV_P_ int how) |
3197 | ev_break (EV_P_ int how) EV_THROW |
3102 | { |
3198 | { |
3103 | loop_done = how; |
3199 | loop_done = how; |
3104 | } |
3200 | } |
3105 | |
3201 | |
3106 | void |
3202 | void |
3107 | ev_ref (EV_P) |
3203 | ev_ref (EV_P) EV_THROW |
3108 | { |
3204 | { |
3109 | ++activecnt; |
3205 | ++activecnt; |
3110 | } |
3206 | } |
3111 | |
3207 | |
3112 | void |
3208 | void |
3113 | ev_unref (EV_P) |
3209 | ev_unref (EV_P) EV_THROW |
3114 | { |
3210 | { |
3115 | --activecnt; |
3211 | --activecnt; |
3116 | } |
3212 | } |
3117 | |
3213 | |
3118 | void |
3214 | void |
3119 | ev_now_update (EV_P) |
3215 | ev_now_update (EV_P) EV_THROW |
3120 | { |
3216 | { |
3121 | time_update (EV_A_ 1e100); |
3217 | time_update (EV_A_ 1e100); |
3122 | } |
3218 | } |
3123 | |
3219 | |
3124 | void |
3220 | void |
3125 | ev_suspend (EV_P) |
3221 | ev_suspend (EV_P) EV_THROW |
3126 | { |
3222 | { |
3127 | ev_now_update (EV_A); |
3223 | ev_now_update (EV_A); |
3128 | } |
3224 | } |
3129 | |
3225 | |
3130 | void |
3226 | void |
3131 | ev_resume (EV_P) |
3227 | ev_resume (EV_P) EV_THROW |
3132 | { |
3228 | { |
3133 | ev_tstamp mn_prev = mn_now; |
3229 | ev_tstamp mn_prev = mn_now; |
3134 | |
3230 | |
3135 | ev_now_update (EV_A); |
3231 | ev_now_update (EV_A); |
3136 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3232 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3175 | w->pending = 0; |
3271 | w->pending = 0; |
3176 | } |
3272 | } |
3177 | } |
3273 | } |
3178 | |
3274 | |
3179 | int |
3275 | int |
3180 | ev_clear_pending (EV_P_ void *w) |
3276 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3181 | { |
3277 | { |
3182 | W w_ = (W)w; |
3278 | W w_ = (W)w; |
3183 | int pending = w_->pending; |
3279 | int pending = w_->pending; |
3184 | |
3280 | |
3185 | if (expect_true (pending)) |
3281 | if (expect_true (pending)) |
… | |
… | |
3218 | } |
3314 | } |
3219 | |
3315 | |
3220 | /*****************************************************************************/ |
3316 | /*****************************************************************************/ |
3221 | |
3317 | |
3222 | void noinline |
3318 | void noinline |
3223 | ev_io_start (EV_P_ ev_io *w) |
3319 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3224 | { |
3320 | { |
3225 | int fd = w->fd; |
3321 | int fd = w->fd; |
3226 | |
3322 | |
3227 | if (expect_false (ev_is_active (w))) |
3323 | if (expect_false (ev_is_active (w))) |
3228 | return; |
3324 | return; |
… | |
… | |
3234 | |
3330 | |
3235 | ev_start (EV_A_ (W)w, 1); |
3331 | ev_start (EV_A_ (W)w, 1); |
3236 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3332 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3237 | wlist_add (&anfds[fd].head, (WL)w); |
3333 | wlist_add (&anfds[fd].head, (WL)w); |
3238 | |
3334 | |
|
|
3335 | /* common bug, apparently */ |
|
|
3336 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3337 | |
3239 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3338 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3240 | w->events &= ~EV__IOFDSET; |
3339 | w->events &= ~EV__IOFDSET; |
3241 | |
3340 | |
3242 | EV_FREQUENT_CHECK; |
3341 | EV_FREQUENT_CHECK; |
3243 | } |
3342 | } |
3244 | |
3343 | |
3245 | void noinline |
3344 | void noinline |
3246 | ev_io_stop (EV_P_ ev_io *w) |
3345 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3247 | { |
3346 | { |
3248 | clear_pending (EV_A_ (W)w); |
3347 | clear_pending (EV_A_ (W)w); |
3249 | if (expect_false (!ev_is_active (w))) |
3348 | if (expect_false (!ev_is_active (w))) |
3250 | return; |
3349 | return; |
3251 | |
3350 | |
… | |
… | |
3260 | |
3359 | |
3261 | EV_FREQUENT_CHECK; |
3360 | EV_FREQUENT_CHECK; |
3262 | } |
3361 | } |
3263 | |
3362 | |
3264 | void noinline |
3363 | void noinline |
3265 | ev_timer_start (EV_P_ ev_timer *w) |
3364 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3266 | { |
3365 | { |
3267 | if (expect_false (ev_is_active (w))) |
3366 | if (expect_false (ev_is_active (w))) |
3268 | return; |
3367 | return; |
3269 | |
3368 | |
3270 | ev_at (w) += mn_now; |
3369 | ev_at (w) += mn_now; |
… | |
… | |
3284 | |
3383 | |
3285 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3384 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3286 | } |
3385 | } |
3287 | |
3386 | |
3288 | void noinline |
3387 | void noinline |
3289 | ev_timer_stop (EV_P_ ev_timer *w) |
3388 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3290 | { |
3389 | { |
3291 | clear_pending (EV_A_ (W)w); |
3390 | clear_pending (EV_A_ (W)w); |
3292 | if (expect_false (!ev_is_active (w))) |
3391 | if (expect_false (!ev_is_active (w))) |
3293 | return; |
3392 | return; |
3294 | |
3393 | |
… | |
… | |
3314 | |
3413 | |
3315 | EV_FREQUENT_CHECK; |
3414 | EV_FREQUENT_CHECK; |
3316 | } |
3415 | } |
3317 | |
3416 | |
3318 | void noinline |
3417 | void noinline |
3319 | ev_timer_again (EV_P_ ev_timer *w) |
3418 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3320 | { |
3419 | { |
3321 | EV_FREQUENT_CHECK; |
3420 | EV_FREQUENT_CHECK; |
3322 | |
3421 | |
3323 | clear_pending (EV_A_ (W)w); |
3422 | clear_pending (EV_A_ (W)w); |
3324 | |
3423 | |
… | |
… | |
3341 | |
3440 | |
3342 | EV_FREQUENT_CHECK; |
3441 | EV_FREQUENT_CHECK; |
3343 | } |
3442 | } |
3344 | |
3443 | |
3345 | ev_tstamp |
3444 | ev_tstamp |
3346 | ev_timer_remaining (EV_P_ ev_timer *w) |
3445 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3347 | { |
3446 | { |
3348 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3447 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3349 | } |
3448 | } |
3350 | |
3449 | |
3351 | #if EV_PERIODIC_ENABLE |
3450 | #if EV_PERIODIC_ENABLE |
3352 | void noinline |
3451 | void noinline |
3353 | ev_periodic_start (EV_P_ ev_periodic *w) |
3452 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3354 | { |
3453 | { |
3355 | if (expect_false (ev_is_active (w))) |
3454 | if (expect_false (ev_is_active (w))) |
3356 | return; |
3455 | return; |
3357 | |
3456 | |
3358 | if (w->reschedule_cb) |
3457 | if (w->reschedule_cb) |
… | |
… | |
3378 | |
3477 | |
3379 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3478 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3380 | } |
3479 | } |
3381 | |
3480 | |
3382 | void noinline |
3481 | void noinline |
3383 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3482 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3384 | { |
3483 | { |
3385 | clear_pending (EV_A_ (W)w); |
3484 | clear_pending (EV_A_ (W)w); |
3386 | if (expect_false (!ev_is_active (w))) |
3485 | if (expect_false (!ev_is_active (w))) |
3387 | return; |
3486 | return; |
3388 | |
3487 | |
… | |
… | |
3406 | |
3505 | |
3407 | EV_FREQUENT_CHECK; |
3506 | EV_FREQUENT_CHECK; |
3408 | } |
3507 | } |
3409 | |
3508 | |
3410 | void noinline |
3509 | void noinline |
3411 | ev_periodic_again (EV_P_ ev_periodic *w) |
3510 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3412 | { |
3511 | { |
3413 | /* TODO: use adjustheap and recalculation */ |
3512 | /* TODO: use adjustheap and recalculation */ |
3414 | ev_periodic_stop (EV_A_ w); |
3513 | ev_periodic_stop (EV_A_ w); |
3415 | ev_periodic_start (EV_A_ w); |
3514 | ev_periodic_start (EV_A_ w); |
3416 | } |
3515 | } |
… | |
… | |
3421 | #endif |
3520 | #endif |
3422 | |
3521 | |
3423 | #if EV_SIGNAL_ENABLE |
3522 | #if EV_SIGNAL_ENABLE |
3424 | |
3523 | |
3425 | void noinline |
3524 | void noinline |
3426 | ev_signal_start (EV_P_ ev_signal *w) |
3525 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3427 | { |
3526 | { |
3428 | if (expect_false (ev_is_active (w))) |
3527 | if (expect_false (ev_is_active (w))) |
3429 | return; |
3528 | return; |
3430 | |
3529 | |
3431 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3530 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3502 | |
3601 | |
3503 | EV_FREQUENT_CHECK; |
3602 | EV_FREQUENT_CHECK; |
3504 | } |
3603 | } |
3505 | |
3604 | |
3506 | void noinline |
3605 | void noinline |
3507 | ev_signal_stop (EV_P_ ev_signal *w) |
3606 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3508 | { |
3607 | { |
3509 | clear_pending (EV_A_ (W)w); |
3608 | clear_pending (EV_A_ (W)w); |
3510 | if (expect_false (!ev_is_active (w))) |
3609 | if (expect_false (!ev_is_active (w))) |
3511 | return; |
3610 | return; |
3512 | |
3611 | |
… | |
… | |
3543 | #endif |
3642 | #endif |
3544 | |
3643 | |
3545 | #if EV_CHILD_ENABLE |
3644 | #if EV_CHILD_ENABLE |
3546 | |
3645 | |
3547 | void |
3646 | void |
3548 | ev_child_start (EV_P_ ev_child *w) |
3647 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3549 | { |
3648 | { |
3550 | #if EV_MULTIPLICITY |
3649 | #if EV_MULTIPLICITY |
3551 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3650 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3552 | #endif |
3651 | #endif |
3553 | if (expect_false (ev_is_active (w))) |
3652 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3560 | |
3659 | |
3561 | EV_FREQUENT_CHECK; |
3660 | EV_FREQUENT_CHECK; |
3562 | } |
3661 | } |
3563 | |
3662 | |
3564 | void |
3663 | void |
3565 | ev_child_stop (EV_P_ ev_child *w) |
3664 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3566 | { |
3665 | { |
3567 | clear_pending (EV_A_ (W)w); |
3666 | clear_pending (EV_A_ (W)w); |
3568 | if (expect_false (!ev_is_active (w))) |
3667 | if (expect_false (!ev_is_active (w))) |
3569 | return; |
3668 | return; |
3570 | |
3669 | |
… | |
… | |
3737 | } |
3836 | } |
3738 | |
3837 | |
3739 | inline_size int |
3838 | inline_size int |
3740 | infy_newfd (void) |
3839 | infy_newfd (void) |
3741 | { |
3840 | { |
3742 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3841 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3743 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3842 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3744 | if (fd >= 0) |
3843 | if (fd >= 0) |
3745 | return fd; |
3844 | return fd; |
3746 | #endif |
3845 | #endif |
3747 | return inotify_init (); |
3846 | return inotify_init (); |
… | |
… | |
3822 | #else |
3921 | #else |
3823 | # define EV_LSTAT(p,b) lstat (p, b) |
3922 | # define EV_LSTAT(p,b) lstat (p, b) |
3824 | #endif |
3923 | #endif |
3825 | |
3924 | |
3826 | void |
3925 | void |
3827 | ev_stat_stat (EV_P_ ev_stat *w) |
3926 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3828 | { |
3927 | { |
3829 | if (lstat (w->path, &w->attr) < 0) |
3928 | if (lstat (w->path, &w->attr) < 0) |
3830 | w->attr.st_nlink = 0; |
3929 | w->attr.st_nlink = 0; |
3831 | else if (!w->attr.st_nlink) |
3930 | else if (!w->attr.st_nlink) |
3832 | w->attr.st_nlink = 1; |
3931 | w->attr.st_nlink = 1; |
… | |
… | |
3871 | ev_feed_event (EV_A_ w, EV_STAT); |
3970 | ev_feed_event (EV_A_ w, EV_STAT); |
3872 | } |
3971 | } |
3873 | } |
3972 | } |
3874 | |
3973 | |
3875 | void |
3974 | void |
3876 | ev_stat_start (EV_P_ ev_stat *w) |
3975 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3877 | { |
3976 | { |
3878 | if (expect_false (ev_is_active (w))) |
3977 | if (expect_false (ev_is_active (w))) |
3879 | return; |
3978 | return; |
3880 | |
3979 | |
3881 | ev_stat_stat (EV_A_ w); |
3980 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3902 | |
4001 | |
3903 | EV_FREQUENT_CHECK; |
4002 | EV_FREQUENT_CHECK; |
3904 | } |
4003 | } |
3905 | |
4004 | |
3906 | void |
4005 | void |
3907 | ev_stat_stop (EV_P_ ev_stat *w) |
4006 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3908 | { |
4007 | { |
3909 | clear_pending (EV_A_ (W)w); |
4008 | clear_pending (EV_A_ (W)w); |
3910 | if (expect_false (!ev_is_active (w))) |
4009 | if (expect_false (!ev_is_active (w))) |
3911 | return; |
4010 | return; |
3912 | |
4011 | |
… | |
… | |
3928 | } |
4027 | } |
3929 | #endif |
4028 | #endif |
3930 | |
4029 | |
3931 | #if EV_IDLE_ENABLE |
4030 | #if EV_IDLE_ENABLE |
3932 | void |
4031 | void |
3933 | ev_idle_start (EV_P_ ev_idle *w) |
4032 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3934 | { |
4033 | { |
3935 | if (expect_false (ev_is_active (w))) |
4034 | if (expect_false (ev_is_active (w))) |
3936 | return; |
4035 | return; |
3937 | |
4036 | |
3938 | pri_adjust (EV_A_ (W)w); |
4037 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3951 | |
4050 | |
3952 | EV_FREQUENT_CHECK; |
4051 | EV_FREQUENT_CHECK; |
3953 | } |
4052 | } |
3954 | |
4053 | |
3955 | void |
4054 | void |
3956 | ev_idle_stop (EV_P_ ev_idle *w) |
4055 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3957 | { |
4056 | { |
3958 | clear_pending (EV_A_ (W)w); |
4057 | clear_pending (EV_A_ (W)w); |
3959 | if (expect_false (!ev_is_active (w))) |
4058 | if (expect_false (!ev_is_active (w))) |
3960 | return; |
4059 | return; |
3961 | |
4060 | |
… | |
… | |
3975 | } |
4074 | } |
3976 | #endif |
4075 | #endif |
3977 | |
4076 | |
3978 | #if EV_PREPARE_ENABLE |
4077 | #if EV_PREPARE_ENABLE |
3979 | void |
4078 | void |
3980 | ev_prepare_start (EV_P_ ev_prepare *w) |
4079 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3981 | { |
4080 | { |
3982 | if (expect_false (ev_is_active (w))) |
4081 | if (expect_false (ev_is_active (w))) |
3983 | return; |
4082 | return; |
3984 | |
4083 | |
3985 | EV_FREQUENT_CHECK; |
4084 | EV_FREQUENT_CHECK; |
… | |
… | |
3990 | |
4089 | |
3991 | EV_FREQUENT_CHECK; |
4090 | EV_FREQUENT_CHECK; |
3992 | } |
4091 | } |
3993 | |
4092 | |
3994 | void |
4093 | void |
3995 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4094 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3996 | { |
4095 | { |
3997 | clear_pending (EV_A_ (W)w); |
4096 | clear_pending (EV_A_ (W)w); |
3998 | if (expect_false (!ev_is_active (w))) |
4097 | if (expect_false (!ev_is_active (w))) |
3999 | return; |
4098 | return; |
4000 | |
4099 | |
… | |
… | |
4013 | } |
4112 | } |
4014 | #endif |
4113 | #endif |
4015 | |
4114 | |
4016 | #if EV_CHECK_ENABLE |
4115 | #if EV_CHECK_ENABLE |
4017 | void |
4116 | void |
4018 | ev_check_start (EV_P_ ev_check *w) |
4117 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4019 | { |
4118 | { |
4020 | if (expect_false (ev_is_active (w))) |
4119 | if (expect_false (ev_is_active (w))) |
4021 | return; |
4120 | return; |
4022 | |
4121 | |
4023 | EV_FREQUENT_CHECK; |
4122 | EV_FREQUENT_CHECK; |
… | |
… | |
4028 | |
4127 | |
4029 | EV_FREQUENT_CHECK; |
4128 | EV_FREQUENT_CHECK; |
4030 | } |
4129 | } |
4031 | |
4130 | |
4032 | void |
4131 | void |
4033 | ev_check_stop (EV_P_ ev_check *w) |
4132 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4034 | { |
4133 | { |
4035 | clear_pending (EV_A_ (W)w); |
4134 | clear_pending (EV_A_ (W)w); |
4036 | if (expect_false (!ev_is_active (w))) |
4135 | if (expect_false (!ev_is_active (w))) |
4037 | return; |
4136 | return; |
4038 | |
4137 | |
… | |
… | |
4051 | } |
4150 | } |
4052 | #endif |
4151 | #endif |
4053 | |
4152 | |
4054 | #if EV_EMBED_ENABLE |
4153 | #if EV_EMBED_ENABLE |
4055 | void noinline |
4154 | void noinline |
4056 | ev_embed_sweep (EV_P_ ev_embed *w) |
4155 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4057 | { |
4156 | { |
4058 | ev_run (w->other, EVRUN_NOWAIT); |
4157 | ev_run (w->other, EVRUN_NOWAIT); |
4059 | } |
4158 | } |
4060 | |
4159 | |
4061 | static void |
4160 | static void |
… | |
… | |
4109 | ev_idle_stop (EV_A_ idle); |
4208 | ev_idle_stop (EV_A_ idle); |
4110 | } |
4209 | } |
4111 | #endif |
4210 | #endif |
4112 | |
4211 | |
4113 | void |
4212 | void |
4114 | ev_embed_start (EV_P_ ev_embed *w) |
4213 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4115 | { |
4214 | { |
4116 | if (expect_false (ev_is_active (w))) |
4215 | if (expect_false (ev_is_active (w))) |
4117 | return; |
4216 | return; |
4118 | |
4217 | |
4119 | { |
4218 | { |
… | |
… | |
4140 | |
4239 | |
4141 | EV_FREQUENT_CHECK; |
4240 | EV_FREQUENT_CHECK; |
4142 | } |
4241 | } |
4143 | |
4242 | |
4144 | void |
4243 | void |
4145 | ev_embed_stop (EV_P_ ev_embed *w) |
4244 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4146 | { |
4245 | { |
4147 | clear_pending (EV_A_ (W)w); |
4246 | clear_pending (EV_A_ (W)w); |
4148 | if (expect_false (!ev_is_active (w))) |
4247 | if (expect_false (!ev_is_active (w))) |
4149 | return; |
4248 | return; |
4150 | |
4249 | |
… | |
… | |
4160 | } |
4259 | } |
4161 | #endif |
4260 | #endif |
4162 | |
4261 | |
4163 | #if EV_FORK_ENABLE |
4262 | #if EV_FORK_ENABLE |
4164 | void |
4263 | void |
4165 | ev_fork_start (EV_P_ ev_fork *w) |
4264 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4166 | { |
4265 | { |
4167 | if (expect_false (ev_is_active (w))) |
4266 | if (expect_false (ev_is_active (w))) |
4168 | return; |
4267 | return; |
4169 | |
4268 | |
4170 | EV_FREQUENT_CHECK; |
4269 | EV_FREQUENT_CHECK; |
… | |
… | |
4175 | |
4274 | |
4176 | EV_FREQUENT_CHECK; |
4275 | EV_FREQUENT_CHECK; |
4177 | } |
4276 | } |
4178 | |
4277 | |
4179 | void |
4278 | void |
4180 | ev_fork_stop (EV_P_ ev_fork *w) |
4279 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4181 | { |
4280 | { |
4182 | clear_pending (EV_A_ (W)w); |
4281 | clear_pending (EV_A_ (W)w); |
4183 | if (expect_false (!ev_is_active (w))) |
4282 | if (expect_false (!ev_is_active (w))) |
4184 | return; |
4283 | return; |
4185 | |
4284 | |
… | |
… | |
4198 | } |
4297 | } |
4199 | #endif |
4298 | #endif |
4200 | |
4299 | |
4201 | #if EV_CLEANUP_ENABLE |
4300 | #if EV_CLEANUP_ENABLE |
4202 | void |
4301 | void |
4203 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4302 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4204 | { |
4303 | { |
4205 | if (expect_false (ev_is_active (w))) |
4304 | if (expect_false (ev_is_active (w))) |
4206 | return; |
4305 | return; |
4207 | |
4306 | |
4208 | EV_FREQUENT_CHECK; |
4307 | EV_FREQUENT_CHECK; |
… | |
… | |
4215 | ev_unref (EV_A); |
4314 | ev_unref (EV_A); |
4216 | EV_FREQUENT_CHECK; |
4315 | EV_FREQUENT_CHECK; |
4217 | } |
4316 | } |
4218 | |
4317 | |
4219 | void |
4318 | void |
4220 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4319 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4221 | { |
4320 | { |
4222 | clear_pending (EV_A_ (W)w); |
4321 | clear_pending (EV_A_ (W)w); |
4223 | if (expect_false (!ev_is_active (w))) |
4322 | if (expect_false (!ev_is_active (w))) |
4224 | return; |
4323 | return; |
4225 | |
4324 | |
… | |
… | |
4239 | } |
4338 | } |
4240 | #endif |
4339 | #endif |
4241 | |
4340 | |
4242 | #if EV_ASYNC_ENABLE |
4341 | #if EV_ASYNC_ENABLE |
4243 | void |
4342 | void |
4244 | ev_async_start (EV_P_ ev_async *w) |
4343 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4245 | { |
4344 | { |
4246 | if (expect_false (ev_is_active (w))) |
4345 | if (expect_false (ev_is_active (w))) |
4247 | return; |
4346 | return; |
4248 | |
4347 | |
4249 | w->sent = 0; |
4348 | w->sent = 0; |
… | |
… | |
4258 | |
4357 | |
4259 | EV_FREQUENT_CHECK; |
4358 | EV_FREQUENT_CHECK; |
4260 | } |
4359 | } |
4261 | |
4360 | |
4262 | void |
4361 | void |
4263 | ev_async_stop (EV_P_ ev_async *w) |
4362 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4264 | { |
4363 | { |
4265 | clear_pending (EV_A_ (W)w); |
4364 | clear_pending (EV_A_ (W)w); |
4266 | if (expect_false (!ev_is_active (w))) |
4365 | if (expect_false (!ev_is_active (w))) |
4267 | return; |
4366 | return; |
4268 | |
4367 | |
… | |
… | |
4279 | |
4378 | |
4280 | EV_FREQUENT_CHECK; |
4379 | EV_FREQUENT_CHECK; |
4281 | } |
4380 | } |
4282 | |
4381 | |
4283 | void |
4382 | void |
4284 | ev_async_send (EV_P_ ev_async *w) |
4383 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4285 | { |
4384 | { |
4286 | w->sent = 1; |
4385 | w->sent = 1; |
4287 | evpipe_write (EV_A_ &async_pending); |
4386 | evpipe_write (EV_A_ &async_pending); |
4288 | } |
4387 | } |
4289 | #endif |
4388 | #endif |
… | |
… | |
4326 | |
4425 | |
4327 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4426 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4328 | } |
4427 | } |
4329 | |
4428 | |
4330 | void |
4429 | void |
4331 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4430 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4332 | { |
4431 | { |
4333 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4432 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4334 | |
4433 | |
4335 | if (expect_false (!once)) |
4434 | if (expect_false (!once)) |
4336 | { |
4435 | { |
… | |
… | |
4358 | |
4457 | |
4359 | /*****************************************************************************/ |
4458 | /*****************************************************************************/ |
4360 | |
4459 | |
4361 | #if EV_WALK_ENABLE |
4460 | #if EV_WALK_ENABLE |
4362 | void ecb_cold |
4461 | void ecb_cold |
4363 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4462 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4364 | { |
4463 | { |
4365 | int i, j; |
4464 | int i, j; |
4366 | ev_watcher_list *wl, *wn; |
4465 | ev_watcher_list *wl, *wn; |
4367 | |
4466 | |
4368 | if (types & (EV_IO | EV_EMBED)) |
4467 | if (types & (EV_IO | EV_EMBED)) |