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,2013 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007-2019 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 | * |
… | |
… | |
115 | # else |
115 | # else |
116 | # undef EV_USE_EPOLL |
116 | # undef EV_USE_EPOLL |
117 | # define EV_USE_EPOLL 0 |
117 | # define EV_USE_EPOLL 0 |
118 | # endif |
118 | # endif |
119 | |
119 | |
|
|
120 | # if HAVE_LINUX_AIO_ABI_H |
|
|
121 | # ifndef EV_USE_LINUXAIO |
|
|
122 | # define EV_USE_LINUXAIO EV_FEATURE_BACKENDS |
|
|
123 | # endif |
|
|
124 | # else |
|
|
125 | # undef EV_USE_LINUXAIO |
|
|
126 | # define EV_USE_LINUXAIO 0 |
|
|
127 | # endif |
|
|
128 | |
120 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
129 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
121 | # ifndef EV_USE_KQUEUE |
130 | # ifndef EV_USE_KQUEUE |
122 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
131 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
123 | # endif |
132 | # endif |
124 | # else |
133 | # else |
… | |
… | |
162 | # define EV_USE_EVENTFD 0 |
171 | # define EV_USE_EVENTFD 0 |
163 | # endif |
172 | # endif |
164 | |
173 | |
165 | #endif |
174 | #endif |
166 | |
175 | |
|
|
176 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
177 | * a limit of 1024 into their select. Where people have brains, |
|
|
178 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
179 | * ordered to have a vacuum, or they do anything for money. |
|
|
180 | * This might help. Or not. |
|
|
181 | * Note that this must be defined early, as other include files |
|
|
182 | * will rely on this define as well. |
|
|
183 | */ |
|
|
184 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
185 | |
167 | #include <stdlib.h> |
186 | #include <stdlib.h> |
168 | #include <string.h> |
187 | #include <string.h> |
169 | #include <fcntl.h> |
188 | #include <fcntl.h> |
170 | #include <stddef.h> |
189 | #include <stddef.h> |
171 | |
190 | |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
227 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
228 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
229 | # endif |
211 | # undef EV_AVOID_STDIO |
230 | # undef EV_AVOID_STDIO |
212 | #endif |
231 | #endif |
213 | |
|
|
214 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
215 | * a limit of 1024 into their select. Where people have brains, |
|
|
216 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
217 | * ordered to have a vacuum, or they do anything for money. |
|
|
218 | * This might help. Or not. |
|
|
219 | */ |
|
|
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
221 | |
232 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
233 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
234 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
235 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
236 | #if defined EV_NSIG |
… | |
… | |
313 | |
324 | |
314 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
315 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
316 | #endif |
327 | #endif |
317 | |
328 | |
|
|
329 | #ifndef EV_USE_LINUXAIO |
|
|
330 | # if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ |
|
|
331 | # define EV_USE_LINUXAIO 1 |
|
|
332 | # else |
|
|
333 | # define EV_USE_LINUXAIO 0 |
|
|
334 | # endif |
|
|
335 | #endif |
|
|
336 | |
318 | #ifndef EV_USE_INOTIFY |
337 | #ifndef EV_USE_INOTIFY |
319 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
320 | # define EV_USE_INOTIFY EV_FEATURE_OS |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
321 | # else |
340 | # else |
322 | # define EV_USE_INOTIFY 0 |
341 | # define EV_USE_INOTIFY 0 |
… | |
… | |
414 | |
433 | |
415 | #if !EV_USE_NANOSLEEP |
434 | #if !EV_USE_NANOSLEEP |
416 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
435 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
417 | # if !defined _WIN32 && !defined __hpux |
436 | # if !defined _WIN32 && !defined __hpux |
418 | # include <sys/select.h> |
437 | # include <sys/select.h> |
|
|
438 | # endif |
|
|
439 | #endif |
|
|
440 | |
|
|
441 | #if EV_USE_LINUXAIO |
|
|
442 | # include <sys/syscall.h> |
|
|
443 | # if !SYS_io_getevents || !EV_USE_EPOLL /* ev_linxaio uses ev_poll.c:ev_epoll_create */ |
|
|
444 | # undef EV_USE_LINUXAIO |
|
|
445 | # define EV_USE_LINUXAIO 0 |
419 | # endif |
446 | # endif |
420 | #endif |
447 | #endif |
421 | |
448 | |
422 | #if EV_USE_INOTIFY |
449 | #if EV_USE_INOTIFY |
423 | # include <sys/statfs.h> |
450 | # include <sys/statfs.h> |
… | |
… | |
532 | |
559 | |
533 | #ifndef ECB_H |
560 | #ifndef ECB_H |
534 | #define ECB_H |
561 | #define ECB_H |
535 | |
562 | |
536 | /* 16 bits major, 16 bits minor */ |
563 | /* 16 bits major, 16 bits minor */ |
537 | #define ECB_VERSION 0x00010005 |
564 | #define ECB_VERSION 0x00010006 |
538 | |
565 | |
539 | #ifdef _WIN32 |
566 | #ifdef _WIN32 |
540 | typedef signed char int8_t; |
567 | typedef signed char int8_t; |
541 | typedef unsigned char uint8_t; |
568 | typedef unsigned char uint8_t; |
542 | typedef signed short int16_t; |
569 | typedef signed short int16_t; |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
634 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
635 | #endif |
609 | |
636 | |
610 | #define ECB_CPP (__cplusplus+0) |
637 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
638 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
639 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
640 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
641 | |
613 | #if ECB_CPP |
642 | #if ECB_CPP |
614 | #define ECB_C 0 |
643 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
644 | #define ECB_STDC_VERSION 0 |
616 | #else |
645 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
647 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
648 | #endif |
620 | |
649 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
650 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
651 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
652 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
653 | |
624 | #if ECB_CPP |
654 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
655 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
656 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
657 | #define ECB_EXTERN_C_END } |
… | |
… | |
653 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
683 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
654 | #endif |
684 | #endif |
655 | |
685 | |
656 | #ifndef ECB_MEMORY_FENCE |
686 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
687 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
688 | #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory") |
658 | #if __i386 || __i386__ |
689 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
690 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
691 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
692 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
693 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
694 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
695 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
696 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
697 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
698 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
699 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
700 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
701 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
712 | #if ECB_GCC_VERSION(4,7) |
743 | #if ECB_GCC_VERSION(4,7) |
713 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
744 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
714 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
745 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
715 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
746 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
716 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
747 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
748 | #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED) |
717 | |
749 | |
718 | #elif ECB_CLANG_EXTENSION(c_atomic) |
750 | #elif ECB_CLANG_EXTENSION(c_atomic) |
719 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
751 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
720 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
752 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
721 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
753 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
722 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
754 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
755 | #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED) |
723 | |
756 | |
724 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
757 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
725 | #define ECB_MEMORY_FENCE __sync_synchronize () |
758 | #define ECB_MEMORY_FENCE __sync_synchronize () |
726 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
759 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
727 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
760 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
… | |
… | |
737 | #elif defined _WIN32 |
770 | #elif defined _WIN32 |
738 | #include <WinNT.h> |
771 | #include <WinNT.h> |
739 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
772 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
740 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
773 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
741 | #include <mbarrier.h> |
774 | #include <mbarrier.h> |
742 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
775 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
743 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
776 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier () |
744 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
777 | #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier () |
|
|
778 | #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier () |
745 | #elif __xlC__ |
779 | #elif __xlC__ |
746 | #define ECB_MEMORY_FENCE __sync () |
780 | #define ECB_MEMORY_FENCE __sync () |
747 | #endif |
781 | #endif |
748 | #endif |
782 | #endif |
749 | |
783 | |
750 | #ifndef ECB_MEMORY_FENCE |
784 | #ifndef ECB_MEMORY_FENCE |
751 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
785 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
752 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
786 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
753 | /* not just C11 atomics and atomic accesses */ |
787 | /* not just C11 atomics and atomic accesses */ |
754 | #include <stdatomic.h> |
788 | #include <stdatomic.h> |
755 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
756 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
757 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
758 | /* for most usages, or gcc and clang have a bug */ |
|
|
759 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
760 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
761 | /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */ |
|
|
762 | /* for all __atomic_thread_fence's except seq_cst */ |
|
|
763 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
789 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
|
|
790 | #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire) |
|
|
791 | #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release) |
764 | #endif |
792 | #endif |
765 | #endif |
793 | #endif |
766 | |
794 | |
767 | #ifndef ECB_MEMORY_FENCE |
795 | #ifndef ECB_MEMORY_FENCE |
768 | #if !ECB_AVOID_PTHREADS |
796 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
786 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
814 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
787 | #endif |
815 | #endif |
788 | |
816 | |
789 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
817 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
790 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
818 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
819 | #endif |
|
|
820 | |
|
|
821 | #if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE |
|
|
822 | #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */ |
791 | #endif |
823 | #endif |
792 | |
824 | |
793 | /*****************************************************************************/ |
825 | /*****************************************************************************/ |
794 | |
826 | |
795 | #if ECB_CPP |
827 | #if ECB_CPP |
… | |
… | |
1538 | # define ABSPRI(w) (((W)w), 0) |
1570 | # define ABSPRI(w) (((W)w), 0) |
1539 | #else |
1571 | #else |
1540 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1572 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1541 | #endif |
1573 | #endif |
1542 | |
1574 | |
1543 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1575 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1544 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1545 | |
1576 | |
1546 | typedef ev_watcher *W; |
1577 | typedef ev_watcher *W; |
1547 | typedef ev_watcher_list *WL; |
1578 | typedef ev_watcher_list *WL; |
1548 | typedef ev_watcher_time *WT; |
1579 | typedef ev_watcher_time *WT; |
1549 | |
1580 | |
… | |
… | |
1573 | #ifdef _WIN32 |
1604 | #ifdef _WIN32 |
1574 | # include "ev_win32.c" |
1605 | # include "ev_win32.c" |
1575 | #endif |
1606 | #endif |
1576 | |
1607 | |
1577 | /*****************************************************************************/ |
1608 | /*****************************************************************************/ |
|
|
1609 | |
|
|
1610 | #if EV_USE_LINUXAIO |
|
|
1611 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
1612 | #endif |
1578 | |
1613 | |
1579 | /* define a suitable floor function (only used by periodics atm) */ |
1614 | /* define a suitable floor function (only used by periodics atm) */ |
1580 | |
1615 | |
1581 | #if EV_USE_FLOOR |
1616 | #if EV_USE_FLOOR |
1582 | # include <math.h> |
1617 | # include <math.h> |
… | |
… | |
1675 | { |
1710 | { |
1676 | write (STDERR_FILENO, msg, strlen (msg)); |
1711 | write (STDERR_FILENO, msg, strlen (msg)); |
1677 | } |
1712 | } |
1678 | #endif |
1713 | #endif |
1679 | |
1714 | |
1680 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1715 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1681 | |
1716 | |
1682 | ecb_cold |
1717 | ecb_cold |
1683 | void |
1718 | void |
1684 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1719 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1685 | { |
1720 | { |
1686 | syserr_cb = cb; |
1721 | syserr_cb = cb; |
1687 | } |
1722 | } |
1688 | |
1723 | |
1689 | noinline ecb_cold |
1724 | noinline ecb_cold |
… | |
… | |
1708 | abort (); |
1743 | abort (); |
1709 | } |
1744 | } |
1710 | } |
1745 | } |
1711 | |
1746 | |
1712 | static void * |
1747 | static void * |
1713 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1748 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1714 | { |
1749 | { |
1715 | /* some systems, notably openbsd and darwin, fail to properly |
1750 | /* some systems, notably openbsd and darwin, fail to properly |
1716 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1751 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1717 | * the single unix specification, so work around them here. |
1752 | * the single unix specification, so work around them here. |
1718 | * recently, also (at least) fedora and debian started breaking it, |
1753 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1724 | |
1759 | |
1725 | free (ptr); |
1760 | free (ptr); |
1726 | return 0; |
1761 | return 0; |
1727 | } |
1762 | } |
1728 | |
1763 | |
1729 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1764 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1730 | |
1765 | |
1731 | ecb_cold |
1766 | ecb_cold |
1732 | void |
1767 | void |
1733 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1768 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1734 | { |
1769 | { |
1735 | alloc = cb; |
1770 | alloc = cb; |
1736 | } |
1771 | } |
1737 | |
1772 | |
1738 | inline_speed void * |
1773 | inline_speed void * |
… | |
… | |
1765 | typedef struct |
1800 | typedef struct |
1766 | { |
1801 | { |
1767 | WL head; |
1802 | WL head; |
1768 | unsigned char events; /* the events watched for */ |
1803 | unsigned char events; /* the events watched for */ |
1769 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1804 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1770 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
1805 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1771 | unsigned char unused; |
1806 | unsigned char unused; |
1772 | #if EV_USE_EPOLL |
1807 | #if EV_USE_EPOLL |
1773 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1808 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1774 | #endif |
1809 | #endif |
1775 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1810 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1855 | |
1890 | |
1856 | /*****************************************************************************/ |
1891 | /*****************************************************************************/ |
1857 | |
1892 | |
1858 | #ifndef EV_HAVE_EV_TIME |
1893 | #ifndef EV_HAVE_EV_TIME |
1859 | ev_tstamp |
1894 | ev_tstamp |
1860 | ev_time (void) EV_THROW |
1895 | ev_time (void) EV_NOEXCEPT |
1861 | { |
1896 | { |
1862 | #if EV_USE_REALTIME |
1897 | #if EV_USE_REALTIME |
1863 | if (expect_true (have_realtime)) |
1898 | if (expect_true (have_realtime)) |
1864 | { |
1899 | { |
1865 | struct timespec ts; |
1900 | struct timespec ts; |
… | |
… | |
1889 | return ev_time (); |
1924 | return ev_time (); |
1890 | } |
1925 | } |
1891 | |
1926 | |
1892 | #if EV_MULTIPLICITY |
1927 | #if EV_MULTIPLICITY |
1893 | ev_tstamp |
1928 | ev_tstamp |
1894 | ev_now (EV_P) EV_THROW |
1929 | ev_now (EV_P) EV_NOEXCEPT |
1895 | { |
1930 | { |
1896 | return ev_rt_now; |
1931 | return ev_rt_now; |
1897 | } |
1932 | } |
1898 | #endif |
1933 | #endif |
1899 | |
1934 | |
1900 | void |
1935 | void |
1901 | ev_sleep (ev_tstamp delay) EV_THROW |
1936 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1902 | { |
1937 | { |
1903 | if (delay > 0.) |
1938 | if (delay > 0.) |
1904 | { |
1939 | { |
1905 | #if EV_USE_NANOSLEEP |
1940 | #if EV_USE_NANOSLEEP |
1906 | struct timespec ts; |
1941 | struct timespec ts; |
… | |
… | |
1956 | { |
1991 | { |
1957 | *cur = array_nextsize (elem, *cur, cnt); |
1992 | *cur = array_nextsize (elem, *cur, cnt); |
1958 | return ev_realloc (base, elem * *cur); |
1993 | return ev_realloc (base, elem * *cur); |
1959 | } |
1994 | } |
1960 | |
1995 | |
|
|
1996 | #define array_needsize_noinit(base,offset,count) |
|
|
1997 | |
1961 | #define array_init_zero(base,count) \ |
1998 | #define array_needsize_zerofill(base,offset,count) \ |
1962 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1999 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
1963 | |
2000 | |
1964 | #define array_needsize(type,base,cur,cnt,init) \ |
2001 | #define array_needsize(type,base,cur,cnt,init) \ |
1965 | if (expect_false ((cnt) > (cur))) \ |
2002 | if (expect_false ((cnt) > (cur))) \ |
1966 | { \ |
2003 | { \ |
1967 | ecb_unused int ocur_ = (cur); \ |
2004 | ecb_unused int ocur_ = (cur); \ |
1968 | (base) = (type *)array_realloc \ |
2005 | (base) = (type *)array_realloc \ |
1969 | (sizeof (type), (base), &(cur), (cnt)); \ |
2006 | (sizeof (type), (base), &(cur), (cnt)); \ |
1970 | init ((base) + (ocur_), (cur) - ocur_); \ |
2007 | init ((base), ocur_, ((cur) - ocur_)); \ |
1971 | } |
2008 | } |
1972 | |
2009 | |
1973 | #if 0 |
2010 | #if 0 |
1974 | #define array_slim(type,stem) \ |
2011 | #define array_slim(type,stem) \ |
1975 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
2012 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
… | |
… | |
1992 | { |
2029 | { |
1993 | } |
2030 | } |
1994 | |
2031 | |
1995 | noinline |
2032 | noinline |
1996 | void |
2033 | void |
1997 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2034 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1998 | { |
2035 | { |
1999 | W w_ = (W)w; |
2036 | W w_ = (W)w; |
2000 | int pri = ABSPRI (w_); |
2037 | int pri = ABSPRI (w_); |
2001 | |
2038 | |
2002 | if (expect_false (w_->pending)) |
2039 | if (expect_false (w_->pending)) |
2003 | pendings [pri][w_->pending - 1].events |= revents; |
2040 | pendings [pri][w_->pending - 1].events |= revents; |
2004 | else |
2041 | else |
2005 | { |
2042 | { |
2006 | w_->pending = ++pendingcnt [pri]; |
2043 | w_->pending = ++pendingcnt [pri]; |
2007 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2044 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2008 | pendings [pri][w_->pending - 1].w = w_; |
2045 | pendings [pri][w_->pending - 1].w = w_; |
2009 | pendings [pri][w_->pending - 1].events = revents; |
2046 | pendings [pri][w_->pending - 1].events = revents; |
2010 | } |
2047 | } |
2011 | |
2048 | |
2012 | pendingpri = NUMPRI - 1; |
2049 | pendingpri = NUMPRI - 1; |
2013 | } |
2050 | } |
2014 | |
2051 | |
2015 | inline_speed void |
2052 | inline_speed void |
2016 | feed_reverse (EV_P_ W w) |
2053 | feed_reverse (EV_P_ W w) |
2017 | { |
2054 | { |
2018 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2055 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2019 | rfeeds [rfeedcnt++] = w; |
2056 | rfeeds [rfeedcnt++] = w; |
2020 | } |
2057 | } |
2021 | |
2058 | |
2022 | inline_size void |
2059 | inline_size void |
2023 | feed_reverse_done (EV_P_ int revents) |
2060 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2063 | if (expect_true (!anfd->reify)) |
2100 | if (expect_true (!anfd->reify)) |
2064 | fd_event_nocheck (EV_A_ fd, revents); |
2101 | fd_event_nocheck (EV_A_ fd, revents); |
2065 | } |
2102 | } |
2066 | |
2103 | |
2067 | void |
2104 | void |
2068 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2105 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2069 | { |
2106 | { |
2070 | if (fd >= 0 && fd < anfdmax) |
2107 | if (fd >= 0 && fd < anfdmax) |
2071 | fd_event_nocheck (EV_A_ fd, revents); |
2108 | fd_event_nocheck (EV_A_ fd, revents); |
2072 | } |
2109 | } |
2073 | |
2110 | |
… | |
… | |
2110 | ev_io *w; |
2147 | ev_io *w; |
2111 | |
2148 | |
2112 | unsigned char o_events = anfd->events; |
2149 | unsigned char o_events = anfd->events; |
2113 | unsigned char o_reify = anfd->reify; |
2150 | unsigned char o_reify = anfd->reify; |
2114 | |
2151 | |
2115 | anfd->reify = 0; |
2152 | anfd->reify = 0; |
2116 | |
2153 | |
2117 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2154 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2118 | { |
2155 | { |
2119 | anfd->events = 0; |
2156 | anfd->events = 0; |
2120 | |
2157 | |
… | |
… | |
2141 | anfds [fd].reify |= flags; |
2178 | anfds [fd].reify |= flags; |
2142 | |
2179 | |
2143 | if (expect_true (!reify)) |
2180 | if (expect_true (!reify)) |
2144 | { |
2181 | { |
2145 | ++fdchangecnt; |
2182 | ++fdchangecnt; |
2146 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2183 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2147 | fdchanges [fdchangecnt - 1] = fd; |
2184 | fdchanges [fdchangecnt - 1] = fd; |
2148 | } |
2185 | } |
2149 | } |
2186 | } |
2150 | |
2187 | |
2151 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2188 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
… | |
… | |
2473 | #endif |
2510 | #endif |
2474 | { |
2511 | { |
2475 | #ifdef _WIN32 |
2512 | #ifdef _WIN32 |
2476 | WSABUF buf; |
2513 | WSABUF buf; |
2477 | DWORD sent; |
2514 | DWORD sent; |
2478 | buf.buf = &buf; |
2515 | buf.buf = (char *)&buf; |
2479 | buf.len = 1; |
2516 | buf.len = 1; |
2480 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2517 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2481 | #else |
2518 | #else |
2482 | write (evpipe [1], &(evpipe [1]), 1); |
2519 | write (evpipe [1], &(evpipe [1]), 1); |
2483 | #endif |
2520 | #endif |
… | |
… | |
2555 | } |
2592 | } |
2556 | |
2593 | |
2557 | /*****************************************************************************/ |
2594 | /*****************************************************************************/ |
2558 | |
2595 | |
2559 | void |
2596 | void |
2560 | ev_feed_signal (int signum) EV_THROW |
2597 | ev_feed_signal (int signum) EV_NOEXCEPT |
2561 | { |
2598 | { |
2562 | #if EV_MULTIPLICITY |
2599 | #if EV_MULTIPLICITY |
2563 | EV_P; |
2600 | EV_P; |
2564 | ECB_MEMORY_FENCE_ACQUIRE; |
2601 | ECB_MEMORY_FENCE_ACQUIRE; |
2565 | EV_A = signals [signum - 1].loop; |
2602 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2582 | ev_feed_signal (signum); |
2619 | ev_feed_signal (signum); |
2583 | } |
2620 | } |
2584 | |
2621 | |
2585 | noinline |
2622 | noinline |
2586 | void |
2623 | void |
2587 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2624 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2588 | { |
2625 | { |
2589 | WL w; |
2626 | WL w; |
2590 | |
2627 | |
2591 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2628 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2592 | return; |
2629 | return; |
… | |
… | |
2701 | # include "ev_kqueue.c" |
2738 | # include "ev_kqueue.c" |
2702 | #endif |
2739 | #endif |
2703 | #if EV_USE_EPOLL |
2740 | #if EV_USE_EPOLL |
2704 | # include "ev_epoll.c" |
2741 | # include "ev_epoll.c" |
2705 | #endif |
2742 | #endif |
|
|
2743 | #if EV_USE_LINUXAIO |
|
|
2744 | # include "ev_linuxaio.c" |
|
|
2745 | #endif |
2706 | #if EV_USE_POLL |
2746 | #if EV_USE_POLL |
2707 | # include "ev_poll.c" |
2747 | # include "ev_poll.c" |
2708 | #endif |
2748 | #endif |
2709 | #if EV_USE_SELECT |
2749 | #if EV_USE_SELECT |
2710 | # include "ev_select.c" |
2750 | # include "ev_select.c" |
2711 | #endif |
2751 | #endif |
2712 | |
2752 | |
2713 | ecb_cold int |
2753 | ecb_cold int |
2714 | ev_version_major (void) EV_THROW |
2754 | ev_version_major (void) EV_NOEXCEPT |
2715 | { |
2755 | { |
2716 | return EV_VERSION_MAJOR; |
2756 | return EV_VERSION_MAJOR; |
2717 | } |
2757 | } |
2718 | |
2758 | |
2719 | ecb_cold int |
2759 | ecb_cold int |
2720 | ev_version_minor (void) EV_THROW |
2760 | ev_version_minor (void) EV_NOEXCEPT |
2721 | { |
2761 | { |
2722 | return EV_VERSION_MINOR; |
2762 | return EV_VERSION_MINOR; |
2723 | } |
2763 | } |
2724 | |
2764 | |
2725 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2765 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2734 | #endif |
2774 | #endif |
2735 | } |
2775 | } |
2736 | |
2776 | |
2737 | ecb_cold |
2777 | ecb_cold |
2738 | unsigned int |
2778 | unsigned int |
2739 | ev_supported_backends (void) EV_THROW |
2779 | ev_supported_backends (void) EV_NOEXCEPT |
2740 | { |
2780 | { |
2741 | unsigned int flags = 0; |
2781 | unsigned int flags = 0; |
2742 | |
2782 | |
2743 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2783 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2744 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2784 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2745 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2785 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2786 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2746 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2787 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2747 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2788 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2748 | |
2789 | |
2749 | return flags; |
2790 | return flags; |
2750 | } |
2791 | } |
2751 | |
2792 | |
2752 | ecb_cold |
2793 | ecb_cold |
2753 | unsigned int |
2794 | unsigned int |
2754 | ev_recommended_backends (void) EV_THROW |
2795 | ev_recommended_backends (void) EV_NOEXCEPT |
2755 | { |
2796 | { |
2756 | unsigned int flags = ev_supported_backends (); |
2797 | unsigned int flags = ev_supported_backends (); |
2757 | |
2798 | |
2758 | #ifndef __NetBSD__ |
2799 | #ifndef __NetBSD__ |
2759 | /* kqueue is borked on everything but netbsd apparently */ |
2800 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2767 | #endif |
2808 | #endif |
2768 | #ifdef __FreeBSD__ |
2809 | #ifdef __FreeBSD__ |
2769 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2810 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2770 | #endif |
2811 | #endif |
2771 | |
2812 | |
|
|
2813 | /* TODO: linuxaio is very experimental */ |
|
|
2814 | #if !EV_RECOMMEND_LINUXAIO |
|
|
2815 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2816 | #endif |
|
|
2817 | |
2772 | return flags; |
2818 | return flags; |
2773 | } |
2819 | } |
2774 | |
2820 | |
2775 | ecb_cold |
2821 | ecb_cold |
2776 | unsigned int |
2822 | unsigned int |
2777 | ev_embeddable_backends (void) EV_THROW |
2823 | ev_embeddable_backends (void) EV_NOEXCEPT |
2778 | { |
2824 | { |
2779 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2825 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2780 | |
2826 | |
2781 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2827 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2782 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2828 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2784 | |
2830 | |
2785 | return flags; |
2831 | return flags; |
2786 | } |
2832 | } |
2787 | |
2833 | |
2788 | unsigned int |
2834 | unsigned int |
2789 | ev_backend (EV_P) EV_THROW |
2835 | ev_backend (EV_P) EV_NOEXCEPT |
2790 | { |
2836 | { |
2791 | return backend; |
2837 | return backend; |
2792 | } |
2838 | } |
2793 | |
2839 | |
2794 | #if EV_FEATURE_API |
2840 | #if EV_FEATURE_API |
2795 | unsigned int |
2841 | unsigned int |
2796 | ev_iteration (EV_P) EV_THROW |
2842 | ev_iteration (EV_P) EV_NOEXCEPT |
2797 | { |
2843 | { |
2798 | return loop_count; |
2844 | return loop_count; |
2799 | } |
2845 | } |
2800 | |
2846 | |
2801 | unsigned int |
2847 | unsigned int |
2802 | ev_depth (EV_P) EV_THROW |
2848 | ev_depth (EV_P) EV_NOEXCEPT |
2803 | { |
2849 | { |
2804 | return loop_depth; |
2850 | return loop_depth; |
2805 | } |
2851 | } |
2806 | |
2852 | |
2807 | void |
2853 | void |
2808 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2854 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2809 | { |
2855 | { |
2810 | io_blocktime = interval; |
2856 | io_blocktime = interval; |
2811 | } |
2857 | } |
2812 | |
2858 | |
2813 | void |
2859 | void |
2814 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2860 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2815 | { |
2861 | { |
2816 | timeout_blocktime = interval; |
2862 | timeout_blocktime = interval; |
2817 | } |
2863 | } |
2818 | |
2864 | |
2819 | void |
2865 | void |
2820 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2866 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2821 | { |
2867 | { |
2822 | userdata = data; |
2868 | userdata = data; |
2823 | } |
2869 | } |
2824 | |
2870 | |
2825 | void * |
2871 | void * |
2826 | ev_userdata (EV_P) EV_THROW |
2872 | ev_userdata (EV_P) EV_NOEXCEPT |
2827 | { |
2873 | { |
2828 | return userdata; |
2874 | return userdata; |
2829 | } |
2875 | } |
2830 | |
2876 | |
2831 | void |
2877 | void |
2832 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2878 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2833 | { |
2879 | { |
2834 | invoke_cb = invoke_pending_cb; |
2880 | invoke_cb = invoke_pending_cb; |
2835 | } |
2881 | } |
2836 | |
2882 | |
2837 | void |
2883 | void |
2838 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2884 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2839 | { |
2885 | { |
2840 | release_cb = release; |
2886 | release_cb = release; |
2841 | acquire_cb = acquire; |
2887 | acquire_cb = acquire; |
2842 | } |
2888 | } |
2843 | #endif |
2889 | #endif |
2844 | |
2890 | |
2845 | /* initialise a loop structure, must be zero-initialised */ |
2891 | /* initialise a loop structure, must be zero-initialised */ |
2846 | noinline ecb_cold |
2892 | noinline ecb_cold |
2847 | static void |
2893 | static void |
2848 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2894 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2849 | { |
2895 | { |
2850 | if (!backend) |
2896 | if (!backend) |
2851 | { |
2897 | { |
2852 | origflags = flags; |
2898 | origflags = flags; |
2853 | |
2899 | |
… | |
… | |
2911 | |
2957 | |
2912 | if (!(flags & EVBACKEND_MASK)) |
2958 | if (!(flags & EVBACKEND_MASK)) |
2913 | flags |= ev_recommended_backends (); |
2959 | flags |= ev_recommended_backends (); |
2914 | |
2960 | |
2915 | #if EV_USE_IOCP |
2961 | #if EV_USE_IOCP |
2916 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2962 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2917 | #endif |
2963 | #endif |
2918 | #if EV_USE_PORT |
2964 | #if EV_USE_PORT |
2919 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2965 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2920 | #endif |
2966 | #endif |
2921 | #if EV_USE_KQUEUE |
2967 | #if EV_USE_KQUEUE |
2922 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
2968 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
2969 | #endif |
|
|
2970 | #if EV_USE_LINUXAIO |
|
|
2971 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2923 | #endif |
2972 | #endif |
2924 | #if EV_USE_EPOLL |
2973 | #if EV_USE_EPOLL |
2925 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2974 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2926 | #endif |
2975 | #endif |
2927 | #if EV_USE_POLL |
2976 | #if EV_USE_POLL |
2928 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2977 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2929 | #endif |
2978 | #endif |
2930 | #if EV_USE_SELECT |
2979 | #if EV_USE_SELECT |
2931 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2980 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2932 | #endif |
2981 | #endif |
2933 | |
2982 | |
2934 | ev_prepare_init (&pending_w, pendingcb); |
2983 | ev_prepare_init (&pending_w, pendingcb); |
2935 | |
2984 | |
2936 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2985 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2991 | |
3040 | |
2992 | if (backend_fd >= 0) |
3041 | if (backend_fd >= 0) |
2993 | close (backend_fd); |
3042 | close (backend_fd); |
2994 | |
3043 | |
2995 | #if EV_USE_IOCP |
3044 | #if EV_USE_IOCP |
2996 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3045 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2997 | #endif |
3046 | #endif |
2998 | #if EV_USE_PORT |
3047 | #if EV_USE_PORT |
2999 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3048 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3000 | #endif |
3049 | #endif |
3001 | #if EV_USE_KQUEUE |
3050 | #if EV_USE_KQUEUE |
3002 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3051 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3052 | #endif |
|
|
3053 | #if EV_USE_LINUXAIO |
|
|
3054 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
3003 | #endif |
3055 | #endif |
3004 | #if EV_USE_EPOLL |
3056 | #if EV_USE_EPOLL |
3005 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3057 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3006 | #endif |
3058 | #endif |
3007 | #if EV_USE_POLL |
3059 | #if EV_USE_POLL |
3008 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3060 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3009 | #endif |
3061 | #endif |
3010 | #if EV_USE_SELECT |
3062 | #if EV_USE_SELECT |
3011 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3063 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3012 | #endif |
3064 | #endif |
3013 | |
3065 | |
3014 | for (i = NUMPRI; i--; ) |
3066 | for (i = NUMPRI; i--; ) |
3015 | { |
3067 | { |
3016 | array_free (pending, [i]); |
3068 | array_free (pending, [i]); |
… | |
… | |
3058 | |
3110 | |
3059 | inline_size void |
3111 | inline_size void |
3060 | loop_fork (EV_P) |
3112 | loop_fork (EV_P) |
3061 | { |
3113 | { |
3062 | #if EV_USE_PORT |
3114 | #if EV_USE_PORT |
3063 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3115 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3064 | #endif |
3116 | #endif |
3065 | #if EV_USE_KQUEUE |
3117 | #if EV_USE_KQUEUE |
3066 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3118 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3119 | #endif |
|
|
3120 | #if EV_USE_LINUXAIO |
|
|
3121 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3067 | #endif |
3122 | #endif |
3068 | #if EV_USE_EPOLL |
3123 | #if EV_USE_EPOLL |
3069 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3124 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3070 | #endif |
3125 | #endif |
3071 | #if EV_USE_INOTIFY |
3126 | #if EV_USE_INOTIFY |
3072 | infy_fork (EV_A); |
3127 | infy_fork (EV_A); |
3073 | #endif |
3128 | #endif |
3074 | |
3129 | |
… | |
… | |
3094 | |
3149 | |
3095 | #if EV_MULTIPLICITY |
3150 | #if EV_MULTIPLICITY |
3096 | |
3151 | |
3097 | ecb_cold |
3152 | ecb_cold |
3098 | struct ev_loop * |
3153 | struct ev_loop * |
3099 | ev_loop_new (unsigned int flags) EV_THROW |
3154 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3100 | { |
3155 | { |
3101 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3156 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3102 | |
3157 | |
3103 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3158 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3104 | loop_init (EV_A_ flags); |
3159 | loop_init (EV_A_ flags); |
… | |
… | |
3151 | } |
3206 | } |
3152 | #endif |
3207 | #endif |
3153 | |
3208 | |
3154 | #if EV_FEATURE_API |
3209 | #if EV_FEATURE_API |
3155 | void ecb_cold |
3210 | void ecb_cold |
3156 | ev_verify (EV_P) EV_THROW |
3211 | ev_verify (EV_P) EV_NOEXCEPT |
3157 | { |
3212 | { |
3158 | #if EV_VERIFY |
3213 | #if EV_VERIFY |
3159 | int i; |
3214 | int i; |
3160 | WL w, w2; |
3215 | WL w, w2; |
3161 | |
3216 | |
… | |
… | |
3242 | ecb_cold |
3297 | ecb_cold |
3243 | struct ev_loop * |
3298 | struct ev_loop * |
3244 | #else |
3299 | #else |
3245 | int |
3300 | int |
3246 | #endif |
3301 | #endif |
3247 | ev_default_loop (unsigned int flags) EV_THROW |
3302 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3248 | { |
3303 | { |
3249 | if (!ev_default_loop_ptr) |
3304 | if (!ev_default_loop_ptr) |
3250 | { |
3305 | { |
3251 | #if EV_MULTIPLICITY |
3306 | #if EV_MULTIPLICITY |
3252 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3307 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3271 | |
3326 | |
3272 | return ev_default_loop_ptr; |
3327 | return ev_default_loop_ptr; |
3273 | } |
3328 | } |
3274 | |
3329 | |
3275 | void |
3330 | void |
3276 | ev_loop_fork (EV_P) EV_THROW |
3331 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3277 | { |
3332 | { |
3278 | postfork = 1; |
3333 | postfork = 1; |
3279 | } |
3334 | } |
3280 | |
3335 | |
3281 | /*****************************************************************************/ |
3336 | /*****************************************************************************/ |
… | |
… | |
3285 | { |
3340 | { |
3286 | EV_CB_INVOKE ((W)w, revents); |
3341 | EV_CB_INVOKE ((W)w, revents); |
3287 | } |
3342 | } |
3288 | |
3343 | |
3289 | unsigned int |
3344 | unsigned int |
3290 | ev_pending_count (EV_P) EV_THROW |
3345 | ev_pending_count (EV_P) EV_NOEXCEPT |
3291 | { |
3346 | { |
3292 | int pri; |
3347 | int pri; |
3293 | unsigned int count = 0; |
3348 | unsigned int count = 0; |
3294 | |
3349 | |
3295 | for (pri = NUMPRI; pri--; ) |
3350 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3302 | void |
3357 | void |
3303 | ev_invoke_pending (EV_P) |
3358 | ev_invoke_pending (EV_P) |
3304 | { |
3359 | { |
3305 | pendingpri = NUMPRI; |
3360 | pendingpri = NUMPRI; |
3306 | |
3361 | |
3307 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3362 | do |
3308 | { |
3363 | { |
3309 | --pendingpri; |
3364 | --pendingpri; |
3310 | |
3365 | |
|
|
3366 | /* pendingpri possibly gets modified in the inner loop */ |
3311 | while (pendingcnt [pendingpri]) |
3367 | while (pendingcnt [pendingpri]) |
3312 | { |
3368 | { |
3313 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3369 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3314 | |
3370 | |
3315 | p->w->pending = 0; |
3371 | p->w->pending = 0; |
3316 | EV_CB_INVOKE (p->w, p->events); |
3372 | EV_CB_INVOKE (p->w, p->events); |
3317 | EV_FREQUENT_CHECK; |
3373 | EV_FREQUENT_CHECK; |
3318 | } |
3374 | } |
3319 | } |
3375 | } |
|
|
3376 | while (pendingpri); |
3320 | } |
3377 | } |
3321 | |
3378 | |
3322 | #if EV_IDLE_ENABLE |
3379 | #if EV_IDLE_ENABLE |
3323 | /* make idle watchers pending. this handles the "call-idle */ |
3380 | /* make idle watchers pending. this handles the "call-idle */ |
3324 | /* only when higher priorities are idle" logic */ |
3381 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3692 | { |
3749 | { |
3693 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3750 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3694 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3751 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3695 | } |
3752 | } |
3696 | |
3753 | |
3697 | |
|
|
3698 | /* update ev_rt_now, do magic */ |
3754 | /* update ev_rt_now, do magic */ |
3699 | time_update (EV_A_ waittime + sleeptime); |
3755 | time_update (EV_A_ waittime + sleeptime); |
3700 | } |
3756 | } |
3701 | |
3757 | |
3702 | /* queue pending timers and reschedule them */ |
3758 | /* queue pending timers and reschedule them */ |
… | |
… | |
3733 | |
3789 | |
3734 | return activecnt; |
3790 | return activecnt; |
3735 | } |
3791 | } |
3736 | |
3792 | |
3737 | void |
3793 | void |
3738 | ev_break (EV_P_ int how) EV_THROW |
3794 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3739 | { |
3795 | { |
3740 | loop_done = how; |
3796 | loop_done = how; |
3741 | } |
3797 | } |
3742 | |
3798 | |
3743 | void |
3799 | void |
3744 | ev_ref (EV_P) EV_THROW |
3800 | ev_ref (EV_P) EV_NOEXCEPT |
3745 | { |
3801 | { |
3746 | ++activecnt; |
3802 | ++activecnt; |
3747 | } |
3803 | } |
3748 | |
3804 | |
3749 | void |
3805 | void |
3750 | ev_unref (EV_P) EV_THROW |
3806 | ev_unref (EV_P) EV_NOEXCEPT |
3751 | { |
3807 | { |
3752 | --activecnt; |
3808 | --activecnt; |
3753 | } |
3809 | } |
3754 | |
3810 | |
3755 | void |
3811 | void |
3756 | ev_now_update (EV_P) EV_THROW |
3812 | ev_now_update (EV_P) EV_NOEXCEPT |
3757 | { |
3813 | { |
3758 | time_update (EV_A_ 1e100); |
3814 | time_update (EV_A_ 1e100); |
3759 | } |
3815 | } |
3760 | |
3816 | |
3761 | void |
3817 | void |
3762 | ev_suspend (EV_P) EV_THROW |
3818 | ev_suspend (EV_P) EV_NOEXCEPT |
3763 | { |
3819 | { |
3764 | ev_now_update (EV_A); |
3820 | ev_now_update (EV_A); |
3765 | } |
3821 | } |
3766 | |
3822 | |
3767 | void |
3823 | void |
3768 | ev_resume (EV_P) EV_THROW |
3824 | ev_resume (EV_P) EV_NOEXCEPT |
3769 | { |
3825 | { |
3770 | ev_tstamp mn_prev = mn_now; |
3826 | ev_tstamp mn_prev = mn_now; |
3771 | |
3827 | |
3772 | ev_now_update (EV_A); |
3828 | ev_now_update (EV_A); |
3773 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3829 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3812 | w->pending = 0; |
3868 | w->pending = 0; |
3813 | } |
3869 | } |
3814 | } |
3870 | } |
3815 | |
3871 | |
3816 | int |
3872 | int |
3817 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3873 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3818 | { |
3874 | { |
3819 | W w_ = (W)w; |
3875 | W w_ = (W)w; |
3820 | int pending = w_->pending; |
3876 | int pending = w_->pending; |
3821 | |
3877 | |
3822 | if (expect_true (pending)) |
3878 | if (expect_true (pending)) |
… | |
… | |
3856 | |
3912 | |
3857 | /*****************************************************************************/ |
3913 | /*****************************************************************************/ |
3858 | |
3914 | |
3859 | noinline |
3915 | noinline |
3860 | void |
3916 | void |
3861 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3917 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3862 | { |
3918 | { |
3863 | int fd = w->fd; |
3919 | int fd = w->fd; |
3864 | |
3920 | |
3865 | if (expect_false (ev_is_active (w))) |
3921 | if (expect_false (ev_is_active (w))) |
3866 | return; |
3922 | return; |
3867 | |
3923 | |
3868 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3924 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3869 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3925 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3870 | |
3926 | |
|
|
3927 | #if EV_VERIFY >= 2 |
|
|
3928 | assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd))); |
|
|
3929 | #endif |
3871 | EV_FREQUENT_CHECK; |
3930 | EV_FREQUENT_CHECK; |
3872 | |
3931 | |
3873 | ev_start (EV_A_ (W)w, 1); |
3932 | ev_start (EV_A_ (W)w, 1); |
3874 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3933 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3875 | wlist_add (&anfds[fd].head, (WL)w); |
3934 | wlist_add (&anfds[fd].head, (WL)w); |
3876 | |
3935 | |
3877 | /* common bug, apparently */ |
3936 | /* common bug, apparently */ |
3878 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3937 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3879 | |
3938 | |
… | |
… | |
3883 | EV_FREQUENT_CHECK; |
3942 | EV_FREQUENT_CHECK; |
3884 | } |
3943 | } |
3885 | |
3944 | |
3886 | noinline |
3945 | noinline |
3887 | void |
3946 | void |
3888 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3947 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3889 | { |
3948 | { |
3890 | clear_pending (EV_A_ (W)w); |
3949 | clear_pending (EV_A_ (W)w); |
3891 | if (expect_false (!ev_is_active (w))) |
3950 | if (expect_false (!ev_is_active (w))) |
3892 | return; |
3951 | return; |
3893 | |
3952 | |
3894 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3953 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3895 | |
3954 | |
|
|
3955 | #if EV_VERIFY >= 2 |
|
|
3956 | assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd))); |
|
|
3957 | #endif |
3896 | EV_FREQUENT_CHECK; |
3958 | EV_FREQUENT_CHECK; |
3897 | |
3959 | |
3898 | wlist_del (&anfds[w->fd].head, (WL)w); |
3960 | wlist_del (&anfds[w->fd].head, (WL)w); |
3899 | ev_stop (EV_A_ (W)w); |
3961 | ev_stop (EV_A_ (W)w); |
3900 | |
3962 | |
… | |
… | |
3903 | EV_FREQUENT_CHECK; |
3965 | EV_FREQUENT_CHECK; |
3904 | } |
3966 | } |
3905 | |
3967 | |
3906 | noinline |
3968 | noinline |
3907 | void |
3969 | void |
3908 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3970 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3909 | { |
3971 | { |
3910 | if (expect_false (ev_is_active (w))) |
3972 | if (expect_false (ev_is_active (w))) |
3911 | return; |
3973 | return; |
3912 | |
3974 | |
3913 | ev_at (w) += mn_now; |
3975 | ev_at (w) += mn_now; |
… | |
… | |
3916 | |
3978 | |
3917 | EV_FREQUENT_CHECK; |
3979 | EV_FREQUENT_CHECK; |
3918 | |
3980 | |
3919 | ++timercnt; |
3981 | ++timercnt; |
3920 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3982 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3921 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3983 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3922 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3984 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3923 | ANHE_at_cache (timers [ev_active (w)]); |
3985 | ANHE_at_cache (timers [ev_active (w)]); |
3924 | upheap (timers, ev_active (w)); |
3986 | upheap (timers, ev_active (w)); |
3925 | |
3987 | |
3926 | EV_FREQUENT_CHECK; |
3988 | EV_FREQUENT_CHECK; |
… | |
… | |
3928 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3990 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3929 | } |
3991 | } |
3930 | |
3992 | |
3931 | noinline |
3993 | noinline |
3932 | void |
3994 | void |
3933 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3995 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3934 | { |
3996 | { |
3935 | clear_pending (EV_A_ (W)w); |
3997 | clear_pending (EV_A_ (W)w); |
3936 | if (expect_false (!ev_is_active (w))) |
3998 | if (expect_false (!ev_is_active (w))) |
3937 | return; |
3999 | return; |
3938 | |
4000 | |
… | |
… | |
3959 | EV_FREQUENT_CHECK; |
4021 | EV_FREQUENT_CHECK; |
3960 | } |
4022 | } |
3961 | |
4023 | |
3962 | noinline |
4024 | noinline |
3963 | void |
4025 | void |
3964 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4026 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3965 | { |
4027 | { |
3966 | EV_FREQUENT_CHECK; |
4028 | EV_FREQUENT_CHECK; |
3967 | |
4029 | |
3968 | clear_pending (EV_A_ (W)w); |
4030 | clear_pending (EV_A_ (W)w); |
3969 | |
4031 | |
… | |
… | |
3986 | |
4048 | |
3987 | EV_FREQUENT_CHECK; |
4049 | EV_FREQUENT_CHECK; |
3988 | } |
4050 | } |
3989 | |
4051 | |
3990 | ev_tstamp |
4052 | ev_tstamp |
3991 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4053 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3992 | { |
4054 | { |
3993 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4055 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3994 | } |
4056 | } |
3995 | |
4057 | |
3996 | #if EV_PERIODIC_ENABLE |
4058 | #if EV_PERIODIC_ENABLE |
3997 | noinline |
4059 | noinline |
3998 | void |
4060 | void |
3999 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4061 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4000 | { |
4062 | { |
4001 | if (expect_false (ev_is_active (w))) |
4063 | if (expect_false (ev_is_active (w))) |
4002 | return; |
4064 | return; |
4003 | |
4065 | |
4004 | if (w->reschedule_cb) |
4066 | if (w->reschedule_cb) |
… | |
… | |
4013 | |
4075 | |
4014 | EV_FREQUENT_CHECK; |
4076 | EV_FREQUENT_CHECK; |
4015 | |
4077 | |
4016 | ++periodiccnt; |
4078 | ++periodiccnt; |
4017 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4079 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4018 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4080 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4019 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4081 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4020 | ANHE_at_cache (periodics [ev_active (w)]); |
4082 | ANHE_at_cache (periodics [ev_active (w)]); |
4021 | upheap (periodics, ev_active (w)); |
4083 | upheap (periodics, ev_active (w)); |
4022 | |
4084 | |
4023 | EV_FREQUENT_CHECK; |
4085 | EV_FREQUENT_CHECK; |
… | |
… | |
4025 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4087 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4026 | } |
4088 | } |
4027 | |
4089 | |
4028 | noinline |
4090 | noinline |
4029 | void |
4091 | void |
4030 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4092 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4031 | { |
4093 | { |
4032 | clear_pending (EV_A_ (W)w); |
4094 | clear_pending (EV_A_ (W)w); |
4033 | if (expect_false (!ev_is_active (w))) |
4095 | if (expect_false (!ev_is_active (w))) |
4034 | return; |
4096 | return; |
4035 | |
4097 | |
… | |
… | |
4054 | EV_FREQUENT_CHECK; |
4116 | EV_FREQUENT_CHECK; |
4055 | } |
4117 | } |
4056 | |
4118 | |
4057 | noinline |
4119 | noinline |
4058 | void |
4120 | void |
4059 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4121 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4060 | { |
4122 | { |
4061 | /* TODO: use adjustheap and recalculation */ |
4123 | /* TODO: use adjustheap and recalculation */ |
4062 | ev_periodic_stop (EV_A_ w); |
4124 | ev_periodic_stop (EV_A_ w); |
4063 | ev_periodic_start (EV_A_ w); |
4125 | ev_periodic_start (EV_A_ w); |
4064 | } |
4126 | } |
… | |
… | |
4070 | |
4132 | |
4071 | #if EV_SIGNAL_ENABLE |
4133 | #if EV_SIGNAL_ENABLE |
4072 | |
4134 | |
4073 | noinline |
4135 | noinline |
4074 | void |
4136 | void |
4075 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4137 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4076 | { |
4138 | { |
4077 | if (expect_false (ev_is_active (w))) |
4139 | if (expect_false (ev_is_active (w))) |
4078 | return; |
4140 | return; |
4079 | |
4141 | |
4080 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4142 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4153 | EV_FREQUENT_CHECK; |
4215 | EV_FREQUENT_CHECK; |
4154 | } |
4216 | } |
4155 | |
4217 | |
4156 | noinline |
4218 | noinline |
4157 | void |
4219 | void |
4158 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4220 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4159 | { |
4221 | { |
4160 | clear_pending (EV_A_ (W)w); |
4222 | clear_pending (EV_A_ (W)w); |
4161 | if (expect_false (!ev_is_active (w))) |
4223 | if (expect_false (!ev_is_active (w))) |
4162 | return; |
4224 | return; |
4163 | |
4225 | |
… | |
… | |
4194 | #endif |
4256 | #endif |
4195 | |
4257 | |
4196 | #if EV_CHILD_ENABLE |
4258 | #if EV_CHILD_ENABLE |
4197 | |
4259 | |
4198 | void |
4260 | void |
4199 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4261 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4200 | { |
4262 | { |
4201 | #if EV_MULTIPLICITY |
4263 | #if EV_MULTIPLICITY |
4202 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4264 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4203 | #endif |
4265 | #endif |
4204 | if (expect_false (ev_is_active (w))) |
4266 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4211 | |
4273 | |
4212 | EV_FREQUENT_CHECK; |
4274 | EV_FREQUENT_CHECK; |
4213 | } |
4275 | } |
4214 | |
4276 | |
4215 | void |
4277 | void |
4216 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4278 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4217 | { |
4279 | { |
4218 | clear_pending (EV_A_ (W)w); |
4280 | clear_pending (EV_A_ (W)w); |
4219 | if (expect_false (!ev_is_active (w))) |
4281 | if (expect_false (!ev_is_active (w))) |
4220 | return; |
4282 | return; |
4221 | |
4283 | |
… | |
… | |
4486 | #else |
4548 | #else |
4487 | # define EV_LSTAT(p,b) lstat (p, b) |
4549 | # define EV_LSTAT(p,b) lstat (p, b) |
4488 | #endif |
4550 | #endif |
4489 | |
4551 | |
4490 | void |
4552 | void |
4491 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4553 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4492 | { |
4554 | { |
4493 | if (lstat (w->path, &w->attr) < 0) |
4555 | if (lstat (w->path, &w->attr) < 0) |
4494 | w->attr.st_nlink = 0; |
4556 | w->attr.st_nlink = 0; |
4495 | else if (!w->attr.st_nlink) |
4557 | else if (!w->attr.st_nlink) |
4496 | w->attr.st_nlink = 1; |
4558 | w->attr.st_nlink = 1; |
… | |
… | |
4536 | ev_feed_event (EV_A_ w, EV_STAT); |
4598 | ev_feed_event (EV_A_ w, EV_STAT); |
4537 | } |
4599 | } |
4538 | } |
4600 | } |
4539 | |
4601 | |
4540 | void |
4602 | void |
4541 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4603 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4542 | { |
4604 | { |
4543 | if (expect_false (ev_is_active (w))) |
4605 | if (expect_false (ev_is_active (w))) |
4544 | return; |
4606 | return; |
4545 | |
4607 | |
4546 | ev_stat_stat (EV_A_ w); |
4608 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4567 | |
4629 | |
4568 | EV_FREQUENT_CHECK; |
4630 | EV_FREQUENT_CHECK; |
4569 | } |
4631 | } |
4570 | |
4632 | |
4571 | void |
4633 | void |
4572 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4634 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4573 | { |
4635 | { |
4574 | clear_pending (EV_A_ (W)w); |
4636 | clear_pending (EV_A_ (W)w); |
4575 | if (expect_false (!ev_is_active (w))) |
4637 | if (expect_false (!ev_is_active (w))) |
4576 | return; |
4638 | return; |
4577 | |
4639 | |
… | |
… | |
4593 | } |
4655 | } |
4594 | #endif |
4656 | #endif |
4595 | |
4657 | |
4596 | #if EV_IDLE_ENABLE |
4658 | #if EV_IDLE_ENABLE |
4597 | void |
4659 | void |
4598 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4660 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4599 | { |
4661 | { |
4600 | if (expect_false (ev_is_active (w))) |
4662 | if (expect_false (ev_is_active (w))) |
4601 | return; |
4663 | return; |
4602 | |
4664 | |
4603 | pri_adjust (EV_A_ (W)w); |
4665 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4608 | int active = ++idlecnt [ABSPRI (w)]; |
4670 | int active = ++idlecnt [ABSPRI (w)]; |
4609 | |
4671 | |
4610 | ++idleall; |
4672 | ++idleall; |
4611 | ev_start (EV_A_ (W)w, active); |
4673 | ev_start (EV_A_ (W)w, active); |
4612 | |
4674 | |
4613 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4675 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4614 | idles [ABSPRI (w)][active - 1] = w; |
4676 | idles [ABSPRI (w)][active - 1] = w; |
4615 | } |
4677 | } |
4616 | |
4678 | |
4617 | EV_FREQUENT_CHECK; |
4679 | EV_FREQUENT_CHECK; |
4618 | } |
4680 | } |
4619 | |
4681 | |
4620 | void |
4682 | void |
4621 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4683 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4622 | { |
4684 | { |
4623 | clear_pending (EV_A_ (W)w); |
4685 | clear_pending (EV_A_ (W)w); |
4624 | if (expect_false (!ev_is_active (w))) |
4686 | if (expect_false (!ev_is_active (w))) |
4625 | return; |
4687 | return; |
4626 | |
4688 | |
… | |
… | |
4640 | } |
4702 | } |
4641 | #endif |
4703 | #endif |
4642 | |
4704 | |
4643 | #if EV_PREPARE_ENABLE |
4705 | #if EV_PREPARE_ENABLE |
4644 | void |
4706 | void |
4645 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4707 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4646 | { |
4708 | { |
4647 | if (expect_false (ev_is_active (w))) |
4709 | if (expect_false (ev_is_active (w))) |
4648 | return; |
4710 | return; |
4649 | |
4711 | |
4650 | EV_FREQUENT_CHECK; |
4712 | EV_FREQUENT_CHECK; |
4651 | |
4713 | |
4652 | ev_start (EV_A_ (W)w, ++preparecnt); |
4714 | ev_start (EV_A_ (W)w, ++preparecnt); |
4653 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4715 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4654 | prepares [preparecnt - 1] = w; |
4716 | prepares [preparecnt - 1] = w; |
4655 | |
4717 | |
4656 | EV_FREQUENT_CHECK; |
4718 | EV_FREQUENT_CHECK; |
4657 | } |
4719 | } |
4658 | |
4720 | |
4659 | void |
4721 | void |
4660 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4722 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4661 | { |
4723 | { |
4662 | clear_pending (EV_A_ (W)w); |
4724 | clear_pending (EV_A_ (W)w); |
4663 | if (expect_false (!ev_is_active (w))) |
4725 | if (expect_false (!ev_is_active (w))) |
4664 | return; |
4726 | return; |
4665 | |
4727 | |
… | |
… | |
4678 | } |
4740 | } |
4679 | #endif |
4741 | #endif |
4680 | |
4742 | |
4681 | #if EV_CHECK_ENABLE |
4743 | #if EV_CHECK_ENABLE |
4682 | void |
4744 | void |
4683 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4745 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4684 | { |
4746 | { |
4685 | if (expect_false (ev_is_active (w))) |
4747 | if (expect_false (ev_is_active (w))) |
4686 | return; |
4748 | return; |
4687 | |
4749 | |
4688 | EV_FREQUENT_CHECK; |
4750 | EV_FREQUENT_CHECK; |
4689 | |
4751 | |
4690 | ev_start (EV_A_ (W)w, ++checkcnt); |
4752 | ev_start (EV_A_ (W)w, ++checkcnt); |
4691 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4753 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4692 | checks [checkcnt - 1] = w; |
4754 | checks [checkcnt - 1] = w; |
4693 | |
4755 | |
4694 | EV_FREQUENT_CHECK; |
4756 | EV_FREQUENT_CHECK; |
4695 | } |
4757 | } |
4696 | |
4758 | |
4697 | void |
4759 | void |
4698 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4760 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4699 | { |
4761 | { |
4700 | clear_pending (EV_A_ (W)w); |
4762 | clear_pending (EV_A_ (W)w); |
4701 | if (expect_false (!ev_is_active (w))) |
4763 | if (expect_false (!ev_is_active (w))) |
4702 | return; |
4764 | return; |
4703 | |
4765 | |
… | |
… | |
4717 | #endif |
4779 | #endif |
4718 | |
4780 | |
4719 | #if EV_EMBED_ENABLE |
4781 | #if EV_EMBED_ENABLE |
4720 | noinline |
4782 | noinline |
4721 | void |
4783 | void |
4722 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4784 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4723 | { |
4785 | { |
4724 | ev_run (w->other, EVRUN_NOWAIT); |
4786 | ev_run (w->other, EVRUN_NOWAIT); |
4725 | } |
4787 | } |
4726 | |
4788 | |
4727 | static void |
4789 | static void |
… | |
… | |
4775 | ev_idle_stop (EV_A_ idle); |
4837 | ev_idle_stop (EV_A_ idle); |
4776 | } |
4838 | } |
4777 | #endif |
4839 | #endif |
4778 | |
4840 | |
4779 | void |
4841 | void |
4780 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4842 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4781 | { |
4843 | { |
4782 | if (expect_false (ev_is_active (w))) |
4844 | if (expect_false (ev_is_active (w))) |
4783 | return; |
4845 | return; |
4784 | |
4846 | |
4785 | { |
4847 | { |
… | |
… | |
4806 | |
4868 | |
4807 | EV_FREQUENT_CHECK; |
4869 | EV_FREQUENT_CHECK; |
4808 | } |
4870 | } |
4809 | |
4871 | |
4810 | void |
4872 | void |
4811 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4873 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4812 | { |
4874 | { |
4813 | clear_pending (EV_A_ (W)w); |
4875 | clear_pending (EV_A_ (W)w); |
4814 | if (expect_false (!ev_is_active (w))) |
4876 | if (expect_false (!ev_is_active (w))) |
4815 | return; |
4877 | return; |
4816 | |
4878 | |
… | |
… | |
4826 | } |
4888 | } |
4827 | #endif |
4889 | #endif |
4828 | |
4890 | |
4829 | #if EV_FORK_ENABLE |
4891 | #if EV_FORK_ENABLE |
4830 | void |
4892 | void |
4831 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4893 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4832 | { |
4894 | { |
4833 | if (expect_false (ev_is_active (w))) |
4895 | if (expect_false (ev_is_active (w))) |
4834 | return; |
4896 | return; |
4835 | |
4897 | |
4836 | EV_FREQUENT_CHECK; |
4898 | EV_FREQUENT_CHECK; |
4837 | |
4899 | |
4838 | ev_start (EV_A_ (W)w, ++forkcnt); |
4900 | ev_start (EV_A_ (W)w, ++forkcnt); |
4839 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4901 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4840 | forks [forkcnt - 1] = w; |
4902 | forks [forkcnt - 1] = w; |
4841 | |
4903 | |
4842 | EV_FREQUENT_CHECK; |
4904 | EV_FREQUENT_CHECK; |
4843 | } |
4905 | } |
4844 | |
4906 | |
4845 | void |
4907 | void |
4846 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4908 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4847 | { |
4909 | { |
4848 | clear_pending (EV_A_ (W)w); |
4910 | clear_pending (EV_A_ (W)w); |
4849 | if (expect_false (!ev_is_active (w))) |
4911 | if (expect_false (!ev_is_active (w))) |
4850 | return; |
4912 | return; |
4851 | |
4913 | |
… | |
… | |
4864 | } |
4926 | } |
4865 | #endif |
4927 | #endif |
4866 | |
4928 | |
4867 | #if EV_CLEANUP_ENABLE |
4929 | #if EV_CLEANUP_ENABLE |
4868 | void |
4930 | void |
4869 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4931 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4870 | { |
4932 | { |
4871 | if (expect_false (ev_is_active (w))) |
4933 | if (expect_false (ev_is_active (w))) |
4872 | return; |
4934 | return; |
4873 | |
4935 | |
4874 | EV_FREQUENT_CHECK; |
4936 | EV_FREQUENT_CHECK; |
4875 | |
4937 | |
4876 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4938 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4877 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4939 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4878 | cleanups [cleanupcnt - 1] = w; |
4940 | cleanups [cleanupcnt - 1] = w; |
4879 | |
4941 | |
4880 | /* cleanup watchers should never keep a refcount on the loop */ |
4942 | /* cleanup watchers should never keep a refcount on the loop */ |
4881 | ev_unref (EV_A); |
4943 | ev_unref (EV_A); |
4882 | EV_FREQUENT_CHECK; |
4944 | EV_FREQUENT_CHECK; |
4883 | } |
4945 | } |
4884 | |
4946 | |
4885 | void |
4947 | void |
4886 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4948 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4887 | { |
4949 | { |
4888 | clear_pending (EV_A_ (W)w); |
4950 | clear_pending (EV_A_ (W)w); |
4889 | if (expect_false (!ev_is_active (w))) |
4951 | if (expect_false (!ev_is_active (w))) |
4890 | return; |
4952 | return; |
4891 | |
4953 | |
… | |
… | |
4905 | } |
4967 | } |
4906 | #endif |
4968 | #endif |
4907 | |
4969 | |
4908 | #if EV_ASYNC_ENABLE |
4970 | #if EV_ASYNC_ENABLE |
4909 | void |
4971 | void |
4910 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4972 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4911 | { |
4973 | { |
4912 | if (expect_false (ev_is_active (w))) |
4974 | if (expect_false (ev_is_active (w))) |
4913 | return; |
4975 | return; |
4914 | |
4976 | |
4915 | w->sent = 0; |
4977 | w->sent = 0; |
… | |
… | |
4917 | evpipe_init (EV_A); |
4979 | evpipe_init (EV_A); |
4918 | |
4980 | |
4919 | EV_FREQUENT_CHECK; |
4981 | EV_FREQUENT_CHECK; |
4920 | |
4982 | |
4921 | ev_start (EV_A_ (W)w, ++asynccnt); |
4983 | ev_start (EV_A_ (W)w, ++asynccnt); |
4922 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4984 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4923 | asyncs [asynccnt - 1] = w; |
4985 | asyncs [asynccnt - 1] = w; |
4924 | |
4986 | |
4925 | EV_FREQUENT_CHECK; |
4987 | EV_FREQUENT_CHECK; |
4926 | } |
4988 | } |
4927 | |
4989 | |
4928 | void |
4990 | void |
4929 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4991 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4930 | { |
4992 | { |
4931 | clear_pending (EV_A_ (W)w); |
4993 | clear_pending (EV_A_ (W)w); |
4932 | if (expect_false (!ev_is_active (w))) |
4994 | if (expect_false (!ev_is_active (w))) |
4933 | return; |
4995 | return; |
4934 | |
4996 | |
… | |
… | |
4945 | |
5007 | |
4946 | EV_FREQUENT_CHECK; |
5008 | EV_FREQUENT_CHECK; |
4947 | } |
5009 | } |
4948 | |
5010 | |
4949 | void |
5011 | void |
4950 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
5012 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4951 | { |
5013 | { |
4952 | w->sent = 1; |
5014 | w->sent = 1; |
4953 | evpipe_write (EV_A_ &async_pending); |
5015 | evpipe_write (EV_A_ &async_pending); |
4954 | } |
5016 | } |
4955 | #endif |
5017 | #endif |
… | |
… | |
4992 | |
5054 | |
4993 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5055 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4994 | } |
5056 | } |
4995 | |
5057 | |
4996 | void |
5058 | void |
4997 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5059 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4998 | { |
5060 | { |
4999 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5061 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5000 | |
|
|
5001 | if (expect_false (!once)) |
|
|
5002 | { |
|
|
5003 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5004 | return; |
|
|
5005 | } |
|
|
5006 | |
5062 | |
5007 | once->cb = cb; |
5063 | once->cb = cb; |
5008 | once->arg = arg; |
5064 | once->arg = arg; |
5009 | |
5065 | |
5010 | ev_init (&once->io, once_cb_io); |
5066 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5025 | /*****************************************************************************/ |
5081 | /*****************************************************************************/ |
5026 | |
5082 | |
5027 | #if EV_WALK_ENABLE |
5083 | #if EV_WALK_ENABLE |
5028 | ecb_cold |
5084 | ecb_cold |
5029 | void |
5085 | void |
5030 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5086 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
5031 | { |
5087 | { |
5032 | int i, j; |
5088 | int i, j; |
5033 | ev_watcher_list *wl, *wn; |
5089 | ev_watcher_list *wl, *wn; |
5034 | |
5090 | |
5035 | if (types & (EV_IO | EV_EMBED)) |
5091 | if (types & (EV_IO | EV_EMBED)) |