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; |
|
|
1939 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
|
|
1940 | #else |
1876 | write (evpipe [1], &(evpipe [1]), 1); |
1941 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1942 | #endif |
1877 | } |
1943 | } |
1878 | |
1944 | |
1879 | errno = old_errno; |
1945 | errno = old_errno; |
1880 | } |
1946 | } |
1881 | } |
1947 | } |
… | |
… | |
1896 | read (evfd, &counter, sizeof (uint64_t)); |
1962 | read (evfd, &counter, sizeof (uint64_t)); |
1897 | } |
1963 | } |
1898 | else |
1964 | else |
1899 | #endif |
1965 | #endif |
1900 | { |
1966 | { |
1901 | char dummy; |
1967 | char dummy[4]; |
1902 | /* 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 |
1903 | read (evpipe [0], &dummy, 1); |
1976 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1977 | #endif |
1904 | } |
1978 | } |
1905 | } |
1979 | } |
1906 | |
1980 | |
1907 | pipe_write_skipped = 0; |
1981 | pipe_write_skipped = 0; |
|
|
1982 | |
|
|
1983 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1908 | |
1984 | |
1909 | #if EV_SIGNAL_ENABLE |
1985 | #if EV_SIGNAL_ENABLE |
1910 | if (sig_pending) |
1986 | if (sig_pending) |
1911 | { |
1987 | { |
1912 | sig_pending = 0; |
1988 | sig_pending = 0; |
|
|
1989 | |
|
|
1990 | ECB_MEMORY_FENCE; |
1913 | |
1991 | |
1914 | for (i = EV_NSIG - 1; i--; ) |
1992 | for (i = EV_NSIG - 1; i--; ) |
1915 | if (expect_false (signals [i].pending)) |
1993 | if (expect_false (signals [i].pending)) |
1916 | ev_feed_signal_event (EV_A_ i + 1); |
1994 | ev_feed_signal_event (EV_A_ i + 1); |
1917 | } |
1995 | } |
… | |
… | |
1919 | |
1997 | |
1920 | #if EV_ASYNC_ENABLE |
1998 | #if EV_ASYNC_ENABLE |
1921 | if (async_pending) |
1999 | if (async_pending) |
1922 | { |
2000 | { |
1923 | async_pending = 0; |
2001 | async_pending = 0; |
|
|
2002 | |
|
|
2003 | ECB_MEMORY_FENCE; |
1924 | |
2004 | |
1925 | for (i = asynccnt; i--; ) |
2005 | for (i = asynccnt; i--; ) |
1926 | if (asyncs [i]->sent) |
2006 | if (asyncs [i]->sent) |
1927 | { |
2007 | { |
1928 | asyncs [i]->sent = 0; |
2008 | asyncs [i]->sent = 0; |
|
|
2009 | ECB_MEMORY_FENCE_RELEASE; |
1929 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
2010 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
1930 | } |
2011 | } |
1931 | } |
2012 | } |
1932 | #endif |
2013 | #endif |
1933 | } |
2014 | } |
1934 | |
2015 | |
1935 | /*****************************************************************************/ |
2016 | /*****************************************************************************/ |
1936 | |
2017 | |
1937 | void |
2018 | void |
1938 | ev_feed_signal (int signum) |
2019 | ev_feed_signal (int signum) EV_THROW |
1939 | { |
2020 | { |
1940 | #if EV_MULTIPLICITY |
2021 | #if EV_MULTIPLICITY |
1941 | EV_P = signals [signum - 1].loop; |
2022 | EV_P = signals [signum - 1].loop; |
1942 | |
2023 | |
1943 | if (!EV_A) |
2024 | if (!EV_A) |
… | |
… | |
1960 | |
2041 | |
1961 | ev_feed_signal (signum); |
2042 | ev_feed_signal (signum); |
1962 | } |
2043 | } |
1963 | |
2044 | |
1964 | void noinline |
2045 | void noinline |
1965 | ev_feed_signal_event (EV_P_ int signum) |
2046 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1966 | { |
2047 | { |
1967 | WL w; |
2048 | WL w; |
1968 | |
2049 | |
1969 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
2050 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1970 | return; |
2051 | return; |
… | |
… | |
1978 | if (expect_false (signals [signum].loop != EV_A)) |
2059 | if (expect_false (signals [signum].loop != EV_A)) |
1979 | return; |
2060 | return; |
1980 | #endif |
2061 | #endif |
1981 | |
2062 | |
1982 | signals [signum].pending = 0; |
2063 | signals [signum].pending = 0; |
|
|
2064 | ECB_MEMORY_FENCE_RELEASE; |
1983 | |
2065 | |
1984 | for (w = signals [signum].head; w; w = w->next) |
2066 | for (w = signals [signum].head; w; w = w->next) |
1985 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
2067 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1986 | } |
2068 | } |
1987 | |
2069 | |
… | |
… | |
2086 | #if EV_USE_SELECT |
2168 | #if EV_USE_SELECT |
2087 | # include "ev_select.c" |
2169 | # include "ev_select.c" |
2088 | #endif |
2170 | #endif |
2089 | |
2171 | |
2090 | int ecb_cold |
2172 | int ecb_cold |
2091 | ev_version_major (void) |
2173 | ev_version_major (void) EV_THROW |
2092 | { |
2174 | { |
2093 | return EV_VERSION_MAJOR; |
2175 | return EV_VERSION_MAJOR; |
2094 | } |
2176 | } |
2095 | |
2177 | |
2096 | int ecb_cold |
2178 | int ecb_cold |
2097 | ev_version_minor (void) |
2179 | ev_version_minor (void) EV_THROW |
2098 | { |
2180 | { |
2099 | return EV_VERSION_MINOR; |
2181 | return EV_VERSION_MINOR; |
2100 | } |
2182 | } |
2101 | |
2183 | |
2102 | /* 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 */ |
… | |
… | |
2110 | || getgid () != getegid (); |
2192 | || getgid () != getegid (); |
2111 | #endif |
2193 | #endif |
2112 | } |
2194 | } |
2113 | |
2195 | |
2114 | unsigned int ecb_cold |
2196 | unsigned int ecb_cold |
2115 | ev_supported_backends (void) |
2197 | ev_supported_backends (void) EV_THROW |
2116 | { |
2198 | { |
2117 | unsigned int flags = 0; |
2199 | unsigned int flags = 0; |
2118 | |
2200 | |
2119 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2201 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2120 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2202 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2124 | |
2206 | |
2125 | return flags; |
2207 | return flags; |
2126 | } |
2208 | } |
2127 | |
2209 | |
2128 | unsigned int ecb_cold |
2210 | unsigned int ecb_cold |
2129 | ev_recommended_backends (void) |
2211 | ev_recommended_backends (void) EV_THROW |
2130 | { |
2212 | { |
2131 | unsigned int flags = ev_supported_backends (); |
2213 | unsigned int flags = ev_supported_backends (); |
2132 | |
2214 | |
2133 | #ifndef __NetBSD__ |
2215 | #ifndef __NetBSD__ |
2134 | /* kqueue is borked on everything but netbsd apparently */ |
2216 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2146 | |
2228 | |
2147 | return flags; |
2229 | return flags; |
2148 | } |
2230 | } |
2149 | |
2231 | |
2150 | unsigned int ecb_cold |
2232 | unsigned int ecb_cold |
2151 | ev_embeddable_backends (void) |
2233 | ev_embeddable_backends (void) EV_THROW |
2152 | { |
2234 | { |
2153 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2235 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2154 | |
2236 | |
2155 | /* 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 */ |
2156 | 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 */ |
… | |
… | |
2158 | |
2240 | |
2159 | return flags; |
2241 | return flags; |
2160 | } |
2242 | } |
2161 | |
2243 | |
2162 | unsigned int |
2244 | unsigned int |
2163 | ev_backend (EV_P) |
2245 | ev_backend (EV_P) EV_THROW |
2164 | { |
2246 | { |
2165 | return backend; |
2247 | return backend; |
2166 | } |
2248 | } |
2167 | |
2249 | |
2168 | #if EV_FEATURE_API |
2250 | #if EV_FEATURE_API |
2169 | unsigned int |
2251 | unsigned int |
2170 | ev_iteration (EV_P) |
2252 | ev_iteration (EV_P) EV_THROW |
2171 | { |
2253 | { |
2172 | return loop_count; |
2254 | return loop_count; |
2173 | } |
2255 | } |
2174 | |
2256 | |
2175 | unsigned int |
2257 | unsigned int |
2176 | ev_depth (EV_P) |
2258 | ev_depth (EV_P) EV_THROW |
2177 | { |
2259 | { |
2178 | return loop_depth; |
2260 | return loop_depth; |
2179 | } |
2261 | } |
2180 | |
2262 | |
2181 | void |
2263 | void |
2182 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2264 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2183 | { |
2265 | { |
2184 | io_blocktime = interval; |
2266 | io_blocktime = interval; |
2185 | } |
2267 | } |
2186 | |
2268 | |
2187 | void |
2269 | void |
2188 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2270 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2189 | { |
2271 | { |
2190 | timeout_blocktime = interval; |
2272 | timeout_blocktime = interval; |
2191 | } |
2273 | } |
2192 | |
2274 | |
2193 | void |
2275 | void |
2194 | ev_set_userdata (EV_P_ void *data) |
2276 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2195 | { |
2277 | { |
2196 | userdata = data; |
2278 | userdata = data; |
2197 | } |
2279 | } |
2198 | |
2280 | |
2199 | void * |
2281 | void * |
2200 | ev_userdata (EV_P) |
2282 | ev_userdata (EV_P) EV_THROW |
2201 | { |
2283 | { |
2202 | return userdata; |
2284 | return userdata; |
2203 | } |
2285 | } |
2204 | |
2286 | |
2205 | void |
2287 | void |
2206 | 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 |
2207 | { |
2289 | { |
2208 | invoke_cb = invoke_pending_cb; |
2290 | invoke_cb = invoke_pending_cb; |
2209 | } |
2291 | } |
2210 | |
2292 | |
2211 | void |
2293 | void |
2212 | 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 |
2213 | { |
2295 | { |
2214 | release_cb = release; |
2296 | release_cb = release; |
2215 | acquire_cb = acquire; |
2297 | acquire_cb = acquire; |
2216 | } |
2298 | } |
2217 | #endif |
2299 | #endif |
2218 | |
2300 | |
2219 | /* initialise a loop structure, must be zero-initialised */ |
2301 | /* initialise a loop structure, must be zero-initialised */ |
2220 | static void noinline ecb_cold |
2302 | static void noinline ecb_cold |
2221 | loop_init (EV_P_ unsigned int flags) |
2303 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2222 | { |
2304 | { |
2223 | if (!backend) |
2305 | if (!backend) |
2224 | { |
2306 | { |
2225 | origflags = flags; |
2307 | origflags = flags; |
2226 | |
2308 | |
… | |
… | |
2331 | EV_INVOKE_PENDING; |
2413 | EV_INVOKE_PENDING; |
2332 | } |
2414 | } |
2333 | #endif |
2415 | #endif |
2334 | |
2416 | |
2335 | #if EV_CHILD_ENABLE |
2417 | #if EV_CHILD_ENABLE |
2336 | if (ev_is_active (&childev)) |
2418 | if (ev_is_default_loop (EV_A) && ev_is_active (&childev)) |
2337 | { |
2419 | { |
2338 | ev_ref (EV_A); /* child watcher */ |
2420 | ev_ref (EV_A); /* child watcher */ |
2339 | ev_signal_stop (EV_A_ &childev); |
2421 | ev_signal_stop (EV_A_ &childev); |
2340 | } |
2422 | } |
2341 | #endif |
2423 | #endif |
… | |
… | |
2479 | } |
2561 | } |
2480 | |
2562 | |
2481 | #if EV_MULTIPLICITY |
2563 | #if EV_MULTIPLICITY |
2482 | |
2564 | |
2483 | struct ev_loop * ecb_cold |
2565 | struct ev_loop * ecb_cold |
2484 | ev_loop_new (unsigned int flags) |
2566 | ev_loop_new (unsigned int flags) EV_THROW |
2485 | { |
2567 | { |
2486 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2568 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2487 | |
2569 | |
2488 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2570 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2489 | loop_init (EV_A_ flags); |
2571 | loop_init (EV_A_ flags); |
… | |
… | |
2533 | } |
2615 | } |
2534 | #endif |
2616 | #endif |
2535 | |
2617 | |
2536 | #if EV_FEATURE_API |
2618 | #if EV_FEATURE_API |
2537 | void ecb_cold |
2619 | void ecb_cold |
2538 | ev_verify (EV_P) |
2620 | ev_verify (EV_P) EV_THROW |
2539 | { |
2621 | { |
2540 | #if EV_VERIFY |
2622 | #if EV_VERIFY |
2541 | int i; |
2623 | int i; |
2542 | WL w; |
2624 | WL w, w2; |
2543 | |
2625 | |
2544 | assert (activecnt >= -1); |
2626 | assert (activecnt >= -1); |
2545 | |
2627 | |
2546 | assert (fdchangemax >= fdchangecnt); |
2628 | assert (fdchangemax >= fdchangecnt); |
2547 | for (i = 0; i < fdchangecnt; ++i) |
2629 | for (i = 0; i < fdchangecnt; ++i) |
2548 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2630 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2549 | |
2631 | |
2550 | assert (anfdmax >= 0); |
2632 | assert (anfdmax >= 0); |
2551 | for (i = 0; i < anfdmax; ++i) |
2633 | for (i = 0; i < anfdmax; ++i) |
|
|
2634 | { |
|
|
2635 | int j = 0; |
|
|
2636 | |
2552 | for (w = anfds [i].head; w; w = w->next) |
2637 | for (w = w2 = anfds [i].head; w; w = w->next) |
2553 | { |
2638 | { |
2554 | 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 | |
2555 | 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)); |
2556 | 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)); |
2557 | } |
2649 | } |
|
|
2650 | } |
2558 | |
2651 | |
2559 | assert (timermax >= timercnt); |
2652 | assert (timermax >= timercnt); |
2560 | verify_heap (EV_A_ timers, timercnt); |
2653 | verify_heap (EV_A_ timers, timercnt); |
2561 | |
2654 | |
2562 | #if EV_PERIODIC_ENABLE |
2655 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2612 | #if EV_MULTIPLICITY |
2705 | #if EV_MULTIPLICITY |
2613 | struct ev_loop * ecb_cold |
2706 | struct ev_loop * ecb_cold |
2614 | #else |
2707 | #else |
2615 | int |
2708 | int |
2616 | #endif |
2709 | #endif |
2617 | ev_default_loop (unsigned int flags) |
2710 | ev_default_loop (unsigned int flags) EV_THROW |
2618 | { |
2711 | { |
2619 | if (!ev_default_loop_ptr) |
2712 | if (!ev_default_loop_ptr) |
2620 | { |
2713 | { |
2621 | #if EV_MULTIPLICITY |
2714 | #if EV_MULTIPLICITY |
2622 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2715 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2641 | |
2734 | |
2642 | return ev_default_loop_ptr; |
2735 | return ev_default_loop_ptr; |
2643 | } |
2736 | } |
2644 | |
2737 | |
2645 | void |
2738 | void |
2646 | ev_loop_fork (EV_P) |
2739 | ev_loop_fork (EV_P) EV_THROW |
2647 | { |
2740 | { |
2648 | postfork = 1; /* must be in line with ev_default_fork */ |
2741 | postfork = 1; |
2649 | } |
2742 | } |
2650 | |
2743 | |
2651 | /*****************************************************************************/ |
2744 | /*****************************************************************************/ |
2652 | |
2745 | |
2653 | void |
2746 | void |
… | |
… | |
2655 | { |
2748 | { |
2656 | EV_CB_INVOKE ((W)w, revents); |
2749 | EV_CB_INVOKE ((W)w, revents); |
2657 | } |
2750 | } |
2658 | |
2751 | |
2659 | unsigned int |
2752 | unsigned int |
2660 | ev_pending_count (EV_P) |
2753 | ev_pending_count (EV_P) EV_THROW |
2661 | { |
2754 | { |
2662 | int pri; |
2755 | int pri; |
2663 | unsigned int count = 0; |
2756 | unsigned int count = 0; |
2664 | |
2757 | |
2665 | for (pri = NUMPRI; pri--; ) |
2758 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2669 | } |
2762 | } |
2670 | |
2763 | |
2671 | void noinline |
2764 | void noinline |
2672 | ev_invoke_pending (EV_P) |
2765 | ev_invoke_pending (EV_P) |
2673 | { |
2766 | { |
2674 | int pri; |
2767 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2675 | |
|
|
2676 | for (pri = NUMPRI; pri--; ) |
|
|
2677 | while (pendingcnt [pri]) |
2768 | while (pendingcnt [pendingpri]) |
2678 | { |
2769 | { |
2679 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2770 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2680 | |
2771 | |
2681 | p->w->pending = 0; |
2772 | p->w->pending = 0; |
2682 | EV_CB_INVOKE (p->w, p->events); |
2773 | EV_CB_INVOKE (p->w, p->events); |
2683 | EV_FREQUENT_CHECK; |
2774 | EV_FREQUENT_CHECK; |
2684 | } |
2775 | } |
… | |
… | |
2779 | { |
2870 | { |
2780 | EV_FREQUENT_CHECK; |
2871 | EV_FREQUENT_CHECK; |
2781 | |
2872 | |
2782 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2873 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2783 | { |
2874 | { |
2784 | int feed_count = 0; |
|
|
2785 | |
|
|
2786 | do |
2875 | do |
2787 | { |
2876 | { |
2788 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2877 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2789 | |
2878 | |
2790 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
2879 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
2924 | |
3013 | |
2925 | mn_now = ev_rt_now; |
3014 | mn_now = ev_rt_now; |
2926 | } |
3015 | } |
2927 | } |
3016 | } |
2928 | |
3017 | |
2929 | void |
3018 | int |
2930 | ev_run (EV_P_ int flags) |
3019 | ev_run (EV_P_ int flags) |
2931 | { |
3020 | { |
2932 | #if EV_FEATURE_API |
3021 | #if EV_FEATURE_API |
2933 | ++loop_depth; |
3022 | ++loop_depth; |
2934 | #endif |
3023 | #endif |
… | |
… | |
3049 | backend_poll (EV_A_ waittime); |
3138 | backend_poll (EV_A_ waittime); |
3050 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3139 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3051 | |
3140 | |
3052 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3141 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
3053 | |
3142 | |
|
|
3143 | ECB_MEMORY_FENCE_ACQUIRE; |
3054 | if (pipe_write_skipped) |
3144 | if (pipe_write_skipped) |
3055 | { |
3145 | { |
3056 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3146 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3057 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3147 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3058 | } |
3148 | } |
… | |
… | |
3091 | loop_done = EVBREAK_CANCEL; |
3181 | loop_done = EVBREAK_CANCEL; |
3092 | |
3182 | |
3093 | #if EV_FEATURE_API |
3183 | #if EV_FEATURE_API |
3094 | --loop_depth; |
3184 | --loop_depth; |
3095 | #endif |
3185 | #endif |
|
|
3186 | |
|
|
3187 | return activecnt; |
3096 | } |
3188 | } |
3097 | |
3189 | |
3098 | void |
3190 | void |
3099 | ev_break (EV_P_ int how) |
3191 | ev_break (EV_P_ int how) EV_THROW |
3100 | { |
3192 | { |
3101 | loop_done = how; |
3193 | loop_done = how; |
3102 | } |
3194 | } |
3103 | |
3195 | |
3104 | void |
3196 | void |
3105 | ev_ref (EV_P) |
3197 | ev_ref (EV_P) EV_THROW |
3106 | { |
3198 | { |
3107 | ++activecnt; |
3199 | ++activecnt; |
3108 | } |
3200 | } |
3109 | |
3201 | |
3110 | void |
3202 | void |
3111 | ev_unref (EV_P) |
3203 | ev_unref (EV_P) EV_THROW |
3112 | { |
3204 | { |
3113 | --activecnt; |
3205 | --activecnt; |
3114 | } |
3206 | } |
3115 | |
3207 | |
3116 | void |
3208 | void |
3117 | ev_now_update (EV_P) |
3209 | ev_now_update (EV_P) EV_THROW |
3118 | { |
3210 | { |
3119 | time_update (EV_A_ 1e100); |
3211 | time_update (EV_A_ 1e100); |
3120 | } |
3212 | } |
3121 | |
3213 | |
3122 | void |
3214 | void |
3123 | ev_suspend (EV_P) |
3215 | ev_suspend (EV_P) EV_THROW |
3124 | { |
3216 | { |
3125 | ev_now_update (EV_A); |
3217 | ev_now_update (EV_A); |
3126 | } |
3218 | } |
3127 | |
3219 | |
3128 | void |
3220 | void |
3129 | ev_resume (EV_P) |
3221 | ev_resume (EV_P) EV_THROW |
3130 | { |
3222 | { |
3131 | ev_tstamp mn_prev = mn_now; |
3223 | ev_tstamp mn_prev = mn_now; |
3132 | |
3224 | |
3133 | ev_now_update (EV_A); |
3225 | ev_now_update (EV_A); |
3134 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3226 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3173 | w->pending = 0; |
3265 | w->pending = 0; |
3174 | } |
3266 | } |
3175 | } |
3267 | } |
3176 | |
3268 | |
3177 | int |
3269 | int |
3178 | ev_clear_pending (EV_P_ void *w) |
3270 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3179 | { |
3271 | { |
3180 | W w_ = (W)w; |
3272 | W w_ = (W)w; |
3181 | int pending = w_->pending; |
3273 | int pending = w_->pending; |
3182 | |
3274 | |
3183 | if (expect_true (pending)) |
3275 | if (expect_true (pending)) |
… | |
… | |
3216 | } |
3308 | } |
3217 | |
3309 | |
3218 | /*****************************************************************************/ |
3310 | /*****************************************************************************/ |
3219 | |
3311 | |
3220 | void noinline |
3312 | void noinline |
3221 | ev_io_start (EV_P_ ev_io *w) |
3313 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3222 | { |
3314 | { |
3223 | int fd = w->fd; |
3315 | int fd = w->fd; |
3224 | |
3316 | |
3225 | if (expect_false (ev_is_active (w))) |
3317 | if (expect_false (ev_is_active (w))) |
3226 | return; |
3318 | return; |
… | |
… | |
3232 | |
3324 | |
3233 | ev_start (EV_A_ (W)w, 1); |
3325 | ev_start (EV_A_ (W)w, 1); |
3234 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3326 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3235 | wlist_add (&anfds[fd].head, (WL)w); |
3327 | wlist_add (&anfds[fd].head, (WL)w); |
3236 | |
3328 | |
|
|
3329 | /* common bug, apparently */ |
|
|
3330 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3331 | |
3237 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3332 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3238 | w->events &= ~EV__IOFDSET; |
3333 | w->events &= ~EV__IOFDSET; |
3239 | |
3334 | |
3240 | EV_FREQUENT_CHECK; |
3335 | EV_FREQUENT_CHECK; |
3241 | } |
3336 | } |
3242 | |
3337 | |
3243 | void noinline |
3338 | void noinline |
3244 | ev_io_stop (EV_P_ ev_io *w) |
3339 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3245 | { |
3340 | { |
3246 | clear_pending (EV_A_ (W)w); |
3341 | clear_pending (EV_A_ (W)w); |
3247 | if (expect_false (!ev_is_active (w))) |
3342 | if (expect_false (!ev_is_active (w))) |
3248 | return; |
3343 | return; |
3249 | |
3344 | |
… | |
… | |
3258 | |
3353 | |
3259 | EV_FREQUENT_CHECK; |
3354 | EV_FREQUENT_CHECK; |
3260 | } |
3355 | } |
3261 | |
3356 | |
3262 | void noinline |
3357 | void noinline |
3263 | ev_timer_start (EV_P_ ev_timer *w) |
3358 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3264 | { |
3359 | { |
3265 | if (expect_false (ev_is_active (w))) |
3360 | if (expect_false (ev_is_active (w))) |
3266 | return; |
3361 | return; |
3267 | |
3362 | |
3268 | ev_at (w) += mn_now; |
3363 | ev_at (w) += mn_now; |
… | |
… | |
3282 | |
3377 | |
3283 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3378 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3284 | } |
3379 | } |
3285 | |
3380 | |
3286 | void noinline |
3381 | void noinline |
3287 | ev_timer_stop (EV_P_ ev_timer *w) |
3382 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3288 | { |
3383 | { |
3289 | clear_pending (EV_A_ (W)w); |
3384 | clear_pending (EV_A_ (W)w); |
3290 | if (expect_false (!ev_is_active (w))) |
3385 | if (expect_false (!ev_is_active (w))) |
3291 | return; |
3386 | return; |
3292 | |
3387 | |
… | |
… | |
3312 | |
3407 | |
3313 | EV_FREQUENT_CHECK; |
3408 | EV_FREQUENT_CHECK; |
3314 | } |
3409 | } |
3315 | |
3410 | |
3316 | void noinline |
3411 | void noinline |
3317 | ev_timer_again (EV_P_ ev_timer *w) |
3412 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3318 | { |
3413 | { |
3319 | EV_FREQUENT_CHECK; |
3414 | EV_FREQUENT_CHECK; |
3320 | |
3415 | |
3321 | clear_pending (EV_A_ (W)w); |
3416 | clear_pending (EV_A_ (W)w); |
3322 | |
3417 | |
… | |
… | |
3339 | |
3434 | |
3340 | EV_FREQUENT_CHECK; |
3435 | EV_FREQUENT_CHECK; |
3341 | } |
3436 | } |
3342 | |
3437 | |
3343 | ev_tstamp |
3438 | ev_tstamp |
3344 | ev_timer_remaining (EV_P_ ev_timer *w) |
3439 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3345 | { |
3440 | { |
3346 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3441 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3347 | } |
3442 | } |
3348 | |
3443 | |
3349 | #if EV_PERIODIC_ENABLE |
3444 | #if EV_PERIODIC_ENABLE |
3350 | void noinline |
3445 | void noinline |
3351 | ev_periodic_start (EV_P_ ev_periodic *w) |
3446 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3352 | { |
3447 | { |
3353 | if (expect_false (ev_is_active (w))) |
3448 | if (expect_false (ev_is_active (w))) |
3354 | return; |
3449 | return; |
3355 | |
3450 | |
3356 | if (w->reschedule_cb) |
3451 | if (w->reschedule_cb) |
… | |
… | |
3376 | |
3471 | |
3377 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3472 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3378 | } |
3473 | } |
3379 | |
3474 | |
3380 | void noinline |
3475 | void noinline |
3381 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3476 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3382 | { |
3477 | { |
3383 | clear_pending (EV_A_ (W)w); |
3478 | clear_pending (EV_A_ (W)w); |
3384 | if (expect_false (!ev_is_active (w))) |
3479 | if (expect_false (!ev_is_active (w))) |
3385 | return; |
3480 | return; |
3386 | |
3481 | |
… | |
… | |
3404 | |
3499 | |
3405 | EV_FREQUENT_CHECK; |
3500 | EV_FREQUENT_CHECK; |
3406 | } |
3501 | } |
3407 | |
3502 | |
3408 | void noinline |
3503 | void noinline |
3409 | ev_periodic_again (EV_P_ ev_periodic *w) |
3504 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3410 | { |
3505 | { |
3411 | /* TODO: use adjustheap and recalculation */ |
3506 | /* TODO: use adjustheap and recalculation */ |
3412 | ev_periodic_stop (EV_A_ w); |
3507 | ev_periodic_stop (EV_A_ w); |
3413 | ev_periodic_start (EV_A_ w); |
3508 | ev_periodic_start (EV_A_ w); |
3414 | } |
3509 | } |
… | |
… | |
3419 | #endif |
3514 | #endif |
3420 | |
3515 | |
3421 | #if EV_SIGNAL_ENABLE |
3516 | #if EV_SIGNAL_ENABLE |
3422 | |
3517 | |
3423 | void noinline |
3518 | void noinline |
3424 | ev_signal_start (EV_P_ ev_signal *w) |
3519 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3425 | { |
3520 | { |
3426 | if (expect_false (ev_is_active (w))) |
3521 | if (expect_false (ev_is_active (w))) |
3427 | return; |
3522 | return; |
3428 | |
3523 | |
3429 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3524 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3500 | |
3595 | |
3501 | EV_FREQUENT_CHECK; |
3596 | EV_FREQUENT_CHECK; |
3502 | } |
3597 | } |
3503 | |
3598 | |
3504 | void noinline |
3599 | void noinline |
3505 | ev_signal_stop (EV_P_ ev_signal *w) |
3600 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3506 | { |
3601 | { |
3507 | clear_pending (EV_A_ (W)w); |
3602 | clear_pending (EV_A_ (W)w); |
3508 | if (expect_false (!ev_is_active (w))) |
3603 | if (expect_false (!ev_is_active (w))) |
3509 | return; |
3604 | return; |
3510 | |
3605 | |
… | |
… | |
3541 | #endif |
3636 | #endif |
3542 | |
3637 | |
3543 | #if EV_CHILD_ENABLE |
3638 | #if EV_CHILD_ENABLE |
3544 | |
3639 | |
3545 | void |
3640 | void |
3546 | ev_child_start (EV_P_ ev_child *w) |
3641 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3547 | { |
3642 | { |
3548 | #if EV_MULTIPLICITY |
3643 | #if EV_MULTIPLICITY |
3549 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3644 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3550 | #endif |
3645 | #endif |
3551 | if (expect_false (ev_is_active (w))) |
3646 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3558 | |
3653 | |
3559 | EV_FREQUENT_CHECK; |
3654 | EV_FREQUENT_CHECK; |
3560 | } |
3655 | } |
3561 | |
3656 | |
3562 | void |
3657 | void |
3563 | ev_child_stop (EV_P_ ev_child *w) |
3658 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3564 | { |
3659 | { |
3565 | clear_pending (EV_A_ (W)w); |
3660 | clear_pending (EV_A_ (W)w); |
3566 | if (expect_false (!ev_is_active (w))) |
3661 | if (expect_false (!ev_is_active (w))) |
3567 | return; |
3662 | return; |
3568 | |
3663 | |
… | |
… | |
3735 | } |
3830 | } |
3736 | |
3831 | |
3737 | inline_size int |
3832 | inline_size int |
3738 | infy_newfd (void) |
3833 | infy_newfd (void) |
3739 | { |
3834 | { |
3740 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3835 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3741 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3836 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3742 | if (fd >= 0) |
3837 | if (fd >= 0) |
3743 | return fd; |
3838 | return fd; |
3744 | #endif |
3839 | #endif |
3745 | return inotify_init (); |
3840 | return inotify_init (); |
… | |
… | |
3820 | #else |
3915 | #else |
3821 | # define EV_LSTAT(p,b) lstat (p, b) |
3916 | # define EV_LSTAT(p,b) lstat (p, b) |
3822 | #endif |
3917 | #endif |
3823 | |
3918 | |
3824 | void |
3919 | void |
3825 | ev_stat_stat (EV_P_ ev_stat *w) |
3920 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3826 | { |
3921 | { |
3827 | if (lstat (w->path, &w->attr) < 0) |
3922 | if (lstat (w->path, &w->attr) < 0) |
3828 | w->attr.st_nlink = 0; |
3923 | w->attr.st_nlink = 0; |
3829 | else if (!w->attr.st_nlink) |
3924 | else if (!w->attr.st_nlink) |
3830 | w->attr.st_nlink = 1; |
3925 | w->attr.st_nlink = 1; |
… | |
… | |
3869 | ev_feed_event (EV_A_ w, EV_STAT); |
3964 | ev_feed_event (EV_A_ w, EV_STAT); |
3870 | } |
3965 | } |
3871 | } |
3966 | } |
3872 | |
3967 | |
3873 | void |
3968 | void |
3874 | ev_stat_start (EV_P_ ev_stat *w) |
3969 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3875 | { |
3970 | { |
3876 | if (expect_false (ev_is_active (w))) |
3971 | if (expect_false (ev_is_active (w))) |
3877 | return; |
3972 | return; |
3878 | |
3973 | |
3879 | ev_stat_stat (EV_A_ w); |
3974 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3900 | |
3995 | |
3901 | EV_FREQUENT_CHECK; |
3996 | EV_FREQUENT_CHECK; |
3902 | } |
3997 | } |
3903 | |
3998 | |
3904 | void |
3999 | void |
3905 | ev_stat_stop (EV_P_ ev_stat *w) |
4000 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3906 | { |
4001 | { |
3907 | clear_pending (EV_A_ (W)w); |
4002 | clear_pending (EV_A_ (W)w); |
3908 | if (expect_false (!ev_is_active (w))) |
4003 | if (expect_false (!ev_is_active (w))) |
3909 | return; |
4004 | return; |
3910 | |
4005 | |
… | |
… | |
3926 | } |
4021 | } |
3927 | #endif |
4022 | #endif |
3928 | |
4023 | |
3929 | #if EV_IDLE_ENABLE |
4024 | #if EV_IDLE_ENABLE |
3930 | void |
4025 | void |
3931 | ev_idle_start (EV_P_ ev_idle *w) |
4026 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3932 | { |
4027 | { |
3933 | if (expect_false (ev_is_active (w))) |
4028 | if (expect_false (ev_is_active (w))) |
3934 | return; |
4029 | return; |
3935 | |
4030 | |
3936 | pri_adjust (EV_A_ (W)w); |
4031 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3949 | |
4044 | |
3950 | EV_FREQUENT_CHECK; |
4045 | EV_FREQUENT_CHECK; |
3951 | } |
4046 | } |
3952 | |
4047 | |
3953 | void |
4048 | void |
3954 | ev_idle_stop (EV_P_ ev_idle *w) |
4049 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3955 | { |
4050 | { |
3956 | clear_pending (EV_A_ (W)w); |
4051 | clear_pending (EV_A_ (W)w); |
3957 | if (expect_false (!ev_is_active (w))) |
4052 | if (expect_false (!ev_is_active (w))) |
3958 | return; |
4053 | return; |
3959 | |
4054 | |
… | |
… | |
3973 | } |
4068 | } |
3974 | #endif |
4069 | #endif |
3975 | |
4070 | |
3976 | #if EV_PREPARE_ENABLE |
4071 | #if EV_PREPARE_ENABLE |
3977 | void |
4072 | void |
3978 | ev_prepare_start (EV_P_ ev_prepare *w) |
4073 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3979 | { |
4074 | { |
3980 | if (expect_false (ev_is_active (w))) |
4075 | if (expect_false (ev_is_active (w))) |
3981 | return; |
4076 | return; |
3982 | |
4077 | |
3983 | EV_FREQUENT_CHECK; |
4078 | EV_FREQUENT_CHECK; |
… | |
… | |
3988 | |
4083 | |
3989 | EV_FREQUENT_CHECK; |
4084 | EV_FREQUENT_CHECK; |
3990 | } |
4085 | } |
3991 | |
4086 | |
3992 | void |
4087 | void |
3993 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4088 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3994 | { |
4089 | { |
3995 | clear_pending (EV_A_ (W)w); |
4090 | clear_pending (EV_A_ (W)w); |
3996 | if (expect_false (!ev_is_active (w))) |
4091 | if (expect_false (!ev_is_active (w))) |
3997 | return; |
4092 | return; |
3998 | |
4093 | |
… | |
… | |
4011 | } |
4106 | } |
4012 | #endif |
4107 | #endif |
4013 | |
4108 | |
4014 | #if EV_CHECK_ENABLE |
4109 | #if EV_CHECK_ENABLE |
4015 | void |
4110 | void |
4016 | ev_check_start (EV_P_ ev_check *w) |
4111 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4017 | { |
4112 | { |
4018 | if (expect_false (ev_is_active (w))) |
4113 | if (expect_false (ev_is_active (w))) |
4019 | return; |
4114 | return; |
4020 | |
4115 | |
4021 | EV_FREQUENT_CHECK; |
4116 | EV_FREQUENT_CHECK; |
… | |
… | |
4026 | |
4121 | |
4027 | EV_FREQUENT_CHECK; |
4122 | EV_FREQUENT_CHECK; |
4028 | } |
4123 | } |
4029 | |
4124 | |
4030 | void |
4125 | void |
4031 | ev_check_stop (EV_P_ ev_check *w) |
4126 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4032 | { |
4127 | { |
4033 | clear_pending (EV_A_ (W)w); |
4128 | clear_pending (EV_A_ (W)w); |
4034 | if (expect_false (!ev_is_active (w))) |
4129 | if (expect_false (!ev_is_active (w))) |
4035 | return; |
4130 | return; |
4036 | |
4131 | |
… | |
… | |
4049 | } |
4144 | } |
4050 | #endif |
4145 | #endif |
4051 | |
4146 | |
4052 | #if EV_EMBED_ENABLE |
4147 | #if EV_EMBED_ENABLE |
4053 | void noinline |
4148 | void noinline |
4054 | ev_embed_sweep (EV_P_ ev_embed *w) |
4149 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4055 | { |
4150 | { |
4056 | ev_run (w->other, EVRUN_NOWAIT); |
4151 | ev_run (w->other, EVRUN_NOWAIT); |
4057 | } |
4152 | } |
4058 | |
4153 | |
4059 | static void |
4154 | static void |
… | |
… | |
4107 | ev_idle_stop (EV_A_ idle); |
4202 | ev_idle_stop (EV_A_ idle); |
4108 | } |
4203 | } |
4109 | #endif |
4204 | #endif |
4110 | |
4205 | |
4111 | void |
4206 | void |
4112 | ev_embed_start (EV_P_ ev_embed *w) |
4207 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4113 | { |
4208 | { |
4114 | if (expect_false (ev_is_active (w))) |
4209 | if (expect_false (ev_is_active (w))) |
4115 | return; |
4210 | return; |
4116 | |
4211 | |
4117 | { |
4212 | { |
… | |
… | |
4138 | |
4233 | |
4139 | EV_FREQUENT_CHECK; |
4234 | EV_FREQUENT_CHECK; |
4140 | } |
4235 | } |
4141 | |
4236 | |
4142 | void |
4237 | void |
4143 | ev_embed_stop (EV_P_ ev_embed *w) |
4238 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4144 | { |
4239 | { |
4145 | clear_pending (EV_A_ (W)w); |
4240 | clear_pending (EV_A_ (W)w); |
4146 | if (expect_false (!ev_is_active (w))) |
4241 | if (expect_false (!ev_is_active (w))) |
4147 | return; |
4242 | return; |
4148 | |
4243 | |
… | |
… | |
4158 | } |
4253 | } |
4159 | #endif |
4254 | #endif |
4160 | |
4255 | |
4161 | #if EV_FORK_ENABLE |
4256 | #if EV_FORK_ENABLE |
4162 | void |
4257 | void |
4163 | ev_fork_start (EV_P_ ev_fork *w) |
4258 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4164 | { |
4259 | { |
4165 | if (expect_false (ev_is_active (w))) |
4260 | if (expect_false (ev_is_active (w))) |
4166 | return; |
4261 | return; |
4167 | |
4262 | |
4168 | EV_FREQUENT_CHECK; |
4263 | EV_FREQUENT_CHECK; |
… | |
… | |
4173 | |
4268 | |
4174 | EV_FREQUENT_CHECK; |
4269 | EV_FREQUENT_CHECK; |
4175 | } |
4270 | } |
4176 | |
4271 | |
4177 | void |
4272 | void |
4178 | ev_fork_stop (EV_P_ ev_fork *w) |
4273 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4179 | { |
4274 | { |
4180 | clear_pending (EV_A_ (W)w); |
4275 | clear_pending (EV_A_ (W)w); |
4181 | if (expect_false (!ev_is_active (w))) |
4276 | if (expect_false (!ev_is_active (w))) |
4182 | return; |
4277 | return; |
4183 | |
4278 | |
… | |
… | |
4196 | } |
4291 | } |
4197 | #endif |
4292 | #endif |
4198 | |
4293 | |
4199 | #if EV_CLEANUP_ENABLE |
4294 | #if EV_CLEANUP_ENABLE |
4200 | void |
4295 | void |
4201 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4296 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4202 | { |
4297 | { |
4203 | if (expect_false (ev_is_active (w))) |
4298 | if (expect_false (ev_is_active (w))) |
4204 | return; |
4299 | return; |
4205 | |
4300 | |
4206 | EV_FREQUENT_CHECK; |
4301 | EV_FREQUENT_CHECK; |
… | |
… | |
4213 | ev_unref (EV_A); |
4308 | ev_unref (EV_A); |
4214 | EV_FREQUENT_CHECK; |
4309 | EV_FREQUENT_CHECK; |
4215 | } |
4310 | } |
4216 | |
4311 | |
4217 | void |
4312 | void |
4218 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4313 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4219 | { |
4314 | { |
4220 | clear_pending (EV_A_ (W)w); |
4315 | clear_pending (EV_A_ (W)w); |
4221 | if (expect_false (!ev_is_active (w))) |
4316 | if (expect_false (!ev_is_active (w))) |
4222 | return; |
4317 | return; |
4223 | |
4318 | |
… | |
… | |
4237 | } |
4332 | } |
4238 | #endif |
4333 | #endif |
4239 | |
4334 | |
4240 | #if EV_ASYNC_ENABLE |
4335 | #if EV_ASYNC_ENABLE |
4241 | void |
4336 | void |
4242 | ev_async_start (EV_P_ ev_async *w) |
4337 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4243 | { |
4338 | { |
4244 | if (expect_false (ev_is_active (w))) |
4339 | if (expect_false (ev_is_active (w))) |
4245 | return; |
4340 | return; |
4246 | |
4341 | |
4247 | w->sent = 0; |
4342 | w->sent = 0; |
… | |
… | |
4256 | |
4351 | |
4257 | EV_FREQUENT_CHECK; |
4352 | EV_FREQUENT_CHECK; |
4258 | } |
4353 | } |
4259 | |
4354 | |
4260 | void |
4355 | void |
4261 | ev_async_stop (EV_P_ ev_async *w) |
4356 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4262 | { |
4357 | { |
4263 | clear_pending (EV_A_ (W)w); |
4358 | clear_pending (EV_A_ (W)w); |
4264 | if (expect_false (!ev_is_active (w))) |
4359 | if (expect_false (!ev_is_active (w))) |
4265 | return; |
4360 | return; |
4266 | |
4361 | |
… | |
… | |
4277 | |
4372 | |
4278 | EV_FREQUENT_CHECK; |
4373 | EV_FREQUENT_CHECK; |
4279 | } |
4374 | } |
4280 | |
4375 | |
4281 | void |
4376 | void |
4282 | ev_async_send (EV_P_ ev_async *w) |
4377 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4283 | { |
4378 | { |
4284 | w->sent = 1; |
4379 | w->sent = 1; |
4285 | evpipe_write (EV_A_ &async_pending); |
4380 | evpipe_write (EV_A_ &async_pending); |
4286 | } |
4381 | } |
4287 | #endif |
4382 | #endif |
… | |
… | |
4324 | |
4419 | |
4325 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4420 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4326 | } |
4421 | } |
4327 | |
4422 | |
4328 | void |
4423 | void |
4329 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4424 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4330 | { |
4425 | { |
4331 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4426 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4332 | |
4427 | |
4333 | if (expect_false (!once)) |
4428 | if (expect_false (!once)) |
4334 | { |
4429 | { |
… | |
… | |
4356 | |
4451 | |
4357 | /*****************************************************************************/ |
4452 | /*****************************************************************************/ |
4358 | |
4453 | |
4359 | #if EV_WALK_ENABLE |
4454 | #if EV_WALK_ENABLE |
4360 | void ecb_cold |
4455 | void ecb_cold |
4361 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4456 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4362 | { |
4457 | { |
4363 | int i, j; |
4458 | int i, j; |
4364 | ev_watcher_list *wl, *wn; |
4459 | ev_watcher_list *wl, *wn; |
4365 | |
4460 | |
4366 | if (types & (EV_IO | EV_EMBED)) |
4461 | if (types & (EV_IO | EV_EMBED)) |