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> |
… | |
… | |
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 |
… | |
… | |
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)) \ |
… | |
… | |
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) |
… | |
… | |
2112 | ev_io *w; |
2147 | ev_io *w; |
2113 | |
2148 | |
2114 | unsigned char o_events = anfd->events; |
2149 | unsigned char o_events = anfd->events; |
2115 | unsigned char o_reify = anfd->reify; |
2150 | unsigned char o_reify = anfd->reify; |
2116 | |
2151 | |
2117 | anfd->reify = 0; |
2152 | anfd->reify = 0; |
2118 | |
2153 | |
2119 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2154 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2120 | { |
2155 | { |
2121 | anfd->events = 0; |
2156 | anfd->events = 0; |
2122 | |
2157 | |
… | |
… | |
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 */ |
… | |
… | |
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" |
… | |
… | |
2740 | unsigned int |
2778 | unsigned int |
2741 | ev_supported_backends (void) EV_NOEXCEPT |
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 |
… | |
… | |
2767 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
2806 | flags &= ~EVBACKEND_KQUEUE; /* horribly broken, even for sockets */ |
2768 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
2807 | flags &= ~EVBACKEND_POLL; /* poll is based on kqueue from 10.5 onwards */ |
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) */ |
|
|
2811 | #endif |
|
|
2812 | |
|
|
2813 | /* TODO: linuxaio is very experimental */ |
|
|
2814 | #if !EV_RECOMMEND_LINUXAIO |
|
|
2815 | flags &= ~EVBACKEND_LINUXAIO; |
2772 | #endif |
2816 | #endif |
2773 | |
2817 | |
2774 | return flags; |
2818 | return flags; |
2775 | } |
2819 | } |
2776 | |
2820 | |
… | |
… | |
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 | |
… | |
… | |
3870 | return; |
3923 | return; |
3871 | |
3924 | |
3872 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3925 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3873 | 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)))); |
3874 | |
3927 | |
|
|
3928 | #if EV_VERIFY >= 2 |
|
|
3929 | assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd))); |
|
|
3930 | #endif |
3875 | EV_FREQUENT_CHECK; |
3931 | EV_FREQUENT_CHECK; |
3876 | |
3932 | |
3877 | ev_start (EV_A_ (W)w, 1); |
3933 | ev_start (EV_A_ (W)w, 1); |
3878 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3934 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3879 | wlist_add (&anfds[fd].head, (WL)w); |
3935 | wlist_add (&anfds[fd].head, (WL)w); |
3880 | |
3936 | |
3881 | /* common bug, apparently */ |
3937 | /* common bug, apparently */ |
3882 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3938 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3883 | |
3939 | |
… | |
… | |
3895 | if (expect_false (!ev_is_active (w))) |
3951 | if (expect_false (!ev_is_active (w))) |
3896 | return; |
3952 | return; |
3897 | |
3953 | |
3898 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3954 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3899 | |
3955 | |
|
|
3956 | #if EV_VERIFY >= 2 |
|
|
3957 | assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd))); |
|
|
3958 | #endif |
3900 | EV_FREQUENT_CHECK; |
3959 | EV_FREQUENT_CHECK; |
3901 | |
3960 | |
3902 | wlist_del (&anfds[w->fd].head, (WL)w); |
3961 | wlist_del (&anfds[w->fd].head, (WL)w); |
3903 | ev_stop (EV_A_ (W)w); |
3962 | ev_stop (EV_A_ (W)w); |
3904 | |
3963 | |
… | |
… | |
3920 | |
3979 | |
3921 | EV_FREQUENT_CHECK; |
3980 | EV_FREQUENT_CHECK; |
3922 | |
3981 | |
3923 | ++timercnt; |
3982 | ++timercnt; |
3924 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3983 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3925 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3984 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3926 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3985 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3927 | ANHE_at_cache (timers [ev_active (w)]); |
3986 | ANHE_at_cache (timers [ev_active (w)]); |
3928 | upheap (timers, ev_active (w)); |
3987 | upheap (timers, ev_active (w)); |
3929 | |
3988 | |
3930 | EV_FREQUENT_CHECK; |
3989 | EV_FREQUENT_CHECK; |
… | |
… | |
4017 | |
4076 | |
4018 | EV_FREQUENT_CHECK; |
4077 | EV_FREQUENT_CHECK; |
4019 | |
4078 | |
4020 | ++periodiccnt; |
4079 | ++periodiccnt; |
4021 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4080 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4022 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4081 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
4023 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4082 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4024 | ANHE_at_cache (periodics [ev_active (w)]); |
4083 | ANHE_at_cache (periodics [ev_active (w)]); |
4025 | upheap (periodics, ev_active (w)); |
4084 | upheap (periodics, ev_active (w)); |
4026 | |
4085 | |
4027 | EV_FREQUENT_CHECK; |
4086 | EV_FREQUENT_CHECK; |
… | |
… | |
4612 | int active = ++idlecnt [ABSPRI (w)]; |
4671 | int active = ++idlecnt [ABSPRI (w)]; |
4613 | |
4672 | |
4614 | ++idleall; |
4673 | ++idleall; |
4615 | ev_start (EV_A_ (W)w, active); |
4674 | ev_start (EV_A_ (W)w, active); |
4616 | |
4675 | |
4617 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4676 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4618 | idles [ABSPRI (w)][active - 1] = w; |
4677 | idles [ABSPRI (w)][active - 1] = w; |
4619 | } |
4678 | } |
4620 | |
4679 | |
4621 | EV_FREQUENT_CHECK; |
4680 | EV_FREQUENT_CHECK; |
4622 | } |
4681 | } |
… | |
… | |
4652 | return; |
4711 | return; |
4653 | |
4712 | |
4654 | EV_FREQUENT_CHECK; |
4713 | EV_FREQUENT_CHECK; |
4655 | |
4714 | |
4656 | ev_start (EV_A_ (W)w, ++preparecnt); |
4715 | ev_start (EV_A_ (W)w, ++preparecnt); |
4657 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4716 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4658 | prepares [preparecnt - 1] = w; |
4717 | prepares [preparecnt - 1] = w; |
4659 | |
4718 | |
4660 | EV_FREQUENT_CHECK; |
4719 | EV_FREQUENT_CHECK; |
4661 | } |
4720 | } |
4662 | |
4721 | |
… | |
… | |
4690 | return; |
4749 | return; |
4691 | |
4750 | |
4692 | EV_FREQUENT_CHECK; |
4751 | EV_FREQUENT_CHECK; |
4693 | |
4752 | |
4694 | ev_start (EV_A_ (W)w, ++checkcnt); |
4753 | ev_start (EV_A_ (W)w, ++checkcnt); |
4695 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4754 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4696 | checks [checkcnt - 1] = w; |
4755 | checks [checkcnt - 1] = w; |
4697 | |
4756 | |
4698 | EV_FREQUENT_CHECK; |
4757 | EV_FREQUENT_CHECK; |
4699 | } |
4758 | } |
4700 | |
4759 | |
… | |
… | |
4838 | return; |
4897 | return; |
4839 | |
4898 | |
4840 | EV_FREQUENT_CHECK; |
4899 | EV_FREQUENT_CHECK; |
4841 | |
4900 | |
4842 | ev_start (EV_A_ (W)w, ++forkcnt); |
4901 | ev_start (EV_A_ (W)w, ++forkcnt); |
4843 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4902 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4844 | forks [forkcnt - 1] = w; |
4903 | forks [forkcnt - 1] = w; |
4845 | |
4904 | |
4846 | EV_FREQUENT_CHECK; |
4905 | EV_FREQUENT_CHECK; |
4847 | } |
4906 | } |
4848 | |
4907 | |
… | |
… | |
4876 | return; |
4935 | return; |
4877 | |
4936 | |
4878 | EV_FREQUENT_CHECK; |
4937 | EV_FREQUENT_CHECK; |
4879 | |
4938 | |
4880 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4939 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4881 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4940 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4882 | cleanups [cleanupcnt - 1] = w; |
4941 | cleanups [cleanupcnt - 1] = w; |
4883 | |
4942 | |
4884 | /* cleanup watchers should never keep a refcount on the loop */ |
4943 | /* cleanup watchers should never keep a refcount on the loop */ |
4885 | ev_unref (EV_A); |
4944 | ev_unref (EV_A); |
4886 | EV_FREQUENT_CHECK; |
4945 | EV_FREQUENT_CHECK; |
… | |
… | |
4921 | evpipe_init (EV_A); |
4980 | evpipe_init (EV_A); |
4922 | |
4981 | |
4923 | EV_FREQUENT_CHECK; |
4982 | EV_FREQUENT_CHECK; |
4924 | |
4983 | |
4925 | ev_start (EV_A_ (W)w, ++asynccnt); |
4984 | ev_start (EV_A_ (W)w, ++asynccnt); |
4926 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4985 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4927 | asyncs [asynccnt - 1] = w; |
4986 | asyncs [asynccnt - 1] = w; |
4928 | |
4987 | |
4929 | EV_FREQUENT_CHECK; |
4988 | EV_FREQUENT_CHECK; |
4930 | } |
4989 | } |
4931 | |
4990 | |
… | |
… | |
4999 | |
5058 | |
5000 | void |
5059 | void |
5001 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
5060 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
5002 | { |
5061 | { |
5003 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5062 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5004 | |
|
|
5005 | if (expect_false (!once)) |
|
|
5006 | { |
|
|
5007 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
5008 | return; |
|
|
5009 | } |
|
|
5010 | |
5063 | |
5011 | once->cb = cb; |
5064 | once->cb = cb; |
5012 | once->arg = arg; |
5065 | once->arg = arg; |
5013 | |
5066 | |
5014 | ev_init (&once->io, once_cb_io); |
5067 | ev_init (&once->io, once_cb_io); |