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,2012 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 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 | * |
… | |
… | |
43 | # include EV_CONFIG_H |
43 | # include EV_CONFIG_H |
44 | # else |
44 | # else |
45 | # include "config.h" |
45 | # include "config.h" |
46 | # endif |
46 | # endif |
47 | |
47 | |
48 | #if HAVE_FLOOR |
48 | # if HAVE_FLOOR |
49 | # ifndef EV_USE_FLOOR |
49 | # ifndef EV_USE_FLOOR |
50 | # define EV_USE_FLOOR 1 |
50 | # define EV_USE_FLOOR 1 |
|
|
51 | # endif |
51 | # endif |
52 | # endif |
52 | #endif |
|
|
53 | |
53 | |
54 | # if HAVE_CLOCK_SYSCALL |
54 | # if HAVE_CLOCK_SYSCALL |
55 | # ifndef EV_USE_CLOCK_SYSCALL |
55 | # ifndef EV_USE_CLOCK_SYSCALL |
56 | # define EV_USE_CLOCK_SYSCALL 1 |
56 | # define EV_USE_CLOCK_SYSCALL 1 |
57 | # ifndef EV_USE_REALTIME |
57 | # ifndef EV_USE_REALTIME |
… | |
… | |
256 | # else |
256 | # else |
257 | # define EV_USE_CLOCK_SYSCALL 0 |
257 | # define EV_USE_CLOCK_SYSCALL 0 |
258 | # endif |
258 | # endif |
259 | #endif |
259 | #endif |
260 | |
260 | |
|
|
261 | #if !(_POSIX_TIMERS > 0) |
|
|
262 | # ifndef EV_USE_MONOTONIC |
|
|
263 | # define EV_USE_MONOTONIC 0 |
|
|
264 | # endif |
|
|
265 | # ifndef EV_USE_REALTIME |
|
|
266 | # define EV_USE_REALTIME 0 |
|
|
267 | # endif |
|
|
268 | #endif |
|
|
269 | |
261 | #ifndef EV_USE_MONOTONIC |
270 | #ifndef EV_USE_MONOTONIC |
262 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
271 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
263 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
272 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
264 | # else |
273 | # else |
265 | # define EV_USE_MONOTONIC 0 |
274 | # define EV_USE_MONOTONIC 0 |
… | |
… | |
482 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
491 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
483 | /* ECB.H BEGIN */ |
492 | /* ECB.H BEGIN */ |
484 | /* |
493 | /* |
485 | * libecb - http://software.schmorp.de/pkg/libecb |
494 | * libecb - http://software.schmorp.de/pkg/libecb |
486 | * |
495 | * |
487 | * Copyright (©) 2009-2013 Marc Alexander Lehmann <libecb@schmorp.de> |
496 | * Copyright (©) 2009-2014 Marc Alexander Lehmann <libecb@schmorp.de> |
488 | * Copyright (©) 2011 Emanuele Giaquinta |
497 | * Copyright (©) 2011 Emanuele Giaquinta |
489 | * All rights reserved. |
498 | * All rights reserved. |
490 | * |
499 | * |
491 | * Redistribution and use in source and binary forms, with or without modifica- |
500 | * Redistribution and use in source and binary forms, with or without modifica- |
492 | * tion, are permitted provided that the following conditions are met: |
501 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
506 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
515 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
507 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
516 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
508 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
517 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH- |
509 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
518 | * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
510 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
519 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
|
|
520 | * |
|
|
521 | * Alternatively, the contents of this file may be used under the terms of |
|
|
522 | * the GNU General Public License ("GPL") version 2 or any later version, |
|
|
523 | * in which case the provisions of the GPL are applicable instead of |
|
|
524 | * the above. If you wish to allow the use of your version of this file |
|
|
525 | * only under the terms of the GPL and not to allow others to use your |
|
|
526 | * version of this file under the BSD license, indicate your decision |
|
|
527 | * by deleting the provisions above and replace them with the notice |
|
|
528 | * and other provisions required by the GPL. If you do not delete the |
|
|
529 | * provisions above, a recipient may use your version of this file under |
|
|
530 | * either the BSD or the GPL. |
511 | */ |
531 | */ |
512 | |
532 | |
513 | #ifndef ECB_H |
533 | #ifndef ECB_H |
514 | #define ECB_H |
534 | #define ECB_H |
515 | |
535 | |
… | |
… | |
570 | #else |
590 | #else |
571 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
591 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
572 | #endif |
592 | #endif |
573 | #endif |
593 | #endif |
574 | |
594 | |
575 | #define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ |
|
|
576 | #define ECB_C99 (__STDC_VERSION__ >= 199901L) |
|
|
577 | #define ECB_C11 (__STDC_VERSION__ >= 201112L) |
|
|
578 | #define ECB_CPP (__cplusplus+0) |
595 | #define ECB_CPP (__cplusplus+0) |
579 | #define ECB_CPP11 (__cplusplus >= 201103L) |
596 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
597 | |
|
|
598 | #if ECB_CPP |
|
|
599 | #define ECB_C 0 |
|
|
600 | #define ECB_STDC_VERSION 0 |
|
|
601 | #else |
|
|
602 | #define ECB_C 1 |
|
|
603 | #define ECB_STDC_VERSION __STDC_VERSION__ |
|
|
604 | #endif |
|
|
605 | |
|
|
606 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
|
|
607 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
580 | |
608 | |
581 | #if ECB_CPP |
609 | #if ECB_CPP |
582 | #define ECB_EXTERN_C extern "C" |
610 | #define ECB_EXTERN_C extern "C" |
583 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
611 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
584 | #define ECB_EXTERN_C_END } |
612 | #define ECB_EXTERN_C_END } |
… | |
… | |
617 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
645 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
618 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
646 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
619 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
647 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
620 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
648 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
621 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
649 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
|
|
650 | #elif __aarch64__ |
|
|
651 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb ish" : : : "memory") |
622 | #elif (__sparc || __sparc__) && !__sparcv8 |
652 | #elif (__sparc || __sparc__) && !__sparcv8 |
623 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
653 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad" : : : "memory") |
624 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
654 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
625 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
655 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
626 | #elif defined __s390__ || defined __s390x__ |
656 | #elif defined __s390__ || defined __s390x__ |
… | |
… | |
648 | |
678 | |
649 | #ifndef ECB_MEMORY_FENCE |
679 | #ifndef ECB_MEMORY_FENCE |
650 | #if ECB_GCC_VERSION(4,7) |
680 | #if ECB_GCC_VERSION(4,7) |
651 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
681 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
652 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
682 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
|
|
683 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
|
|
684 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
653 | |
685 | |
654 | /* The __has_feature syntax from clang is so misdesigned that we cannot use it |
686 | /* The __has_feature syntax from clang is so misdesigned that we cannot use it |
655 | * without risking compile time errors with other compilers. We *could* |
687 | * without risking compile time errors with other compilers. We *could* |
656 | * define our own ecb_clang_has_feature, but I just can't be bothered to work |
688 | * define our own ecb_clang_has_feature, but I just can't be bothered to work |
657 | * around this shit time and again. |
689 | * around this shit time and again. |
658 | * #elif defined __clang && __has_feature (cxx_atomic) |
690 | * #elif defined __clang && __has_feature (cxx_atomic) |
659 | * // see comment below (stdatomic.h) about the C11 memory model. |
691 | * // see comment below (stdatomic.h) about the C11 memory model. |
660 | * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
692 | * #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
|
|
693 | * #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
|
|
694 | * #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
661 | */ |
695 | */ |
662 | |
696 | |
663 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
697 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
664 | #define ECB_MEMORY_FENCE __sync_synchronize () |
698 | #define ECB_MEMORY_FENCE __sync_synchronize () |
665 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
699 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
… | |
… | |
695 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
729 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
696 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
730 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
697 | /* for most usages, or gcc and clang have a bug */ |
731 | /* for most usages, or gcc and clang have a bug */ |
698 | /* I *currently* lean towards the latter, and inefficiently implement */ |
732 | /* I *currently* lean towards the latter, and inefficiently implement */ |
699 | /* all three of ecb's fences as a seq_cst fence */ |
733 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
734 | /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */ |
|
|
735 | /* for all __atomic_thread_fence's except seq_cst */ |
700 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
736 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
701 | #endif |
737 | #endif |
702 | #endif |
738 | #endif |
703 | |
739 | |
704 | #ifndef ECB_MEMORY_FENCE |
740 | #ifndef ECB_MEMORY_FENCE |
… | |
… | |
761 | #define ecb_is_constant(expr) __builtin_constant_p (expr) |
797 | #define ecb_is_constant(expr) __builtin_constant_p (expr) |
762 | #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
798 | #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) |
763 | #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
799 | #define ecb_prefetch(addr,rw,locality) __builtin_prefetch (addr, rw, locality) |
764 | #else |
800 | #else |
765 | #define ecb_attribute(attrlist) |
801 | #define ecb_attribute(attrlist) |
|
|
802 | |
|
|
803 | /* possible C11 impl for integral types |
|
|
804 | typedef struct ecb_is_constant_struct ecb_is_constant_struct; |
|
|
805 | #define ecb_is_constant(expr) _Generic ((1 ? (struct ecb_is_constant_struct *)0 : (void *)((expr) - (expr)), ecb_is_constant_struct *: 0, default: 1)) */ |
|
|
806 | |
766 | #define ecb_is_constant(expr) 0 |
807 | #define ecb_is_constant(expr) 0 |
767 | #define ecb_expect(expr,value) (expr) |
808 | #define ecb_expect(expr,value) (expr) |
768 | #define ecb_prefetch(addr,rw,locality) |
809 | #define ecb_prefetch(addr,rw,locality) |
769 | #endif |
810 | #endif |
770 | |
811 | |
… | |
… | |
773 | #define ecb_decltype(x) __decltype(x) |
814 | #define ecb_decltype(x) __decltype(x) |
774 | #elif ECB_GCC_VERSION(3,0) |
815 | #elif ECB_GCC_VERSION(3,0) |
775 | #define ecb_decltype(x) __typeof(x) |
816 | #define ecb_decltype(x) __typeof(x) |
776 | #endif |
817 | #endif |
777 | |
818 | |
|
|
819 | #if _MSC_VER >= 1300 |
|
|
820 | #define ecb_deprecated __declspec(deprecated) |
|
|
821 | #else |
|
|
822 | #define ecb_deprecated ecb_attribute ((__deprecated__)) |
|
|
823 | #endif |
|
|
824 | |
778 | #define ecb_noinline ecb_attribute ((__noinline__)) |
825 | #define ecb_noinline ecb_attribute ((__noinline__)) |
779 | #define ecb_unused ecb_attribute ((__unused__)) |
826 | #define ecb_unused ecb_attribute ((__unused__)) |
780 | #define ecb_const ecb_attribute ((__const__)) |
827 | #define ecb_const ecb_attribute ((__const__)) |
781 | #define ecb_pure ecb_attribute ((__pure__)) |
828 | #define ecb_pure ecb_attribute ((__pure__)) |
782 | |
829 | |
|
|
830 | /* http://msdn.microsoft.com/en-us/library/k6ktzx3s.aspx __declspec(noreturn) */ |
783 | #if ECB_C11 |
831 | #if ECB_C11 |
784 | #define ecb_noreturn _Noreturn |
832 | #define ecb_noreturn _Noreturn |
785 | #else |
833 | #else |
786 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
834 | #define ecb_noreturn ecb_attribute ((__noreturn__)) |
787 | #endif |
835 | #endif |
… | |
… | |
1056 | /* the only noteworthy exception is ancient armle, which uses order 43218765 */ |
1104 | /* the only noteworthy exception is ancient armle, which uses order 43218765 */ |
1057 | #if 0 \ |
1105 | #if 0 \ |
1058 | || __i386 || __i386__ \ |
1106 | || __i386 || __i386__ \ |
1059 | || __amd64 || __amd64__ || __x86_64 || __x86_64__ \ |
1107 | || __amd64 || __amd64__ || __x86_64 || __x86_64__ \ |
1060 | || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \ |
1108 | || __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ \ |
1061 | || defined __arm__ && defined __ARM_EABI__ \ |
|
|
1062 | || defined __s390__ || defined __s390x__ \ |
1109 | || defined __s390__ || defined __s390x__ \ |
1063 | || defined __mips__ \ |
1110 | || defined __mips__ \ |
1064 | || defined __alpha__ \ |
1111 | || defined __alpha__ \ |
1065 | || defined __hppa__ \ |
1112 | || defined __hppa__ \ |
1066 | || defined __ia64__ \ |
1113 | || defined __ia64__ \ |
1067 | || defined __m68k__ \ |
1114 | || defined __m68k__ \ |
1068 | || defined __m88k__ \ |
1115 | || defined __m88k__ \ |
1069 | || defined __sh__ \ |
1116 | || defined __sh__ \ |
1070 | || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 |
1117 | || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 \ |
|
|
1118 | || (defined __arm__ && (defined __ARM_EABI__ || defined __EABI__ || defined __VFP_FP__ || defined _WIN32_WCE || defined __ANDROID__)) \ |
|
|
1119 | || defined __aarch64__ |
1071 | #define ECB_STDFP 1 |
1120 | #define ECB_STDFP 1 |
1072 | #include <string.h> /* for memcpy */ |
1121 | #include <string.h> /* for memcpy */ |
1073 | #else |
1122 | #else |
1074 | #define ECB_STDFP 0 |
1123 | #define ECB_STDFP 0 |
1075 | #endif |
1124 | #endif |
… | |
… | |
2564 | { |
2613 | { |
2565 | invoke_cb = invoke_pending_cb; |
2614 | invoke_cb = invoke_pending_cb; |
2566 | } |
2615 | } |
2567 | |
2616 | |
2568 | void |
2617 | void |
2569 | ev_set_loop_release_cb (EV_P_ ev_loop_callback_nothrow release, ev_loop_callback_nothrow acquire) EV_THROW |
2618 | ev_set_loop_release_cb (EV_P_ ev_loop_callback EV_THROW release, ev_loop_callback EV_THROW acquire) EV_THROW |
2570 | { |
2619 | { |
2571 | release_cb = release; |
2620 | release_cb = release; |
2572 | acquire_cb = acquire; |
2621 | acquire_cb = acquire; |
2573 | } |
2622 | } |
2574 | #endif |
2623 | #endif |