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 |
… | |
… | |
315 | |
324 | |
316 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
317 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
318 | #endif |
327 | #endif |
319 | |
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 | |
320 | #ifndef EV_USE_INOTIFY |
337 | #ifndef EV_USE_INOTIFY |
321 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
322 | # define EV_USE_INOTIFY EV_FEATURE_OS |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
323 | # else |
340 | # else |
324 | # define EV_USE_INOTIFY 0 |
341 | # define EV_USE_INOTIFY 0 |
… | |
… | |
416 | |
433 | |
417 | #if !EV_USE_NANOSLEEP |
434 | #if !EV_USE_NANOSLEEP |
418 | /* 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 */ |
419 | # if !defined _WIN32 && !defined __hpux |
436 | # if !defined _WIN32 && !defined __hpux |
420 | # 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 |
421 | # endif |
446 | # endif |
422 | #endif |
447 | #endif |
423 | |
448 | |
424 | #if EV_USE_INOTIFY |
449 | #if EV_USE_INOTIFY |
425 | # include <sys/statfs.h> |
450 | # include <sys/statfs.h> |
… | |
… | |
534 | |
559 | |
535 | #ifndef ECB_H |
560 | #ifndef ECB_H |
536 | #define ECB_H |
561 | #define ECB_H |
537 | |
562 | |
538 | /* 16 bits major, 16 bits minor */ |
563 | /* 16 bits major, 16 bits minor */ |
539 | #define ECB_VERSION 0x00010005 |
564 | #define ECB_VERSION 0x00010006 |
540 | |
565 | |
541 | #ifdef _WIN32 |
566 | #ifdef _WIN32 |
542 | typedef signed char int8_t; |
567 | typedef signed char int8_t; |
543 | typedef unsigned char uint8_t; |
568 | typedef unsigned char uint8_t; |
544 | typedef signed short int16_t; |
569 | typedef signed short int16_t; |
… | |
… | |
609 | #define ECB_CLANG_EXTENSION(x) 0 |
634 | #define ECB_CLANG_EXTENSION(x) 0 |
610 | #endif |
635 | #endif |
611 | |
636 | |
612 | #define ECB_CPP (__cplusplus+0) |
637 | #define ECB_CPP (__cplusplus+0) |
613 | #define ECB_CPP11 (__cplusplus >= 201103L) |
638 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
639 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
640 | #define ECB_CPP17 (__cplusplus >= 201703L) |
614 | |
641 | |
615 | #if ECB_CPP |
642 | #if ECB_CPP |
616 | #define ECB_C 0 |
643 | #define ECB_C 0 |
617 | #define ECB_STDC_VERSION 0 |
644 | #define ECB_STDC_VERSION 0 |
618 | #else |
645 | #else |
… | |
… | |
620 | #define ECB_STDC_VERSION __STDC_VERSION__ |
647 | #define ECB_STDC_VERSION __STDC_VERSION__ |
621 | #endif |
648 | #endif |
622 | |
649 | |
623 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
650 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
624 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
651 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
652 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
625 | |
653 | |
626 | #if ECB_CPP |
654 | #if ECB_CPP |
627 | #define ECB_EXTERN_C extern "C" |
655 | #define ECB_EXTERN_C extern "C" |
628 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
656 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
629 | #define ECB_EXTERN_C_END } |
657 | #define ECB_EXTERN_C_END } |
… | |
… | |
655 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
683 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
656 | #endif |
684 | #endif |
657 | |
685 | |
658 | #ifndef ECB_MEMORY_FENCE |
686 | #ifndef ECB_MEMORY_FENCE |
659 | #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") |
660 | #if __i386 || __i386__ |
689 | #if __i386 || __i386__ |
661 | #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") |
662 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
691 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
663 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
692 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
664 | #elif ECB_GCC_AMD64 |
693 | #elif ECB_GCC_AMD64 |
665 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
694 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
666 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
695 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
667 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
696 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
668 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
697 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
669 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
698 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
670 | #elif defined __ARM_ARCH_2__ \ |
699 | #elif defined __ARM_ARCH_2__ \ |
671 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
700 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
672 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
701 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
714 | #if ECB_GCC_VERSION(4,7) |
743 | #if ECB_GCC_VERSION(4,7) |
715 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
744 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
716 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
745 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
717 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
746 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
718 | #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) |
719 | |
749 | |
720 | #elif ECB_CLANG_EXTENSION(c_atomic) |
750 | #elif ECB_CLANG_EXTENSION(c_atomic) |
721 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
751 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
722 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
752 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
723 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
753 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
724 | #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) |
725 | |
756 | |
726 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
757 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
727 | #define ECB_MEMORY_FENCE __sync_synchronize () |
758 | #define ECB_MEMORY_FENCE __sync_synchronize () |
728 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
759 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
729 | /* 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... */ |
… | |
… | |
739 | #elif defined _WIN32 |
770 | #elif defined _WIN32 |
740 | #include <WinNT.h> |
771 | #include <WinNT.h> |
741 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
772 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
742 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
773 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
743 | #include <mbarrier.h> |
774 | #include <mbarrier.h> |
744 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
775 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
745 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
776 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier () |
746 | #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 () |
747 | #elif __xlC__ |
779 | #elif __xlC__ |
748 | #define ECB_MEMORY_FENCE __sync () |
780 | #define ECB_MEMORY_FENCE __sync () |
749 | #endif |
781 | #endif |
750 | #endif |
782 | #endif |
751 | |
783 | |
752 | #ifndef ECB_MEMORY_FENCE |
784 | #ifndef ECB_MEMORY_FENCE |
753 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
785 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
754 | /* 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, */ |
755 | /* not just C11 atomics and atomic accesses */ |
787 | /* not just C11 atomics and atomic accesses */ |
756 | #include <stdatomic.h> |
788 | #include <stdatomic.h> |
757 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
758 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
759 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
760 | /* for most usages, or gcc and clang have a bug */ |
|
|
761 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
762 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
763 | /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */ |
|
|
764 | /* for all __atomic_thread_fence's except seq_cst */ |
|
|
765 | #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) |
766 | #endif |
792 | #endif |
767 | #endif |
793 | #endif |
768 | |
794 | |
769 | #ifndef ECB_MEMORY_FENCE |
795 | #ifndef ECB_MEMORY_FENCE |
770 | #if !ECB_AVOID_PTHREADS |
796 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
788 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
814 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
789 | #endif |
815 | #endif |
790 | |
816 | |
791 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
817 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
792 | #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 */ |
793 | #endif |
823 | #endif |
794 | |
824 | |
795 | /*****************************************************************************/ |
825 | /*****************************************************************************/ |
796 | |
826 | |
797 | #if ECB_CPP |
827 | #if ECB_CPP |
… | |
… | |
1540 | # define ABSPRI(w) (((W)w), 0) |
1570 | # define ABSPRI(w) (((W)w), 0) |
1541 | #else |
1571 | #else |
1542 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1572 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1543 | #endif |
1573 | #endif |
1544 | |
1574 | |
1545 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1575 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1546 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1547 | |
1576 | |
1548 | typedef ev_watcher *W; |
1577 | typedef ev_watcher *W; |
1549 | typedef ev_watcher_list *WL; |
1578 | typedef ev_watcher_list *WL; |
1550 | typedef ev_watcher_time *WT; |
1579 | typedef ev_watcher_time *WT; |
1551 | |
1580 | |
… | |
… | |
1575 | #ifdef _WIN32 |
1604 | #ifdef _WIN32 |
1576 | # include "ev_win32.c" |
1605 | # include "ev_win32.c" |
1577 | #endif |
1606 | #endif |
1578 | |
1607 | |
1579 | /*****************************************************************************/ |
1608 | /*****************************************************************************/ |
|
|
1609 | |
|
|
1610 | #if EV_USE_LINUXAIO |
|
|
1611 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
1612 | #endif |
1580 | |
1613 | |
1581 | /* define a suitable floor function (only used by periodics atm) */ |
1614 | /* define a suitable floor function (only used by periodics atm) */ |
1582 | |
1615 | |
1583 | #if EV_USE_FLOOR |
1616 | #if EV_USE_FLOOR |
1584 | # include <math.h> |
1617 | # include <math.h> |
… | |
… | |
1677 | { |
1710 | { |
1678 | write (STDERR_FILENO, msg, strlen (msg)); |
1711 | write (STDERR_FILENO, msg, strlen (msg)); |
1679 | } |
1712 | } |
1680 | #endif |
1713 | #endif |
1681 | |
1714 | |
1682 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1715 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1683 | |
1716 | |
1684 | ecb_cold |
1717 | ecb_cold |
1685 | void |
1718 | void |
1686 | 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 |
1687 | { |
1720 | { |
1688 | syserr_cb = cb; |
1721 | syserr_cb = cb; |
1689 | } |
1722 | } |
1690 | |
1723 | |
1691 | noinline ecb_cold |
1724 | noinline ecb_cold |
… | |
… | |
1710 | abort (); |
1743 | abort (); |
1711 | } |
1744 | } |
1712 | } |
1745 | } |
1713 | |
1746 | |
1714 | static void * |
1747 | static void * |
1715 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1748 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1716 | { |
1749 | { |
1717 | /* some systems, notably openbsd and darwin, fail to properly |
1750 | /* some systems, notably openbsd and darwin, fail to properly |
1718 | * 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 |
1719 | * the single unix specification, so work around them here. |
1752 | * the single unix specification, so work around them here. |
1720 | * recently, also (at least) fedora and debian started breaking it, |
1753 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1726 | |
1759 | |
1727 | free (ptr); |
1760 | free (ptr); |
1728 | return 0; |
1761 | return 0; |
1729 | } |
1762 | } |
1730 | |
1763 | |
1731 | 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; |
1732 | |
1765 | |
1733 | ecb_cold |
1766 | ecb_cold |
1734 | void |
1767 | void |
1735 | 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 |
1736 | { |
1769 | { |
1737 | alloc = cb; |
1770 | alloc = cb; |
1738 | } |
1771 | } |
1739 | |
1772 | |
1740 | inline_speed void * |
1773 | inline_speed void * |
… | |
… | |
1767 | typedef struct |
1800 | typedef struct |
1768 | { |
1801 | { |
1769 | WL head; |
1802 | WL head; |
1770 | unsigned char events; /* the events watched for */ |
1803 | unsigned char events; /* the events watched for */ |
1771 | 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) */ |
1772 | 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 */ |
1773 | unsigned char unused; |
1806 | unsigned char unused; |
1774 | #if EV_USE_EPOLL |
1807 | #if EV_USE_EPOLL |
1775 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1808 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1776 | #endif |
1809 | #endif |
1777 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1810 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1857 | |
1890 | |
1858 | /*****************************************************************************/ |
1891 | /*****************************************************************************/ |
1859 | |
1892 | |
1860 | #ifndef EV_HAVE_EV_TIME |
1893 | #ifndef EV_HAVE_EV_TIME |
1861 | ev_tstamp |
1894 | ev_tstamp |
1862 | ev_time (void) EV_THROW |
1895 | ev_time (void) EV_NOEXCEPT |
1863 | { |
1896 | { |
1864 | #if EV_USE_REALTIME |
1897 | #if EV_USE_REALTIME |
1865 | if (expect_true (have_realtime)) |
1898 | if (expect_true (have_realtime)) |
1866 | { |
1899 | { |
1867 | struct timespec ts; |
1900 | struct timespec ts; |
… | |
… | |
1891 | return ev_time (); |
1924 | return ev_time (); |
1892 | } |
1925 | } |
1893 | |
1926 | |
1894 | #if EV_MULTIPLICITY |
1927 | #if EV_MULTIPLICITY |
1895 | ev_tstamp |
1928 | ev_tstamp |
1896 | ev_now (EV_P) EV_THROW |
1929 | ev_now (EV_P) EV_NOEXCEPT |
1897 | { |
1930 | { |
1898 | return ev_rt_now; |
1931 | return ev_rt_now; |
1899 | } |
1932 | } |
1900 | #endif |
1933 | #endif |
1901 | |
1934 | |
1902 | void |
1935 | void |
1903 | ev_sleep (ev_tstamp delay) EV_THROW |
1936 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1904 | { |
1937 | { |
1905 | if (delay > 0.) |
1938 | if (delay > 0.) |
1906 | { |
1939 | { |
1907 | #if EV_USE_NANOSLEEP |
1940 | #if EV_USE_NANOSLEEP |
1908 | struct timespec ts; |
1941 | struct timespec ts; |
… | |
… | |
1958 | { |
1991 | { |
1959 | *cur = array_nextsize (elem, *cur, cnt); |
1992 | *cur = array_nextsize (elem, *cur, cnt); |
1960 | return ev_realloc (base, elem * *cur); |
1993 | return ev_realloc (base, elem * *cur); |
1961 | } |
1994 | } |
1962 | |
1995 | |
|
|
1996 | #define array_needsize_noinit(base,offset,count) |
|
|
1997 | |
1963 | #define array_init_zero(base,count) \ |
1998 | #define array_needsize_zerofill(base,offset,count) \ |
1964 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1999 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
1965 | |
2000 | |
1966 | #define array_needsize(type,base,cur,cnt,init) \ |
2001 | #define array_needsize(type,base,cur,cnt,init) \ |
1967 | if (expect_false ((cnt) > (cur))) \ |
2002 | if (expect_false ((cnt) > (cur))) \ |
1968 | { \ |
2003 | { \ |
1969 | ecb_unused int ocur_ = (cur); \ |
2004 | ecb_unused int ocur_ = (cur); \ |
1970 | (base) = (type *)array_realloc \ |
2005 | (base) = (type *)array_realloc \ |
1971 | (sizeof (type), (base), &(cur), (cnt)); \ |
2006 | (sizeof (type), (base), &(cur), (cnt)); \ |
1972 | init ((base) + (ocur_), (cur) - ocur_); \ |
2007 | init ((base), ocur_, ((cur) - ocur_)); \ |
1973 | } |
2008 | } |
1974 | |
2009 | |
1975 | #if 0 |
2010 | #if 0 |
1976 | #define array_slim(type,stem) \ |
2011 | #define array_slim(type,stem) \ |
1977 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
2012 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
… | |
… | |
1994 | { |
2029 | { |
1995 | } |
2030 | } |
1996 | |
2031 | |
1997 | noinline |
2032 | noinline |
1998 | void |
2033 | void |
1999 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2034 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
2000 | { |
2035 | { |
2001 | W w_ = (W)w; |
2036 | W w_ = (W)w; |
2002 | int pri = ABSPRI (w_); |
2037 | int pri = ABSPRI (w_); |
2003 | |
2038 | |
2004 | if (expect_false (w_->pending)) |
2039 | if (expect_false (w_->pending)) |
2005 | pendings [pri][w_->pending - 1].events |= revents; |
2040 | pendings [pri][w_->pending - 1].events |= revents; |
2006 | else |
2041 | else |
2007 | { |
2042 | { |
2008 | w_->pending = ++pendingcnt [pri]; |
2043 | w_->pending = ++pendingcnt [pri]; |
2009 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2044 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
2010 | pendings [pri][w_->pending - 1].w = w_; |
2045 | pendings [pri][w_->pending - 1].w = w_; |
2011 | pendings [pri][w_->pending - 1].events = revents; |
2046 | pendings [pri][w_->pending - 1].events = revents; |
2012 | } |
2047 | } |
2013 | |
2048 | |
2014 | pendingpri = NUMPRI - 1; |
2049 | pendingpri = NUMPRI - 1; |
2015 | } |
2050 | } |
2016 | |
2051 | |
2017 | inline_speed void |
2052 | inline_speed void |
2018 | feed_reverse (EV_P_ W w) |
2053 | feed_reverse (EV_P_ W w) |
2019 | { |
2054 | { |
2020 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2055 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2021 | rfeeds [rfeedcnt++] = w; |
2056 | rfeeds [rfeedcnt++] = w; |
2022 | } |
2057 | } |
2023 | |
2058 | |
2024 | inline_size void |
2059 | inline_size void |
2025 | feed_reverse_done (EV_P_ int revents) |
2060 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2065 | if (expect_true (!anfd->reify)) |
2100 | if (expect_true (!anfd->reify)) |
2066 | fd_event_nocheck (EV_A_ fd, revents); |
2101 | fd_event_nocheck (EV_A_ fd, revents); |
2067 | } |
2102 | } |
2068 | |
2103 | |
2069 | void |
2104 | void |
2070 | 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 |
2071 | { |
2106 | { |
2072 | if (fd >= 0 && fd < anfdmax) |
2107 | if (fd >= 0 && fd < anfdmax) |
2073 | fd_event_nocheck (EV_A_ fd, revents); |
2108 | fd_event_nocheck (EV_A_ fd, revents); |
2074 | } |
2109 | } |
2075 | |
2110 | |
… | |
… | |
2143 | anfds [fd].reify |= flags; |
2178 | anfds [fd].reify |= flags; |
2144 | |
2179 | |
2145 | if (expect_true (!reify)) |
2180 | if (expect_true (!reify)) |
2146 | { |
2181 | { |
2147 | ++fdchangecnt; |
2182 | ++fdchangecnt; |
2148 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2183 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2149 | fdchanges [fdchangecnt - 1] = fd; |
2184 | fdchanges [fdchangecnt - 1] = fd; |
2150 | } |
2185 | } |
2151 | } |
2186 | } |
2152 | |
2187 | |
2153 | /* 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 */ |
… | |
… | |
2475 | #endif |
2510 | #endif |
2476 | { |
2511 | { |
2477 | #ifdef _WIN32 |
2512 | #ifdef _WIN32 |
2478 | WSABUF buf; |
2513 | WSABUF buf; |
2479 | DWORD sent; |
2514 | DWORD sent; |
2480 | buf.buf = &buf; |
2515 | buf.buf = (char *)&buf; |
2481 | buf.len = 1; |
2516 | buf.len = 1; |
2482 | 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); |
2483 | #else |
2518 | #else |
2484 | write (evpipe [1], &(evpipe [1]), 1); |
2519 | write (evpipe [1], &(evpipe [1]), 1); |
2485 | #endif |
2520 | #endif |
… | |
… | |
2557 | } |
2592 | } |
2558 | |
2593 | |
2559 | /*****************************************************************************/ |
2594 | /*****************************************************************************/ |
2560 | |
2595 | |
2561 | void |
2596 | void |
2562 | ev_feed_signal (int signum) EV_THROW |
2597 | ev_feed_signal (int signum) EV_NOEXCEPT |
2563 | { |
2598 | { |
2564 | #if EV_MULTIPLICITY |
2599 | #if EV_MULTIPLICITY |
2565 | EV_P; |
2600 | EV_P; |
2566 | ECB_MEMORY_FENCE_ACQUIRE; |
2601 | ECB_MEMORY_FENCE_ACQUIRE; |
2567 | EV_A = signals [signum - 1].loop; |
2602 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2584 | ev_feed_signal (signum); |
2619 | ev_feed_signal (signum); |
2585 | } |
2620 | } |
2586 | |
2621 | |
2587 | noinline |
2622 | noinline |
2588 | void |
2623 | void |
2589 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2624 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2590 | { |
2625 | { |
2591 | WL w; |
2626 | WL w; |
2592 | |
2627 | |
2593 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2628 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2594 | return; |
2629 | return; |
… | |
… | |
2703 | # include "ev_kqueue.c" |
2738 | # include "ev_kqueue.c" |
2704 | #endif |
2739 | #endif |
2705 | #if EV_USE_EPOLL |
2740 | #if EV_USE_EPOLL |
2706 | # include "ev_epoll.c" |
2741 | # include "ev_epoll.c" |
2707 | #endif |
2742 | #endif |
|
|
2743 | #if EV_USE_LINUXAIO |
|
|
2744 | # include "ev_linuxaio.c" |
|
|
2745 | #endif |
2708 | #if EV_USE_POLL |
2746 | #if EV_USE_POLL |
2709 | # include "ev_poll.c" |
2747 | # include "ev_poll.c" |
2710 | #endif |
2748 | #endif |
2711 | #if EV_USE_SELECT |
2749 | #if EV_USE_SELECT |
2712 | # include "ev_select.c" |
2750 | # include "ev_select.c" |
2713 | #endif |
2751 | #endif |
2714 | |
2752 | |
2715 | ecb_cold int |
2753 | ecb_cold int |
2716 | ev_version_major (void) EV_THROW |
2754 | ev_version_major (void) EV_NOEXCEPT |
2717 | { |
2755 | { |
2718 | return EV_VERSION_MAJOR; |
2756 | return EV_VERSION_MAJOR; |
2719 | } |
2757 | } |
2720 | |
2758 | |
2721 | ecb_cold int |
2759 | ecb_cold int |
2722 | ev_version_minor (void) EV_THROW |
2760 | ev_version_minor (void) EV_NOEXCEPT |
2723 | { |
2761 | { |
2724 | return EV_VERSION_MINOR; |
2762 | return EV_VERSION_MINOR; |
2725 | } |
2763 | } |
2726 | |
2764 | |
2727 | /* 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 */ |
… | |
… | |
2736 | #endif |
2774 | #endif |
2737 | } |
2775 | } |
2738 | |
2776 | |
2739 | ecb_cold |
2777 | ecb_cold |
2740 | unsigned int |
2778 | unsigned int |
2741 | ev_supported_backends (void) EV_THROW |
2779 | ev_supported_backends (void) EV_NOEXCEPT |
2742 | { |
2780 | { |
2743 | unsigned int flags = 0; |
2781 | unsigned int flags = 0; |
2744 | |
2782 | |
2745 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2783 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2746 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2784 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2747 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2785 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2786 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2748 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2787 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2749 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2788 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2750 | |
2789 | |
2751 | return flags; |
2790 | return flags; |
2752 | } |
2791 | } |
2753 | |
2792 | |
2754 | ecb_cold |
2793 | ecb_cold |
2755 | unsigned int |
2794 | unsigned int |
2756 | ev_recommended_backends (void) EV_THROW |
2795 | ev_recommended_backends (void) EV_NOEXCEPT |
2757 | { |
2796 | { |
2758 | unsigned int flags = ev_supported_backends (); |
2797 | unsigned int flags = ev_supported_backends (); |
2759 | |
2798 | |
2760 | #ifndef __NetBSD__ |
2799 | #ifndef __NetBSD__ |
2761 | /* kqueue is borked on everything but netbsd apparently */ |
2800 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2769 | #endif |
2808 | #endif |
2770 | #ifdef __FreeBSD__ |
2809 | #ifdef __FreeBSD__ |
2771 | 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) */ |
2772 | #endif |
2811 | #endif |
2773 | |
2812 | |
|
|
2813 | /* TODO: linuxaio is very experimental */ |
|
|
2814 | #if !EV_RECOMMEND_LINUXAIO |
|
|
2815 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2816 | #endif |
|
|
2817 | |
2774 | return flags; |
2818 | return flags; |
2775 | } |
2819 | } |
2776 | |
2820 | |
2777 | ecb_cold |
2821 | ecb_cold |
2778 | unsigned int |
2822 | unsigned int |
2779 | ev_embeddable_backends (void) EV_THROW |
2823 | ev_embeddable_backends (void) EV_NOEXCEPT |
2780 | { |
2824 | { |
2781 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2825 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2782 | |
2826 | |
2783 | /* 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 */ |
2784 | 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 */ |
… | |
… | |
2786 | |
2830 | |
2787 | return flags; |
2831 | return flags; |
2788 | } |
2832 | } |
2789 | |
2833 | |
2790 | unsigned int |
2834 | unsigned int |
2791 | ev_backend (EV_P) EV_THROW |
2835 | ev_backend (EV_P) EV_NOEXCEPT |
2792 | { |
2836 | { |
2793 | return backend; |
2837 | return backend; |
2794 | } |
2838 | } |
2795 | |
2839 | |
2796 | #if EV_FEATURE_API |
2840 | #if EV_FEATURE_API |
2797 | unsigned int |
2841 | unsigned int |
2798 | ev_iteration (EV_P) EV_THROW |
2842 | ev_iteration (EV_P) EV_NOEXCEPT |
2799 | { |
2843 | { |
2800 | return loop_count; |
2844 | return loop_count; |
2801 | } |
2845 | } |
2802 | |
2846 | |
2803 | unsigned int |
2847 | unsigned int |
2804 | ev_depth (EV_P) EV_THROW |
2848 | ev_depth (EV_P) EV_NOEXCEPT |
2805 | { |
2849 | { |
2806 | return loop_depth; |
2850 | return loop_depth; |
2807 | } |
2851 | } |
2808 | |
2852 | |
2809 | void |
2853 | void |
2810 | 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 |
2811 | { |
2855 | { |
2812 | io_blocktime = interval; |
2856 | io_blocktime = interval; |
2813 | } |
2857 | } |
2814 | |
2858 | |
2815 | void |
2859 | void |
2816 | 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 |
2817 | { |
2861 | { |
2818 | timeout_blocktime = interval; |
2862 | timeout_blocktime = interval; |
2819 | } |
2863 | } |
2820 | |
2864 | |
2821 | void |
2865 | void |
2822 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2866 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2823 | { |
2867 | { |
2824 | userdata = data; |
2868 | userdata = data; |
2825 | } |
2869 | } |
2826 | |
2870 | |
2827 | void * |
2871 | void * |
2828 | ev_userdata (EV_P) EV_THROW |
2872 | ev_userdata (EV_P) EV_NOEXCEPT |
2829 | { |
2873 | { |
2830 | return userdata; |
2874 | return userdata; |
2831 | } |
2875 | } |
2832 | |
2876 | |
2833 | void |
2877 | void |
2834 | 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 |
2835 | { |
2879 | { |
2836 | invoke_cb = invoke_pending_cb; |
2880 | invoke_cb = invoke_pending_cb; |
2837 | } |
2881 | } |
2838 | |
2882 | |
2839 | void |
2883 | void |
2840 | 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 |
2841 | { |
2885 | { |
2842 | release_cb = release; |
2886 | release_cb = release; |
2843 | acquire_cb = acquire; |
2887 | acquire_cb = acquire; |
2844 | } |
2888 | } |
2845 | #endif |
2889 | #endif |
2846 | |
2890 | |
2847 | /* initialise a loop structure, must be zero-initialised */ |
2891 | /* initialise a loop structure, must be zero-initialised */ |
2848 | noinline ecb_cold |
2892 | noinline ecb_cold |
2849 | static void |
2893 | static void |
2850 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2894 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2851 | { |
2895 | { |
2852 | if (!backend) |
2896 | if (!backend) |
2853 | { |
2897 | { |
2854 | origflags = flags; |
2898 | origflags = flags; |
2855 | |
2899 | |
… | |
… | |
2913 | |
2957 | |
2914 | if (!(flags & EVBACKEND_MASK)) |
2958 | if (!(flags & EVBACKEND_MASK)) |
2915 | flags |= ev_recommended_backends (); |
2959 | flags |= ev_recommended_backends (); |
2916 | |
2960 | |
2917 | #if EV_USE_IOCP |
2961 | #if EV_USE_IOCP |
2918 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2962 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2919 | #endif |
2963 | #endif |
2920 | #if EV_USE_PORT |
2964 | #if EV_USE_PORT |
2921 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2965 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2922 | #endif |
2966 | #endif |
2923 | #if EV_USE_KQUEUE |
2967 | #if EV_USE_KQUEUE |
2924 | 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); |
2925 | #endif |
2972 | #endif |
2926 | #if EV_USE_EPOLL |
2973 | #if EV_USE_EPOLL |
2927 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2974 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2928 | #endif |
2975 | #endif |
2929 | #if EV_USE_POLL |
2976 | #if EV_USE_POLL |
2930 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2977 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2931 | #endif |
2978 | #endif |
2932 | #if EV_USE_SELECT |
2979 | #if EV_USE_SELECT |
2933 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2980 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2934 | #endif |
2981 | #endif |
2935 | |
2982 | |
2936 | ev_prepare_init (&pending_w, pendingcb); |
2983 | ev_prepare_init (&pending_w, pendingcb); |
2937 | |
2984 | |
2938 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2985 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2993 | |
3040 | |
2994 | if (backend_fd >= 0) |
3041 | if (backend_fd >= 0) |
2995 | close (backend_fd); |
3042 | close (backend_fd); |
2996 | |
3043 | |
2997 | #if EV_USE_IOCP |
3044 | #if EV_USE_IOCP |
2998 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3045 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2999 | #endif |
3046 | #endif |
3000 | #if EV_USE_PORT |
3047 | #if EV_USE_PORT |
3001 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3048 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3002 | #endif |
3049 | #endif |
3003 | #if EV_USE_KQUEUE |
3050 | #if EV_USE_KQUEUE |
3004 | 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); |
3005 | #endif |
3055 | #endif |
3006 | #if EV_USE_EPOLL |
3056 | #if EV_USE_EPOLL |
3007 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3057 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3008 | #endif |
3058 | #endif |
3009 | #if EV_USE_POLL |
3059 | #if EV_USE_POLL |
3010 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3060 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3011 | #endif |
3061 | #endif |
3012 | #if EV_USE_SELECT |
3062 | #if EV_USE_SELECT |
3013 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3063 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
3014 | #endif |
3064 | #endif |
3015 | |
3065 | |
3016 | for (i = NUMPRI; i--; ) |
3066 | for (i = NUMPRI; i--; ) |
3017 | { |
3067 | { |
3018 | array_free (pending, [i]); |
3068 | array_free (pending, [i]); |
… | |
… | |
3060 | |
3110 | |
3061 | inline_size void |
3111 | inline_size void |
3062 | loop_fork (EV_P) |
3112 | loop_fork (EV_P) |
3063 | { |
3113 | { |
3064 | #if EV_USE_PORT |
3114 | #if EV_USE_PORT |
3065 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3115 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3066 | #endif |
3116 | #endif |
3067 | #if EV_USE_KQUEUE |
3117 | #if EV_USE_KQUEUE |
3068 | 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); |
3069 | #endif |
3122 | #endif |
3070 | #if EV_USE_EPOLL |
3123 | #if EV_USE_EPOLL |
3071 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3124 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3072 | #endif |
3125 | #endif |
3073 | #if EV_USE_INOTIFY |
3126 | #if EV_USE_INOTIFY |
3074 | infy_fork (EV_A); |
3127 | infy_fork (EV_A); |
3075 | #endif |
3128 | #endif |
3076 | |
3129 | |
… | |
… | |
3096 | |
3149 | |
3097 | #if EV_MULTIPLICITY |
3150 | #if EV_MULTIPLICITY |
3098 | |
3151 | |
3099 | ecb_cold |
3152 | ecb_cold |
3100 | struct ev_loop * |
3153 | struct ev_loop * |
3101 | ev_loop_new (unsigned int flags) EV_THROW |
3154 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3102 | { |
3155 | { |
3103 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3156 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3104 | |
3157 | |
3105 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3158 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3106 | loop_init (EV_A_ flags); |
3159 | loop_init (EV_A_ flags); |
… | |
… | |
3153 | } |
3206 | } |
3154 | #endif |
3207 | #endif |
3155 | |
3208 | |
3156 | #if EV_FEATURE_API |
3209 | #if EV_FEATURE_API |
3157 | void ecb_cold |
3210 | void ecb_cold |
3158 | ev_verify (EV_P) EV_THROW |
3211 | ev_verify (EV_P) EV_NOEXCEPT |
3159 | { |
3212 | { |
3160 | #if EV_VERIFY |
3213 | #if EV_VERIFY |
3161 | int i; |
3214 | int i; |
3162 | WL w, w2; |
3215 | WL w, w2; |
3163 | |
3216 | |
… | |
… | |
3244 | ecb_cold |
3297 | ecb_cold |
3245 | struct ev_loop * |
3298 | struct ev_loop * |
3246 | #else |
3299 | #else |
3247 | int |
3300 | int |
3248 | #endif |
3301 | #endif |
3249 | ev_default_loop (unsigned int flags) EV_THROW |
3302 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3250 | { |
3303 | { |
3251 | if (!ev_default_loop_ptr) |
3304 | if (!ev_default_loop_ptr) |
3252 | { |
3305 | { |
3253 | #if EV_MULTIPLICITY |
3306 | #if EV_MULTIPLICITY |
3254 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3307 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3273 | |
3326 | |
3274 | return ev_default_loop_ptr; |
3327 | return ev_default_loop_ptr; |
3275 | } |
3328 | } |
3276 | |
3329 | |
3277 | void |
3330 | void |
3278 | ev_loop_fork (EV_P) EV_THROW |
3331 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3279 | { |
3332 | { |
3280 | postfork = 1; |
3333 | postfork = 1; |
3281 | } |
3334 | } |
3282 | |
3335 | |
3283 | /*****************************************************************************/ |
3336 | /*****************************************************************************/ |
… | |
… | |
3287 | { |
3340 | { |
3288 | EV_CB_INVOKE ((W)w, revents); |
3341 | EV_CB_INVOKE ((W)w, revents); |
3289 | } |
3342 | } |
3290 | |
3343 | |
3291 | unsigned int |
3344 | unsigned int |
3292 | ev_pending_count (EV_P) EV_THROW |
3345 | ev_pending_count (EV_P) EV_NOEXCEPT |
3293 | { |
3346 | { |
3294 | int pri; |
3347 | int pri; |
3295 | unsigned int count = 0; |
3348 | unsigned int count = 0; |
3296 | |
3349 | |
3297 | for (pri = NUMPRI; pri--; ) |
3350 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
3304 | void |
3357 | void |
3305 | ev_invoke_pending (EV_P) |
3358 | ev_invoke_pending (EV_P) |
3306 | { |
3359 | { |
3307 | pendingpri = NUMPRI; |
3360 | pendingpri = NUMPRI; |
3308 | |
3361 | |
3309 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3362 | do |
3310 | { |
3363 | { |
3311 | --pendingpri; |
3364 | --pendingpri; |
3312 | |
3365 | |
|
|
3366 | /* pendingpri possibly gets modified in the inner loop */ |
3313 | while (pendingcnt [pendingpri]) |
3367 | while (pendingcnt [pendingpri]) |
3314 | { |
3368 | { |
3315 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3369 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3316 | |
3370 | |
3317 | p->w->pending = 0; |
3371 | p->w->pending = 0; |
3318 | EV_CB_INVOKE (p->w, p->events); |
3372 | EV_CB_INVOKE (p->w, p->events); |
3319 | EV_FREQUENT_CHECK; |
3373 | EV_FREQUENT_CHECK; |
3320 | } |
3374 | } |
3321 | } |
3375 | } |
|
|
3376 | while (pendingpri); |
3322 | } |
3377 | } |
3323 | |
3378 | |
3324 | #if EV_IDLE_ENABLE |
3379 | #if EV_IDLE_ENABLE |
3325 | /* make idle watchers pending. this handles the "call-idle */ |
3380 | /* make idle watchers pending. this handles the "call-idle */ |
3326 | /* only when higher priorities are idle" logic */ |
3381 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3735 | |
3790 | |
3736 | return activecnt; |
3791 | return activecnt; |
3737 | } |
3792 | } |
3738 | |
3793 | |
3739 | void |
3794 | void |
3740 | ev_break (EV_P_ int how) EV_THROW |
3795 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3741 | { |
3796 | { |
3742 | loop_done = how; |
3797 | loop_done = how; |
3743 | } |
3798 | } |
3744 | |
3799 | |
3745 | void |
3800 | void |
3746 | ev_ref (EV_P) EV_THROW |
3801 | ev_ref (EV_P) EV_NOEXCEPT |
3747 | { |
3802 | { |
3748 | ++activecnt; |
3803 | ++activecnt; |
3749 | } |
3804 | } |
3750 | |
3805 | |
3751 | void |
3806 | void |
3752 | ev_unref (EV_P) EV_THROW |
3807 | ev_unref (EV_P) EV_NOEXCEPT |
3753 | { |
3808 | { |
3754 | --activecnt; |
3809 | --activecnt; |
3755 | } |
3810 | } |
3756 | |
3811 | |
3757 | void |
3812 | void |
3758 | ev_now_update (EV_P) EV_THROW |
3813 | ev_now_update (EV_P) EV_NOEXCEPT |
3759 | { |
3814 | { |
3760 | time_update (EV_A_ 1e100); |
3815 | time_update (EV_A_ 1e100); |
3761 | } |
3816 | } |
3762 | |
3817 | |
3763 | void |
3818 | void |
3764 | ev_suspend (EV_P) EV_THROW |
3819 | ev_suspend (EV_P) EV_NOEXCEPT |
3765 | { |
3820 | { |
3766 | ev_now_update (EV_A); |
3821 | ev_now_update (EV_A); |
3767 | } |
3822 | } |
3768 | |
3823 | |
3769 | void |
3824 | void |
3770 | ev_resume (EV_P) EV_THROW |
3825 | ev_resume (EV_P) EV_NOEXCEPT |
3771 | { |
3826 | { |
3772 | ev_tstamp mn_prev = mn_now; |
3827 | ev_tstamp mn_prev = mn_now; |
3773 | |
3828 | |
3774 | ev_now_update (EV_A); |
3829 | ev_now_update (EV_A); |
3775 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3830 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3814 | w->pending = 0; |
3869 | w->pending = 0; |
3815 | } |
3870 | } |
3816 | } |
3871 | } |
3817 | |
3872 | |
3818 | int |
3873 | int |
3819 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3874 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3820 | { |
3875 | { |
3821 | W w_ = (W)w; |
3876 | W w_ = (W)w; |
3822 | int pending = w_->pending; |
3877 | int pending = w_->pending; |
3823 | |
3878 | |
3824 | if (expect_true (pending)) |
3879 | if (expect_true (pending)) |
… | |
… | |
3858 | |
3913 | |
3859 | /*****************************************************************************/ |
3914 | /*****************************************************************************/ |
3860 | |
3915 | |
3861 | noinline |
3916 | noinline |
3862 | void |
3917 | void |
3863 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3918 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3864 | { |
3919 | { |
3865 | int fd = w->fd; |
3920 | int fd = w->fd; |
3866 | |
3921 | |
3867 | if (expect_false (ev_is_active (w))) |
3922 | if (expect_false (ev_is_active (w))) |
3868 | return; |
3923 | return; |
… | |
… | |
3871 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3926 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3872 | |
3927 | |
3873 | EV_FREQUENT_CHECK; |
3928 | EV_FREQUENT_CHECK; |
3874 | |
3929 | |
3875 | ev_start (EV_A_ (W)w, 1); |
3930 | ev_start (EV_A_ (W)w, 1); |
3876 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3931 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3877 | wlist_add (&anfds[fd].head, (WL)w); |
3932 | wlist_add (&anfds[fd].head, (WL)w); |
3878 | |
3933 | |
3879 | /* common bug, apparently */ |
3934 | /* common bug, apparently */ |
3880 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3935 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3881 | |
3936 | |
… | |
… | |
3885 | EV_FREQUENT_CHECK; |
3940 | EV_FREQUENT_CHECK; |
3886 | } |
3941 | } |
3887 | |
3942 | |
3888 | noinline |
3943 | noinline |
3889 | void |
3944 | void |
3890 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3945 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3891 | { |
3946 | { |
3892 | clear_pending (EV_A_ (W)w); |
3947 | clear_pending (EV_A_ (W)w); |
3893 | if (expect_false (!ev_is_active (w))) |
3948 | if (expect_false (!ev_is_active (w))) |
3894 | return; |
3949 | return; |
3895 | |
3950 | |
… | |
… | |
3905 | EV_FREQUENT_CHECK; |
3960 | EV_FREQUENT_CHECK; |
3906 | } |
3961 | } |
3907 | |
3962 | |
3908 | noinline |
3963 | noinline |
3909 | void |
3964 | void |
3910 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3965 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3911 | { |
3966 | { |
3912 | if (expect_false (ev_is_active (w))) |
3967 | if (expect_false (ev_is_active (w))) |
3913 | return; |
3968 | return; |
3914 | |
3969 | |
3915 | ev_at (w) += mn_now; |
3970 | ev_at (w) += mn_now; |
… | |
… | |
3918 | |
3973 | |
3919 | EV_FREQUENT_CHECK; |
3974 | EV_FREQUENT_CHECK; |
3920 | |
3975 | |
3921 | ++timercnt; |
3976 | ++timercnt; |
3922 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3977 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3923 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3978 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3924 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3979 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3925 | ANHE_at_cache (timers [ev_active (w)]); |
3980 | ANHE_at_cache (timers [ev_active (w)]); |
3926 | upheap (timers, ev_active (w)); |
3981 | upheap (timers, ev_active (w)); |
3927 | |
3982 | |
3928 | EV_FREQUENT_CHECK; |
3983 | EV_FREQUENT_CHECK; |
… | |
… | |
3930 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3985 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3931 | } |
3986 | } |
3932 | |
3987 | |
3933 | noinline |
3988 | noinline |
3934 | void |
3989 | void |
3935 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3990 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3936 | { |
3991 | { |
3937 | clear_pending (EV_A_ (W)w); |
3992 | clear_pending (EV_A_ (W)w); |
3938 | if (expect_false (!ev_is_active (w))) |
3993 | if (expect_false (!ev_is_active (w))) |
3939 | return; |
3994 | return; |
3940 | |
3995 | |
… | |
… | |
3961 | EV_FREQUENT_CHECK; |
4016 | EV_FREQUENT_CHECK; |
3962 | } |
4017 | } |
3963 | |
4018 | |
3964 | noinline |
4019 | noinline |
3965 | void |
4020 | void |
3966 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4021 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3967 | { |
4022 | { |
3968 | EV_FREQUENT_CHECK; |
4023 | EV_FREQUENT_CHECK; |
3969 | |
4024 | |
3970 | clear_pending (EV_A_ (W)w); |
4025 | clear_pending (EV_A_ (W)w); |
3971 | |
4026 | |
… | |
… | |
3988 | |
4043 | |
3989 | EV_FREQUENT_CHECK; |
4044 | EV_FREQUENT_CHECK; |
3990 | } |
4045 | } |
3991 | |
4046 | |
3992 | ev_tstamp |
4047 | ev_tstamp |
3993 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4048 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3994 | { |
4049 | { |
3995 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4050 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3996 | } |
4051 | } |
3997 | |
4052 | |
3998 | #if EV_PERIODIC_ENABLE |
4053 | #if EV_PERIODIC_ENABLE |
3999 | noinline |
4054 | noinline |
4000 | void |
4055 | void |
4001 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4056 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4002 | { |
4057 | { |
4003 | if (expect_false (ev_is_active (w))) |
4058 | if (expect_false (ev_is_active (w))) |
4004 | return; |
4059 | return; |
4005 | |
4060 | |
4006 | if (w->reschedule_cb) |
4061 | if (w->reschedule_cb) |
… | |
… | |
4015 | |
4070 | |
4016 | EV_FREQUENT_CHECK; |
4071 | EV_FREQUENT_CHECK; |
4017 | |
4072 | |
4018 | ++periodiccnt; |
4073 | ++periodiccnt; |
4019 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4074 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4020 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4075 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4021 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4076 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4022 | ANHE_at_cache (periodics [ev_active (w)]); |
4077 | ANHE_at_cache (periodics [ev_active (w)]); |
4023 | upheap (periodics, ev_active (w)); |
4078 | upheap (periodics, ev_active (w)); |
4024 | |
4079 | |
4025 | EV_FREQUENT_CHECK; |
4080 | EV_FREQUENT_CHECK; |
… | |
… | |
4027 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4082 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4028 | } |
4083 | } |
4029 | |
4084 | |
4030 | noinline |
4085 | noinline |
4031 | void |
4086 | void |
4032 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4087 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4033 | { |
4088 | { |
4034 | clear_pending (EV_A_ (W)w); |
4089 | clear_pending (EV_A_ (W)w); |
4035 | if (expect_false (!ev_is_active (w))) |
4090 | if (expect_false (!ev_is_active (w))) |
4036 | return; |
4091 | return; |
4037 | |
4092 | |
… | |
… | |
4056 | EV_FREQUENT_CHECK; |
4111 | EV_FREQUENT_CHECK; |
4057 | } |
4112 | } |
4058 | |
4113 | |
4059 | noinline |
4114 | noinline |
4060 | void |
4115 | void |
4061 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4116 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4062 | { |
4117 | { |
4063 | /* TODO: use adjustheap and recalculation */ |
4118 | /* TODO: use adjustheap and recalculation */ |
4064 | ev_periodic_stop (EV_A_ w); |
4119 | ev_periodic_stop (EV_A_ w); |
4065 | ev_periodic_start (EV_A_ w); |
4120 | ev_periodic_start (EV_A_ w); |
4066 | } |
4121 | } |
… | |
… | |
4072 | |
4127 | |
4073 | #if EV_SIGNAL_ENABLE |
4128 | #if EV_SIGNAL_ENABLE |
4074 | |
4129 | |
4075 | noinline |
4130 | noinline |
4076 | void |
4131 | void |
4077 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4132 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4078 | { |
4133 | { |
4079 | if (expect_false (ev_is_active (w))) |
4134 | if (expect_false (ev_is_active (w))) |
4080 | return; |
4135 | return; |
4081 | |
4136 | |
4082 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4137 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4155 | EV_FREQUENT_CHECK; |
4210 | EV_FREQUENT_CHECK; |
4156 | } |
4211 | } |
4157 | |
4212 | |
4158 | noinline |
4213 | noinline |
4159 | void |
4214 | void |
4160 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4215 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4161 | { |
4216 | { |
4162 | clear_pending (EV_A_ (W)w); |
4217 | clear_pending (EV_A_ (W)w); |
4163 | if (expect_false (!ev_is_active (w))) |
4218 | if (expect_false (!ev_is_active (w))) |
4164 | return; |
4219 | return; |
4165 | |
4220 | |
… | |
… | |
4196 | #endif |
4251 | #endif |
4197 | |
4252 | |
4198 | #if EV_CHILD_ENABLE |
4253 | #if EV_CHILD_ENABLE |
4199 | |
4254 | |
4200 | void |
4255 | void |
4201 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4256 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4202 | { |
4257 | { |
4203 | #if EV_MULTIPLICITY |
4258 | #if EV_MULTIPLICITY |
4204 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4259 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4205 | #endif |
4260 | #endif |
4206 | if (expect_false (ev_is_active (w))) |
4261 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4213 | |
4268 | |
4214 | EV_FREQUENT_CHECK; |
4269 | EV_FREQUENT_CHECK; |
4215 | } |
4270 | } |
4216 | |
4271 | |
4217 | void |
4272 | void |
4218 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4273 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4219 | { |
4274 | { |
4220 | clear_pending (EV_A_ (W)w); |
4275 | clear_pending (EV_A_ (W)w); |
4221 | if (expect_false (!ev_is_active (w))) |
4276 | if (expect_false (!ev_is_active (w))) |
4222 | return; |
4277 | return; |
4223 | |
4278 | |
… | |
… | |
4488 | #else |
4543 | #else |
4489 | # define EV_LSTAT(p,b) lstat (p, b) |
4544 | # define EV_LSTAT(p,b) lstat (p, b) |
4490 | #endif |
4545 | #endif |
4491 | |
4546 | |
4492 | void |
4547 | void |
4493 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4548 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4494 | { |
4549 | { |
4495 | if (lstat (w->path, &w->attr) < 0) |
4550 | if (lstat (w->path, &w->attr) < 0) |
4496 | w->attr.st_nlink = 0; |
4551 | w->attr.st_nlink = 0; |
4497 | else if (!w->attr.st_nlink) |
4552 | else if (!w->attr.st_nlink) |
4498 | w->attr.st_nlink = 1; |
4553 | w->attr.st_nlink = 1; |
… | |
… | |
4538 | ev_feed_event (EV_A_ w, EV_STAT); |
4593 | ev_feed_event (EV_A_ w, EV_STAT); |
4539 | } |
4594 | } |
4540 | } |
4595 | } |
4541 | |
4596 | |
4542 | void |
4597 | void |
4543 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4598 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4544 | { |
4599 | { |
4545 | if (expect_false (ev_is_active (w))) |
4600 | if (expect_false (ev_is_active (w))) |
4546 | return; |
4601 | return; |
4547 | |
4602 | |
4548 | ev_stat_stat (EV_A_ w); |
4603 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4569 | |
4624 | |
4570 | EV_FREQUENT_CHECK; |
4625 | EV_FREQUENT_CHECK; |
4571 | } |
4626 | } |
4572 | |
4627 | |
4573 | void |
4628 | void |
4574 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4629 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4575 | { |
4630 | { |
4576 | clear_pending (EV_A_ (W)w); |
4631 | clear_pending (EV_A_ (W)w); |
4577 | if (expect_false (!ev_is_active (w))) |
4632 | if (expect_false (!ev_is_active (w))) |
4578 | return; |
4633 | return; |
4579 | |
4634 | |
… | |
… | |
4595 | } |
4650 | } |
4596 | #endif |
4651 | #endif |
4597 | |
4652 | |
4598 | #if EV_IDLE_ENABLE |
4653 | #if EV_IDLE_ENABLE |
4599 | void |
4654 | void |
4600 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4655 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4601 | { |
4656 | { |
4602 | if (expect_false (ev_is_active (w))) |
4657 | if (expect_false (ev_is_active (w))) |
4603 | return; |
4658 | return; |
4604 | |
4659 | |
4605 | pri_adjust (EV_A_ (W)w); |
4660 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4610 | int active = ++idlecnt [ABSPRI (w)]; |
4665 | int active = ++idlecnt [ABSPRI (w)]; |
4611 | |
4666 | |
4612 | ++idleall; |
4667 | ++idleall; |
4613 | ev_start (EV_A_ (W)w, active); |
4668 | ev_start (EV_A_ (W)w, active); |
4614 | |
4669 | |
4615 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4670 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4616 | idles [ABSPRI (w)][active - 1] = w; |
4671 | idles [ABSPRI (w)][active - 1] = w; |
4617 | } |
4672 | } |
4618 | |
4673 | |
4619 | EV_FREQUENT_CHECK; |
4674 | EV_FREQUENT_CHECK; |
4620 | } |
4675 | } |
4621 | |
4676 | |
4622 | void |
4677 | void |
4623 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4678 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4624 | { |
4679 | { |
4625 | clear_pending (EV_A_ (W)w); |
4680 | clear_pending (EV_A_ (W)w); |
4626 | if (expect_false (!ev_is_active (w))) |
4681 | if (expect_false (!ev_is_active (w))) |
4627 | return; |
4682 | return; |
4628 | |
4683 | |
… | |
… | |
4642 | } |
4697 | } |
4643 | #endif |
4698 | #endif |
4644 | |
4699 | |
4645 | #if EV_PREPARE_ENABLE |
4700 | #if EV_PREPARE_ENABLE |
4646 | void |
4701 | void |
4647 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4702 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4648 | { |
4703 | { |
4649 | if (expect_false (ev_is_active (w))) |
4704 | if (expect_false (ev_is_active (w))) |
4650 | return; |
4705 | return; |
4651 | |
4706 | |
4652 | EV_FREQUENT_CHECK; |
4707 | EV_FREQUENT_CHECK; |
4653 | |
4708 | |
4654 | ev_start (EV_A_ (W)w, ++preparecnt); |
4709 | ev_start (EV_A_ (W)w, ++preparecnt); |
4655 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4710 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4656 | prepares [preparecnt - 1] = w; |
4711 | prepares [preparecnt - 1] = w; |
4657 | |
4712 | |
4658 | EV_FREQUENT_CHECK; |
4713 | EV_FREQUENT_CHECK; |
4659 | } |
4714 | } |
4660 | |
4715 | |
4661 | void |
4716 | void |
4662 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4717 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4663 | { |
4718 | { |
4664 | clear_pending (EV_A_ (W)w); |
4719 | clear_pending (EV_A_ (W)w); |
4665 | if (expect_false (!ev_is_active (w))) |
4720 | if (expect_false (!ev_is_active (w))) |
4666 | return; |
4721 | return; |
4667 | |
4722 | |
… | |
… | |
4680 | } |
4735 | } |
4681 | #endif |
4736 | #endif |
4682 | |
4737 | |
4683 | #if EV_CHECK_ENABLE |
4738 | #if EV_CHECK_ENABLE |
4684 | void |
4739 | void |
4685 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4740 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4686 | { |
4741 | { |
4687 | if (expect_false (ev_is_active (w))) |
4742 | if (expect_false (ev_is_active (w))) |
4688 | return; |
4743 | return; |
4689 | |
4744 | |
4690 | EV_FREQUENT_CHECK; |
4745 | EV_FREQUENT_CHECK; |
4691 | |
4746 | |
4692 | ev_start (EV_A_ (W)w, ++checkcnt); |
4747 | ev_start (EV_A_ (W)w, ++checkcnt); |
4693 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4748 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4694 | checks [checkcnt - 1] = w; |
4749 | checks [checkcnt - 1] = w; |
4695 | |
4750 | |
4696 | EV_FREQUENT_CHECK; |
4751 | EV_FREQUENT_CHECK; |
4697 | } |
4752 | } |
4698 | |
4753 | |
4699 | void |
4754 | void |
4700 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4755 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4701 | { |
4756 | { |
4702 | clear_pending (EV_A_ (W)w); |
4757 | clear_pending (EV_A_ (W)w); |
4703 | if (expect_false (!ev_is_active (w))) |
4758 | if (expect_false (!ev_is_active (w))) |
4704 | return; |
4759 | return; |
4705 | |
4760 | |
… | |
… | |
4719 | #endif |
4774 | #endif |
4720 | |
4775 | |
4721 | #if EV_EMBED_ENABLE |
4776 | #if EV_EMBED_ENABLE |
4722 | noinline |
4777 | noinline |
4723 | void |
4778 | void |
4724 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4779 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4725 | { |
4780 | { |
4726 | ev_run (w->other, EVRUN_NOWAIT); |
4781 | ev_run (w->other, EVRUN_NOWAIT); |
4727 | } |
4782 | } |
4728 | |
4783 | |
4729 | static void |
4784 | static void |
… | |
… | |
4777 | ev_idle_stop (EV_A_ idle); |
4832 | ev_idle_stop (EV_A_ idle); |
4778 | } |
4833 | } |
4779 | #endif |
4834 | #endif |
4780 | |
4835 | |
4781 | void |
4836 | void |
4782 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4837 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4783 | { |
4838 | { |
4784 | if (expect_false (ev_is_active (w))) |
4839 | if (expect_false (ev_is_active (w))) |
4785 | return; |
4840 | return; |
4786 | |
4841 | |
4787 | { |
4842 | { |
… | |
… | |
4808 | |
4863 | |
4809 | EV_FREQUENT_CHECK; |
4864 | EV_FREQUENT_CHECK; |
4810 | } |
4865 | } |
4811 | |
4866 | |
4812 | void |
4867 | void |
4813 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4868 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4814 | { |
4869 | { |
4815 | clear_pending (EV_A_ (W)w); |
4870 | clear_pending (EV_A_ (W)w); |
4816 | if (expect_false (!ev_is_active (w))) |
4871 | if (expect_false (!ev_is_active (w))) |
4817 | return; |
4872 | return; |
4818 | |
4873 | |
… | |
… | |
4828 | } |
4883 | } |
4829 | #endif |
4884 | #endif |
4830 | |
4885 | |
4831 | #if EV_FORK_ENABLE |
4886 | #if EV_FORK_ENABLE |
4832 | void |
4887 | void |
4833 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4888 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4834 | { |
4889 | { |
4835 | if (expect_false (ev_is_active (w))) |
4890 | if (expect_false (ev_is_active (w))) |
4836 | return; |
4891 | return; |
4837 | |
4892 | |
4838 | EV_FREQUENT_CHECK; |
4893 | EV_FREQUENT_CHECK; |
4839 | |
4894 | |
4840 | ev_start (EV_A_ (W)w, ++forkcnt); |
4895 | ev_start (EV_A_ (W)w, ++forkcnt); |
4841 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4896 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4842 | forks [forkcnt - 1] = w; |
4897 | forks [forkcnt - 1] = w; |
4843 | |
4898 | |
4844 | EV_FREQUENT_CHECK; |
4899 | EV_FREQUENT_CHECK; |
4845 | } |
4900 | } |
4846 | |
4901 | |
4847 | void |
4902 | void |
4848 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4903 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4849 | { |
4904 | { |
4850 | clear_pending (EV_A_ (W)w); |
4905 | clear_pending (EV_A_ (W)w); |
4851 | if (expect_false (!ev_is_active (w))) |
4906 | if (expect_false (!ev_is_active (w))) |
4852 | return; |
4907 | return; |
4853 | |
4908 | |
… | |
… | |
4866 | } |
4921 | } |
4867 | #endif |
4922 | #endif |
4868 | |
4923 | |
4869 | #if EV_CLEANUP_ENABLE |
4924 | #if EV_CLEANUP_ENABLE |
4870 | void |
4925 | void |
4871 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4926 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4872 | { |
4927 | { |
4873 | if (expect_false (ev_is_active (w))) |
4928 | if (expect_false (ev_is_active (w))) |
4874 | return; |
4929 | return; |
4875 | |
4930 | |
4876 | EV_FREQUENT_CHECK; |
4931 | EV_FREQUENT_CHECK; |
4877 | |
4932 | |
4878 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4933 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4879 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4934 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4880 | cleanups [cleanupcnt - 1] = w; |
4935 | cleanups [cleanupcnt - 1] = w; |
4881 | |
4936 | |
4882 | /* cleanup watchers should never keep a refcount on the loop */ |
4937 | /* cleanup watchers should never keep a refcount on the loop */ |
4883 | ev_unref (EV_A); |
4938 | ev_unref (EV_A); |
4884 | EV_FREQUENT_CHECK; |
4939 | EV_FREQUENT_CHECK; |
4885 | } |
4940 | } |
4886 | |
4941 | |
4887 | void |
4942 | void |
4888 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4943 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4889 | { |
4944 | { |
4890 | clear_pending (EV_A_ (W)w); |
4945 | clear_pending (EV_A_ (W)w); |
4891 | if (expect_false (!ev_is_active (w))) |
4946 | if (expect_false (!ev_is_active (w))) |
4892 | return; |
4947 | return; |
4893 | |
4948 | |
… | |
… | |
4907 | } |
4962 | } |
4908 | #endif |
4963 | #endif |
4909 | |
4964 | |
4910 | #if EV_ASYNC_ENABLE |
4965 | #if EV_ASYNC_ENABLE |
4911 | void |
4966 | void |
4912 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4967 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4913 | { |
4968 | { |
4914 | if (expect_false (ev_is_active (w))) |
4969 | if (expect_false (ev_is_active (w))) |
4915 | return; |
4970 | return; |
4916 | |
4971 | |
4917 | w->sent = 0; |
4972 | w->sent = 0; |
… | |
… | |
4919 | evpipe_init (EV_A); |
4974 | evpipe_init (EV_A); |
4920 | |
4975 | |
4921 | EV_FREQUENT_CHECK; |
4976 | EV_FREQUENT_CHECK; |
4922 | |
4977 | |
4923 | ev_start (EV_A_ (W)w, ++asynccnt); |
4978 | ev_start (EV_A_ (W)w, ++asynccnt); |
4924 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4979 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4925 | asyncs [asynccnt - 1] = w; |
4980 | asyncs [asynccnt - 1] = w; |
4926 | |
4981 | |
4927 | EV_FREQUENT_CHECK; |
4982 | EV_FREQUENT_CHECK; |
4928 | } |
4983 | } |
4929 | |
4984 | |
4930 | void |
4985 | void |
4931 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4986 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4932 | { |
4987 | { |
4933 | clear_pending (EV_A_ (W)w); |
4988 | clear_pending (EV_A_ (W)w); |
4934 | if (expect_false (!ev_is_active (w))) |
4989 | if (expect_false (!ev_is_active (w))) |
4935 | return; |
4990 | return; |
4936 | |
4991 | |
… | |
… | |
4947 | |
5002 | |
4948 | EV_FREQUENT_CHECK; |
5003 | EV_FREQUENT_CHECK; |
4949 | } |
5004 | } |
4950 | |
5005 | |
4951 | void |
5006 | void |
4952 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
5007 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4953 | { |
5008 | { |
4954 | w->sent = 1; |
5009 | w->sent = 1; |
4955 | evpipe_write (EV_A_ &async_pending); |
5010 | evpipe_write (EV_A_ &async_pending); |
4956 | } |
5011 | } |
4957 | #endif |
5012 | #endif |
… | |
… | |
4994 | |
5049 | |
4995 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5050 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4996 | } |
5051 | } |
4997 | |
5052 | |
4998 | void |
5053 | void |
4999 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5054 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
5000 | { |
5055 | { |
5001 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5056 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5002 | |
|
|
5003 | if (expect_false (!once)) |
|
|
5004 | { |
|
|
5005 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5006 | return; |
|
|
5007 | } |
|
|
5008 | |
5057 | |
5009 | once->cb = cb; |
5058 | once->cb = cb; |
5010 | once->arg = arg; |
5059 | once->arg = arg; |
5011 | |
5060 | |
5012 | ev_init (&once->io, once_cb_io); |
5061 | ev_init (&once->io, once_cb_io); |
… | |
… | |
5027 | /*****************************************************************************/ |
5076 | /*****************************************************************************/ |
5028 | |
5077 | |
5029 | #if EV_WALK_ENABLE |
5078 | #if EV_WALK_ENABLE |
5030 | ecb_cold |
5079 | ecb_cold |
5031 | void |
5080 | void |
5032 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5081 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
5033 | { |
5082 | { |
5034 | int i, j; |
5083 | int i, j; |
5035 | ev_watcher_list *wl, *wn; |
5084 | ev_watcher_list *wl, *wn; |
5036 | |
5085 | |
5037 | if (types & (EV_IO | EV_EMBED)) |
5086 | if (types & (EV_IO | EV_EMBED)) |