1 | /* |
1 | /* |
2 | * libev event processing core, watcher management |
2 | * libev event processing core, watcher management |
3 | * |
3 | * |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012,2013 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007-2019 Marc Alexander Lehmann <libev@schmorp.de> |
5 | * All rights reserved. |
5 | * All rights reserved. |
6 | * |
6 | * |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
7 | * Redistribution and use in source and binary forms, with or without modifica- |
8 | * tion, are permitted provided that the following conditions are met: |
8 | * tion, are permitted provided that the following conditions are met: |
9 | * |
9 | * |
… | |
… | |
115 | # else |
115 | # else |
116 | # undef EV_USE_EPOLL |
116 | # undef EV_USE_EPOLL |
117 | # define EV_USE_EPOLL 0 |
117 | # define EV_USE_EPOLL 0 |
118 | # endif |
118 | # endif |
119 | |
119 | |
|
|
120 | # if HAVE_LINUX_AIO_ABI_H |
|
|
121 | # ifndef EV_USE_LINUXAIO |
|
|
122 | # define EV_USE_LINUXAIO EV_FEATURE_BACKENDS |
|
|
123 | # endif |
|
|
124 | # else |
|
|
125 | # undef EV_USE_LINUXAIO |
|
|
126 | # define EV_USE_LINUXAIO 0 |
|
|
127 | # endif |
|
|
128 | |
120 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
129 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
121 | # ifndef EV_USE_KQUEUE |
130 | # ifndef EV_USE_KQUEUE |
122 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
131 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
123 | # endif |
132 | # endif |
124 | # else |
133 | # else |
… | |
… | |
162 | # define EV_USE_EVENTFD 0 |
171 | # define EV_USE_EVENTFD 0 |
163 | # endif |
172 | # endif |
164 | |
173 | |
165 | #endif |
174 | #endif |
166 | |
175 | |
|
|
176 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
177 | * a limit of 1024 into their select. Where people have brains, |
|
|
178 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
179 | * ordered to have a vacuum, or they do anything for money. |
|
|
180 | * This might help. Or not. |
|
|
181 | * Note that this must be defined early, as other include files |
|
|
182 | * will rely on this define as well. |
|
|
183 | */ |
|
|
184 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
185 | |
167 | #include <stdlib.h> |
186 | #include <stdlib.h> |
168 | #include <string.h> |
187 | #include <string.h> |
169 | #include <fcntl.h> |
188 | #include <fcntl.h> |
170 | #include <stddef.h> |
189 | #include <stddef.h> |
171 | |
190 | |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
227 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
228 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
229 | # endif |
211 | # undef EV_AVOID_STDIO |
230 | # undef EV_AVOID_STDIO |
212 | #endif |
231 | #endif |
213 | |
|
|
214 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
215 | * a limit of 1024 into their select. Where people have brains, |
|
|
216 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
217 | * ordered to have a vacuum, or they do anything for money. |
|
|
218 | * This might help. Or not. |
|
|
219 | */ |
|
|
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
|
|
221 | |
232 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
233 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
234 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
235 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
236 | #if defined EV_NSIG |
… | |
… | |
313 | |
324 | |
314 | #ifndef EV_USE_PORT |
325 | #ifndef EV_USE_PORT |
315 | # define EV_USE_PORT 0 |
326 | # define EV_USE_PORT 0 |
316 | #endif |
327 | #endif |
317 | |
328 | |
|
|
329 | #ifndef EV_USE_LINUXAIO |
|
|
330 | # if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ |
|
|
331 | # define EV_USE_LINUXAIO 1 |
|
|
332 | # else |
|
|
333 | # define EV_USE_LINUXAIO 0 |
|
|
334 | # endif |
|
|
335 | #endif |
|
|
336 | |
318 | #ifndef EV_USE_INOTIFY |
337 | #ifndef EV_USE_INOTIFY |
319 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
338 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
320 | # define EV_USE_INOTIFY EV_FEATURE_OS |
339 | # define EV_USE_INOTIFY EV_FEATURE_OS |
321 | # else |
340 | # else |
322 | # define EV_USE_INOTIFY 0 |
341 | # define EV_USE_INOTIFY 0 |
… | |
… | |
363 | |
382 | |
364 | #ifndef EV_HEAP_CACHE_AT |
383 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
384 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
385 | #endif |
367 | |
386 | |
368 | #ifdef ANDROID |
387 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
388 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
389 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
390 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
391 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
392 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
377 | /* aix's poll.h seems to cause lots of trouble */ |
396 | /* aix's poll.h seems to cause lots of trouble */ |
378 | #ifdef _AIX |
397 | #ifdef _AIX |
379 | /* AIX has a completely broken poll.h header */ |
398 | /* AIX has a completely broken poll.h header */ |
380 | # undef EV_USE_POLL |
399 | # undef EV_USE_POLL |
381 | # define EV_USE_POLL 0 |
400 | # define EV_USE_POLL 0 |
|
|
401 | #endif |
|
|
402 | |
|
|
403 | #if EV_USE_LINUXAIO |
|
|
404 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
382 | #endif |
405 | #endif |
383 | |
406 | |
384 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
407 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
385 | /* which makes programs even slower. might work on other unices, too. */ |
408 | /* which makes programs even slower. might work on other unices, too. */ |
386 | #if EV_USE_CLOCK_SYSCALL |
409 | #if EV_USE_CLOCK_SYSCALL |
… | |
… | |
414 | |
437 | |
415 | #if !EV_USE_NANOSLEEP |
438 | #if !EV_USE_NANOSLEEP |
416 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
439 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
417 | # if !defined _WIN32 && !defined __hpux |
440 | # if !defined _WIN32 && !defined __hpux |
418 | # include <sys/select.h> |
441 | # include <sys/select.h> |
|
|
442 | # endif |
|
|
443 | #endif |
|
|
444 | |
|
|
445 | #if EV_USE_LINUXAIO |
|
|
446 | # include <sys/syscall.h> |
|
|
447 | # if !SYS_io_getevents |
|
|
448 | # undef EV_USE_LINUXAIO |
|
|
449 | # define EV_USE_LINUXAIO 0 |
419 | # endif |
450 | # endif |
420 | #endif |
451 | #endif |
421 | |
452 | |
422 | #if EV_USE_INOTIFY |
453 | #if EV_USE_INOTIFY |
423 | # include <sys/statfs.h> |
454 | # include <sys/statfs.h> |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
638 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
639 | #endif |
609 | |
640 | |
610 | #define ECB_CPP (__cplusplus+0) |
641 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
642 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
643 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
644 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
645 | |
613 | #if ECB_CPP |
646 | #if ECB_CPP |
614 | #define ECB_C 0 |
647 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
648 | #define ECB_STDC_VERSION 0 |
616 | #else |
649 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
651 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
652 | #endif |
620 | |
653 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
654 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
655 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
656 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
657 | |
624 | #if ECB_CPP |
658 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
659 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
660 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
661 | #define ECB_EXTERN_C_END } |
… | |
… | |
656 | #ifndef ECB_MEMORY_FENCE |
690 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
691 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
658 | #if __i386 || __i386__ |
692 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
693 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
694 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
695 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
696 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
697 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
698 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
699 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
700 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
701 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
702 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
703 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
704 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
1527 | #define inline_size ecb_inline |
1561 | #define inline_size ecb_inline |
1528 | |
1562 | |
1529 | #if EV_FEATURE_CODE |
1563 | #if EV_FEATURE_CODE |
1530 | # define inline_speed ecb_inline |
1564 | # define inline_speed ecb_inline |
1531 | #else |
1565 | #else |
1532 | # define inline_speed static noinline |
1566 | # define inline_speed noinline static |
1533 | #endif |
1567 | #endif |
1534 | |
1568 | |
1535 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1569 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1536 | |
1570 | |
1537 | #if EV_MINPRI == EV_MAXPRI |
1571 | #if EV_MINPRI == EV_MAXPRI |
1538 | # define ABSPRI(w) (((W)w), 0) |
1572 | # define ABSPRI(w) (((W)w), 0) |
1539 | #else |
1573 | #else |
1540 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1574 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1541 | #endif |
1575 | #endif |
1542 | |
1576 | |
1543 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1577 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1544 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1545 | |
1578 | |
1546 | typedef ev_watcher *W; |
1579 | typedef ev_watcher *W; |
1547 | typedef ev_watcher_list *WL; |
1580 | typedef ev_watcher_list *WL; |
1548 | typedef ev_watcher_time *WT; |
1581 | typedef ev_watcher_time *WT; |
1549 | |
1582 | |
… | |
… | |
1584 | #else |
1617 | #else |
1585 | |
1618 | |
1586 | #include <float.h> |
1619 | #include <float.h> |
1587 | |
1620 | |
1588 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1621 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
|
|
1622 | noinline |
1589 | static ev_tstamp noinline |
1623 | static ev_tstamp |
1590 | ev_floor (ev_tstamp v) |
1624 | ev_floor (ev_tstamp v) |
1591 | { |
1625 | { |
1592 | /* the choice of shift factor is not terribly important */ |
1626 | /* the choice of shift factor is not terribly important */ |
1593 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1627 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1594 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1628 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
… | |
… | |
1626 | |
1660 | |
1627 | #ifdef __linux |
1661 | #ifdef __linux |
1628 | # include <sys/utsname.h> |
1662 | # include <sys/utsname.h> |
1629 | #endif |
1663 | #endif |
1630 | |
1664 | |
1631 | static unsigned int noinline ecb_cold |
1665 | noinline ecb_cold |
|
|
1666 | static unsigned int |
1632 | ev_linux_version (void) |
1667 | ev_linux_version (void) |
1633 | { |
1668 | { |
1634 | #ifdef __linux |
1669 | #ifdef __linux |
1635 | unsigned int v = 0; |
1670 | unsigned int v = 0; |
1636 | struct utsname buf; |
1671 | struct utsname buf; |
… | |
… | |
1665 | } |
1700 | } |
1666 | |
1701 | |
1667 | /*****************************************************************************/ |
1702 | /*****************************************************************************/ |
1668 | |
1703 | |
1669 | #if EV_AVOID_STDIO |
1704 | #if EV_AVOID_STDIO |
1670 | static void noinline ecb_cold |
1705 | noinline ecb_cold |
|
|
1706 | static void |
1671 | ev_printerr (const char *msg) |
1707 | ev_printerr (const char *msg) |
1672 | { |
1708 | { |
1673 | write (STDERR_FILENO, msg, strlen (msg)); |
1709 | write (STDERR_FILENO, msg, strlen (msg)); |
1674 | } |
1710 | } |
1675 | #endif |
1711 | #endif |
1676 | |
1712 | |
1677 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1713 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1678 | |
1714 | |
1679 | void ecb_cold |
1715 | ecb_cold |
|
|
1716 | void |
1680 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1717 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1681 | { |
1718 | { |
1682 | syserr_cb = cb; |
1719 | syserr_cb = cb; |
1683 | } |
1720 | } |
1684 | |
1721 | |
1685 | static void noinline ecb_cold |
1722 | noinline ecb_cold |
|
|
1723 | static void |
1686 | ev_syserr (const char *msg) |
1724 | ev_syserr (const char *msg) |
1687 | { |
1725 | { |
1688 | if (!msg) |
1726 | if (!msg) |
1689 | msg = "(libev) system error"; |
1727 | msg = "(libev) system error"; |
1690 | |
1728 | |
… | |
… | |
1703 | abort (); |
1741 | abort (); |
1704 | } |
1742 | } |
1705 | } |
1743 | } |
1706 | |
1744 | |
1707 | static void * |
1745 | static void * |
1708 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1746 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1709 | { |
1747 | { |
1710 | /* some systems, notably openbsd and darwin, fail to properly |
1748 | /* some systems, notably openbsd and darwin, fail to properly |
1711 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1749 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1712 | * the single unix specification, so work around them here. |
1750 | * the single unix specification, so work around them here. |
1713 | * recently, also (at least) fedora and debian started breaking it, |
1751 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1719 | |
1757 | |
1720 | free (ptr); |
1758 | free (ptr); |
1721 | return 0; |
1759 | return 0; |
1722 | } |
1760 | } |
1723 | |
1761 | |
1724 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1762 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1725 | |
1763 | |
1726 | void ecb_cold |
1764 | ecb_cold |
|
|
1765 | void |
1727 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1766 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1728 | { |
1767 | { |
1729 | alloc = cb; |
1768 | alloc = cb; |
1730 | } |
1769 | } |
1731 | |
1770 | |
1732 | inline_speed void * |
1771 | inline_speed void * |
… | |
… | |
1759 | typedef struct |
1798 | typedef struct |
1760 | { |
1799 | { |
1761 | WL head; |
1800 | WL head; |
1762 | unsigned char events; /* the events watched for */ |
1801 | unsigned char events; /* the events watched for */ |
1763 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1802 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1764 | unsigned char emask; /* the epoll backend stores the actual kernel mask in here */ |
1803 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1765 | unsigned char unused; |
1804 | unsigned char unused; |
1766 | #if EV_USE_EPOLL |
1805 | #if EV_USE_EPOLL |
1767 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1806 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1768 | #endif |
1807 | #endif |
1769 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1808 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
… | |
… | |
1849 | |
1888 | |
1850 | /*****************************************************************************/ |
1889 | /*****************************************************************************/ |
1851 | |
1890 | |
1852 | #ifndef EV_HAVE_EV_TIME |
1891 | #ifndef EV_HAVE_EV_TIME |
1853 | ev_tstamp |
1892 | ev_tstamp |
1854 | ev_time (void) EV_THROW |
1893 | ev_time (void) EV_NOEXCEPT |
1855 | { |
1894 | { |
1856 | #if EV_USE_REALTIME |
1895 | #if EV_USE_REALTIME |
1857 | if (expect_true (have_realtime)) |
1896 | if (expect_true (have_realtime)) |
1858 | { |
1897 | { |
1859 | struct timespec ts; |
1898 | struct timespec ts; |
… | |
… | |
1883 | return ev_time (); |
1922 | return ev_time (); |
1884 | } |
1923 | } |
1885 | |
1924 | |
1886 | #if EV_MULTIPLICITY |
1925 | #if EV_MULTIPLICITY |
1887 | ev_tstamp |
1926 | ev_tstamp |
1888 | ev_now (EV_P) EV_THROW |
1927 | ev_now (EV_P) EV_NOEXCEPT |
1889 | { |
1928 | { |
1890 | return ev_rt_now; |
1929 | return ev_rt_now; |
1891 | } |
1930 | } |
1892 | #endif |
1931 | #endif |
1893 | |
1932 | |
1894 | void |
1933 | void |
1895 | ev_sleep (ev_tstamp delay) EV_THROW |
1934 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1896 | { |
1935 | { |
1897 | if (delay > 0.) |
1936 | if (delay > 0.) |
1898 | { |
1937 | { |
1899 | #if EV_USE_NANOSLEEP |
1938 | #if EV_USE_NANOSLEEP |
1900 | struct timespec ts; |
1939 | struct timespec ts; |
1901 | |
1940 | |
1902 | EV_TS_SET (ts, delay); |
1941 | EV_TS_SET (ts, delay); |
1903 | nanosleep (&ts, 0); |
1942 | nanosleep (&ts, 0); |
1904 | #elif defined _WIN32 |
1943 | #elif defined _WIN32 |
|
|
1944 | /* maybe this should round up, as ms is very low resolution */ |
|
|
1945 | /* compared to select (µs) or nanosleep (ns) */ |
1905 | Sleep ((unsigned long)(delay * 1e3)); |
1946 | Sleep ((unsigned long)(delay * 1e3)); |
1906 | #else |
1947 | #else |
1907 | struct timeval tv; |
1948 | struct timeval tv; |
1908 | |
1949 | |
1909 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1950 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1940 | } |
1981 | } |
1941 | |
1982 | |
1942 | return ncur; |
1983 | return ncur; |
1943 | } |
1984 | } |
1944 | |
1985 | |
1945 | static void * noinline ecb_cold |
1986 | noinline ecb_cold |
|
|
1987 | static void * |
1946 | array_realloc (int elem, void *base, int *cur, int cnt) |
1988 | array_realloc (int elem, void *base, int *cur, int cnt) |
1947 | { |
1989 | { |
1948 | *cur = array_nextsize (elem, *cur, cnt); |
1990 | *cur = array_nextsize (elem, *cur, cnt); |
1949 | return ev_realloc (base, elem * *cur); |
1991 | return ev_realloc (base, elem * *cur); |
1950 | } |
1992 | } |
1951 | |
1993 | |
|
|
1994 | #define array_needsize_noinit(base,count) |
|
|
1995 | |
1952 | #define array_init_zero(base,count) \ |
1996 | #define array_needsize_zerofill(base,count) \ |
1953 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1997 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
1954 | |
1998 | |
1955 | #define array_needsize(type,base,cur,cnt,init) \ |
1999 | #define array_needsize(type,base,cur,cnt,init) \ |
1956 | if (expect_false ((cnt) > (cur))) \ |
2000 | if (expect_false ((cnt) > (cur))) \ |
1957 | { \ |
2001 | { \ |
1958 | int ecb_unused ocur_ = (cur); \ |
2002 | ecb_unused int ocur_ = (cur); \ |
1959 | (base) = (type *)array_realloc \ |
2003 | (base) = (type *)array_realloc \ |
1960 | (sizeof (type), (base), &(cur), (cnt)); \ |
2004 | (sizeof (type), (base), &(cur), (cnt)); \ |
1961 | init ((base) + (ocur_), (cur) - ocur_); \ |
2005 | init ((base) + (ocur_), (cur) - ocur_); \ |
1962 | } |
2006 | } |
1963 | |
2007 | |
… | |
… | |
1975 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2019 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1976 | |
2020 | |
1977 | /*****************************************************************************/ |
2021 | /*****************************************************************************/ |
1978 | |
2022 | |
1979 | /* dummy callback for pending events */ |
2023 | /* dummy callback for pending events */ |
1980 | static void noinline |
2024 | noinline |
|
|
2025 | static void |
1981 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2026 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1982 | { |
2027 | { |
1983 | } |
2028 | } |
1984 | |
2029 | |
1985 | void noinline |
2030 | noinline |
|
|
2031 | void |
1986 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2032 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1987 | { |
2033 | { |
1988 | W w_ = (W)w; |
2034 | W w_ = (W)w; |
1989 | int pri = ABSPRI (w_); |
2035 | int pri = ABSPRI (w_); |
1990 | |
2036 | |
1991 | if (expect_false (w_->pending)) |
2037 | if (expect_false (w_->pending)) |
1992 | pendings [pri][w_->pending - 1].events |= revents; |
2038 | pendings [pri][w_->pending - 1].events |= revents; |
1993 | else |
2039 | else |
1994 | { |
2040 | { |
1995 | w_->pending = ++pendingcnt [pri]; |
2041 | w_->pending = ++pendingcnt [pri]; |
1996 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2042 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
1997 | pendings [pri][w_->pending - 1].w = w_; |
2043 | pendings [pri][w_->pending - 1].w = w_; |
1998 | pendings [pri][w_->pending - 1].events = revents; |
2044 | pendings [pri][w_->pending - 1].events = revents; |
1999 | } |
2045 | } |
2000 | |
2046 | |
2001 | pendingpri = NUMPRI - 1; |
2047 | pendingpri = NUMPRI - 1; |
2002 | } |
2048 | } |
2003 | |
2049 | |
2004 | inline_speed void |
2050 | inline_speed void |
2005 | feed_reverse (EV_P_ W w) |
2051 | feed_reverse (EV_P_ W w) |
2006 | { |
2052 | { |
2007 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2053 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2008 | rfeeds [rfeedcnt++] = w; |
2054 | rfeeds [rfeedcnt++] = w; |
2009 | } |
2055 | } |
2010 | |
2056 | |
2011 | inline_size void |
2057 | inline_size void |
2012 | feed_reverse_done (EV_P_ int revents) |
2058 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2052 | if (expect_true (!anfd->reify)) |
2098 | if (expect_true (!anfd->reify)) |
2053 | fd_event_nocheck (EV_A_ fd, revents); |
2099 | fd_event_nocheck (EV_A_ fd, revents); |
2054 | } |
2100 | } |
2055 | |
2101 | |
2056 | void |
2102 | void |
2057 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2103 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2058 | { |
2104 | { |
2059 | if (fd >= 0 && fd < anfdmax) |
2105 | if (fd >= 0 && fd < anfdmax) |
2060 | fd_event_nocheck (EV_A_ fd, revents); |
2106 | fd_event_nocheck (EV_A_ fd, revents); |
2061 | } |
2107 | } |
2062 | |
2108 | |
… | |
… | |
2120 | |
2166 | |
2121 | fdchangecnt = 0; |
2167 | fdchangecnt = 0; |
2122 | } |
2168 | } |
2123 | |
2169 | |
2124 | /* something about the given fd changed */ |
2170 | /* something about the given fd changed */ |
2125 | inline_size void |
2171 | inline_size |
|
|
2172 | void |
2126 | fd_change (EV_P_ int fd, int flags) |
2173 | fd_change (EV_P_ int fd, int flags) |
2127 | { |
2174 | { |
2128 | unsigned char reify = anfds [fd].reify; |
2175 | unsigned char reify = anfds [fd].reify; |
2129 | anfds [fd].reify |= flags; |
2176 | anfds [fd].reify |= flags; |
2130 | |
2177 | |
2131 | if (expect_true (!reify)) |
2178 | if (expect_true (!reify)) |
2132 | { |
2179 | { |
2133 | ++fdchangecnt; |
2180 | ++fdchangecnt; |
2134 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2181 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2135 | fdchanges [fdchangecnt - 1] = fd; |
2182 | fdchanges [fdchangecnt - 1] = fd; |
2136 | } |
2183 | } |
2137 | } |
2184 | } |
2138 | |
2185 | |
2139 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2186 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2140 | inline_speed void ecb_cold |
2187 | inline_speed ecb_cold void |
2141 | fd_kill (EV_P_ int fd) |
2188 | fd_kill (EV_P_ int fd) |
2142 | { |
2189 | { |
2143 | ev_io *w; |
2190 | ev_io *w; |
2144 | |
2191 | |
2145 | while ((w = (ev_io *)anfds [fd].head)) |
2192 | while ((w = (ev_io *)anfds [fd].head)) |
… | |
… | |
2148 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2195 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2149 | } |
2196 | } |
2150 | } |
2197 | } |
2151 | |
2198 | |
2152 | /* check whether the given fd is actually valid, for error recovery */ |
2199 | /* check whether the given fd is actually valid, for error recovery */ |
2153 | inline_size int ecb_cold |
2200 | inline_size ecb_cold int |
2154 | fd_valid (int fd) |
2201 | fd_valid (int fd) |
2155 | { |
2202 | { |
2156 | #ifdef _WIN32 |
2203 | #ifdef _WIN32 |
2157 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2204 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2158 | #else |
2205 | #else |
2159 | return fcntl (fd, F_GETFD) != -1; |
2206 | return fcntl (fd, F_GETFD) != -1; |
2160 | #endif |
2207 | #endif |
2161 | } |
2208 | } |
2162 | |
2209 | |
2163 | /* called on EBADF to verify fds */ |
2210 | /* called on EBADF to verify fds */ |
2164 | static void noinline ecb_cold |
2211 | noinline ecb_cold |
|
|
2212 | static void |
2165 | fd_ebadf (EV_P) |
2213 | fd_ebadf (EV_P) |
2166 | { |
2214 | { |
2167 | int fd; |
2215 | int fd; |
2168 | |
2216 | |
2169 | for (fd = 0; fd < anfdmax; ++fd) |
2217 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2171 | if (!fd_valid (fd) && errno == EBADF) |
2219 | if (!fd_valid (fd) && errno == EBADF) |
2172 | fd_kill (EV_A_ fd); |
2220 | fd_kill (EV_A_ fd); |
2173 | } |
2221 | } |
2174 | |
2222 | |
2175 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2223 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2176 | static void noinline ecb_cold |
2224 | noinline ecb_cold |
|
|
2225 | static void |
2177 | fd_enomem (EV_P) |
2226 | fd_enomem (EV_P) |
2178 | { |
2227 | { |
2179 | int fd; |
2228 | int fd; |
2180 | |
2229 | |
2181 | for (fd = anfdmax; fd--; ) |
2230 | for (fd = anfdmax; fd--; ) |
… | |
… | |
2185 | break; |
2234 | break; |
2186 | } |
2235 | } |
2187 | } |
2236 | } |
2188 | |
2237 | |
2189 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2238 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2190 | static void noinline |
2239 | noinline |
|
|
2240 | static void |
2191 | fd_rearm_all (EV_P) |
2241 | fd_rearm_all (EV_P) |
2192 | { |
2242 | { |
2193 | int fd; |
2243 | int fd; |
2194 | |
2244 | |
2195 | for (fd = 0; fd < anfdmax; ++fd) |
2245 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2376 | |
2426 | |
2377 | /*****************************************************************************/ |
2427 | /*****************************************************************************/ |
2378 | |
2428 | |
2379 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2429 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2380 | |
2430 | |
2381 | static void noinline ecb_cold |
2431 | noinline ecb_cold |
|
|
2432 | static void |
2382 | evpipe_init (EV_P) |
2433 | evpipe_init (EV_P) |
2383 | { |
2434 | { |
2384 | if (!ev_is_active (&pipe_w)) |
2435 | if (!ev_is_active (&pipe_w)) |
2385 | { |
2436 | { |
2386 | int fds [2]; |
2437 | int fds [2]; |
… | |
… | |
2457 | #endif |
2508 | #endif |
2458 | { |
2509 | { |
2459 | #ifdef _WIN32 |
2510 | #ifdef _WIN32 |
2460 | WSABUF buf; |
2511 | WSABUF buf; |
2461 | DWORD sent; |
2512 | DWORD sent; |
2462 | buf.buf = &buf; |
2513 | buf.buf = (char *)&buf; |
2463 | buf.len = 1; |
2514 | buf.len = 1; |
2464 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2515 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2465 | #else |
2516 | #else |
2466 | write (evpipe [1], &(evpipe [1]), 1); |
2517 | write (evpipe [1], &(evpipe [1]), 1); |
2467 | #endif |
2518 | #endif |
… | |
… | |
2539 | } |
2590 | } |
2540 | |
2591 | |
2541 | /*****************************************************************************/ |
2592 | /*****************************************************************************/ |
2542 | |
2593 | |
2543 | void |
2594 | void |
2544 | ev_feed_signal (int signum) EV_THROW |
2595 | ev_feed_signal (int signum) EV_NOEXCEPT |
2545 | { |
2596 | { |
2546 | #if EV_MULTIPLICITY |
2597 | #if EV_MULTIPLICITY |
2547 | EV_P; |
2598 | EV_P; |
2548 | ECB_MEMORY_FENCE_ACQUIRE; |
2599 | ECB_MEMORY_FENCE_ACQUIRE; |
2549 | EV_A = signals [signum - 1].loop; |
2600 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2564 | #endif |
2615 | #endif |
2565 | |
2616 | |
2566 | ev_feed_signal (signum); |
2617 | ev_feed_signal (signum); |
2567 | } |
2618 | } |
2568 | |
2619 | |
2569 | void noinline |
2620 | noinline |
|
|
2621 | void |
2570 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2622 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2571 | { |
2623 | { |
2572 | WL w; |
2624 | WL w; |
2573 | |
2625 | |
2574 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2626 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2575 | return; |
2627 | return; |
… | |
… | |
2681 | # include "ev_port.c" |
2733 | # include "ev_port.c" |
2682 | #endif |
2734 | #endif |
2683 | #if EV_USE_KQUEUE |
2735 | #if EV_USE_KQUEUE |
2684 | # include "ev_kqueue.c" |
2736 | # include "ev_kqueue.c" |
2685 | #endif |
2737 | #endif |
|
|
2738 | #if EV_USE_LINUXAIO |
|
|
2739 | # include "ev_linuxaio.c" |
|
|
2740 | #endif |
2686 | #if EV_USE_EPOLL |
2741 | #if EV_USE_EPOLL |
2687 | # include "ev_epoll.c" |
2742 | # include "ev_epoll.c" |
2688 | #endif |
2743 | #endif |
2689 | #if EV_USE_POLL |
2744 | #if EV_USE_POLL |
2690 | # include "ev_poll.c" |
2745 | # include "ev_poll.c" |
2691 | #endif |
2746 | #endif |
2692 | #if EV_USE_SELECT |
2747 | #if EV_USE_SELECT |
2693 | # include "ev_select.c" |
2748 | # include "ev_select.c" |
2694 | #endif |
2749 | #endif |
2695 | |
2750 | |
2696 | int ecb_cold |
2751 | ecb_cold int |
2697 | ev_version_major (void) EV_THROW |
2752 | ev_version_major (void) EV_NOEXCEPT |
2698 | { |
2753 | { |
2699 | return EV_VERSION_MAJOR; |
2754 | return EV_VERSION_MAJOR; |
2700 | } |
2755 | } |
2701 | |
2756 | |
2702 | int ecb_cold |
2757 | ecb_cold int |
2703 | ev_version_minor (void) EV_THROW |
2758 | ev_version_minor (void) EV_NOEXCEPT |
2704 | { |
2759 | { |
2705 | return EV_VERSION_MINOR; |
2760 | return EV_VERSION_MINOR; |
2706 | } |
2761 | } |
2707 | |
2762 | |
2708 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2763 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2709 | int inline_size ecb_cold |
2764 | inline_size ecb_cold int |
2710 | enable_secure (void) |
2765 | enable_secure (void) |
2711 | { |
2766 | { |
2712 | #ifdef _WIN32 |
2767 | #ifdef _WIN32 |
2713 | return 0; |
2768 | return 0; |
2714 | #else |
2769 | #else |
2715 | return getuid () != geteuid () |
2770 | return getuid () != geteuid () |
2716 | || getgid () != getegid (); |
2771 | || getgid () != getegid (); |
2717 | #endif |
2772 | #endif |
2718 | } |
2773 | } |
2719 | |
2774 | |
2720 | unsigned int ecb_cold |
2775 | ecb_cold |
|
|
2776 | unsigned int |
2721 | ev_supported_backends (void) EV_THROW |
2777 | ev_supported_backends (void) EV_NOEXCEPT |
2722 | { |
2778 | { |
2723 | unsigned int flags = 0; |
2779 | unsigned int flags = 0; |
2724 | |
2780 | |
2725 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2781 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2726 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2782 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2727 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2783 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2784 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
2728 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2785 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2729 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2786 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2730 | |
2787 | |
2731 | return flags; |
2788 | return flags; |
2732 | } |
2789 | } |
2733 | |
2790 | |
2734 | unsigned int ecb_cold |
2791 | ecb_cold |
|
|
2792 | unsigned int |
2735 | ev_recommended_backends (void) EV_THROW |
2793 | ev_recommended_backends (void) EV_NOEXCEPT |
2736 | { |
2794 | { |
2737 | unsigned int flags = ev_supported_backends (); |
2795 | unsigned int flags = ev_supported_backends (); |
2738 | |
2796 | |
2739 | #ifndef __NetBSD__ |
2797 | #ifndef __NetBSD__ |
2740 | /* kqueue is borked on everything but netbsd apparently */ |
2798 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2748 | #endif |
2806 | #endif |
2749 | #ifdef __FreeBSD__ |
2807 | #ifdef __FreeBSD__ |
2750 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2808 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2751 | #endif |
2809 | #endif |
2752 | |
2810 | |
|
|
2811 | /* TODO: linuxaio is very experimental */ |
|
|
2812 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2813 | |
2753 | return flags; |
2814 | return flags; |
2754 | } |
2815 | } |
2755 | |
2816 | |
2756 | unsigned int ecb_cold |
2817 | ecb_cold |
|
|
2818 | unsigned int |
2757 | ev_embeddable_backends (void) EV_THROW |
2819 | ev_embeddable_backends (void) EV_NOEXCEPT |
2758 | { |
2820 | { |
2759 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2821 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2760 | |
2822 | |
2761 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2823 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2762 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2824 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2764 | |
2826 | |
2765 | return flags; |
2827 | return flags; |
2766 | } |
2828 | } |
2767 | |
2829 | |
2768 | unsigned int |
2830 | unsigned int |
2769 | ev_backend (EV_P) EV_THROW |
2831 | ev_backend (EV_P) EV_NOEXCEPT |
2770 | { |
2832 | { |
2771 | return backend; |
2833 | return backend; |
2772 | } |
2834 | } |
2773 | |
2835 | |
2774 | #if EV_FEATURE_API |
2836 | #if EV_FEATURE_API |
2775 | unsigned int |
2837 | unsigned int |
2776 | ev_iteration (EV_P) EV_THROW |
2838 | ev_iteration (EV_P) EV_NOEXCEPT |
2777 | { |
2839 | { |
2778 | return loop_count; |
2840 | return loop_count; |
2779 | } |
2841 | } |
2780 | |
2842 | |
2781 | unsigned int |
2843 | unsigned int |
2782 | ev_depth (EV_P) EV_THROW |
2844 | ev_depth (EV_P) EV_NOEXCEPT |
2783 | { |
2845 | { |
2784 | return loop_depth; |
2846 | return loop_depth; |
2785 | } |
2847 | } |
2786 | |
2848 | |
2787 | void |
2849 | void |
2788 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2850 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2789 | { |
2851 | { |
2790 | io_blocktime = interval; |
2852 | io_blocktime = interval; |
2791 | } |
2853 | } |
2792 | |
2854 | |
2793 | void |
2855 | void |
2794 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2856 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2795 | { |
2857 | { |
2796 | timeout_blocktime = interval; |
2858 | timeout_blocktime = interval; |
2797 | } |
2859 | } |
2798 | |
2860 | |
2799 | void |
2861 | void |
2800 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2862 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2801 | { |
2863 | { |
2802 | userdata = data; |
2864 | userdata = data; |
2803 | } |
2865 | } |
2804 | |
2866 | |
2805 | void * |
2867 | void * |
2806 | ev_userdata (EV_P) EV_THROW |
2868 | ev_userdata (EV_P) EV_NOEXCEPT |
2807 | { |
2869 | { |
2808 | return userdata; |
2870 | return userdata; |
2809 | } |
2871 | } |
2810 | |
2872 | |
2811 | void |
2873 | void |
2812 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
2874 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2813 | { |
2875 | { |
2814 | invoke_cb = invoke_pending_cb; |
2876 | invoke_cb = invoke_pending_cb; |
2815 | } |
2877 | } |
2816 | |
2878 | |
2817 | void |
2879 | void |
2818 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2880 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2819 | { |
2881 | { |
2820 | release_cb = release; |
2882 | release_cb = release; |
2821 | acquire_cb = acquire; |
2883 | acquire_cb = acquire; |
2822 | } |
2884 | } |
2823 | #endif |
2885 | #endif |
2824 | |
2886 | |
2825 | /* initialise a loop structure, must be zero-initialised */ |
2887 | /* initialise a loop structure, must be zero-initialised */ |
2826 | static void noinline ecb_cold |
2888 | noinline ecb_cold |
|
|
2889 | static void |
2827 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2890 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2828 | { |
2891 | { |
2829 | if (!backend) |
2892 | if (!backend) |
2830 | { |
2893 | { |
2831 | origflags = flags; |
2894 | origflags = flags; |
2832 | |
2895 | |
… | |
… | |
2890 | |
2953 | |
2891 | if (!(flags & EVBACKEND_MASK)) |
2954 | if (!(flags & EVBACKEND_MASK)) |
2892 | flags |= ev_recommended_backends (); |
2955 | flags |= ev_recommended_backends (); |
2893 | |
2956 | |
2894 | #if EV_USE_IOCP |
2957 | #if EV_USE_IOCP |
2895 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2958 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2896 | #endif |
2959 | #endif |
2897 | #if EV_USE_PORT |
2960 | #if EV_USE_PORT |
2898 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2961 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2899 | #endif |
2962 | #endif |
2900 | #if EV_USE_KQUEUE |
2963 | #if EV_USE_KQUEUE |
2901 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
2964 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
2965 | #endif |
|
|
2966 | #if EV_USE_LINUXAIO |
|
|
2967 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2902 | #endif |
2968 | #endif |
2903 | #if EV_USE_EPOLL |
2969 | #if EV_USE_EPOLL |
2904 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2970 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2905 | #endif |
2971 | #endif |
2906 | #if EV_USE_POLL |
2972 | #if EV_USE_POLL |
2907 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2973 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2908 | #endif |
2974 | #endif |
2909 | #if EV_USE_SELECT |
2975 | #if EV_USE_SELECT |
2910 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
2976 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2911 | #endif |
2977 | #endif |
2912 | |
2978 | |
2913 | ev_prepare_init (&pending_w, pendingcb); |
2979 | ev_prepare_init (&pending_w, pendingcb); |
2914 | |
2980 | |
2915 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2981 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2918 | #endif |
2984 | #endif |
2919 | } |
2985 | } |
2920 | } |
2986 | } |
2921 | |
2987 | |
2922 | /* free up a loop structure */ |
2988 | /* free up a loop structure */ |
2923 | void ecb_cold |
2989 | ecb_cold |
|
|
2990 | void |
2924 | ev_loop_destroy (EV_P) |
2991 | ev_loop_destroy (EV_P) |
2925 | { |
2992 | { |
2926 | int i; |
2993 | int i; |
2927 | |
2994 | |
2928 | #if EV_MULTIPLICITY |
2995 | #if EV_MULTIPLICITY |
… | |
… | |
2969 | |
3036 | |
2970 | if (backend_fd >= 0) |
3037 | if (backend_fd >= 0) |
2971 | close (backend_fd); |
3038 | close (backend_fd); |
2972 | |
3039 | |
2973 | #if EV_USE_IOCP |
3040 | #if EV_USE_IOCP |
2974 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3041 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2975 | #endif |
3042 | #endif |
2976 | #if EV_USE_PORT |
3043 | #if EV_USE_PORT |
2977 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3044 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
2978 | #endif |
3045 | #endif |
2979 | #if EV_USE_KQUEUE |
3046 | #if EV_USE_KQUEUE |
2980 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3047 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3048 | #endif |
|
|
3049 | #if EV_USE_LINUXAIO |
|
|
3050 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
2981 | #endif |
3051 | #endif |
2982 | #if EV_USE_EPOLL |
3052 | #if EV_USE_EPOLL |
2983 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3053 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
2984 | #endif |
3054 | #endif |
2985 | #if EV_USE_POLL |
3055 | #if EV_USE_POLL |
2986 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3056 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
2987 | #endif |
3057 | #endif |
2988 | #if EV_USE_SELECT |
3058 | #if EV_USE_SELECT |
2989 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3059 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
2990 | #endif |
3060 | #endif |
2991 | |
3061 | |
2992 | for (i = NUMPRI; i--; ) |
3062 | for (i = NUMPRI; i--; ) |
2993 | { |
3063 | { |
2994 | array_free (pending, [i]); |
3064 | array_free (pending, [i]); |
… | |
… | |
3036 | |
3106 | |
3037 | inline_size void |
3107 | inline_size void |
3038 | loop_fork (EV_P) |
3108 | loop_fork (EV_P) |
3039 | { |
3109 | { |
3040 | #if EV_USE_PORT |
3110 | #if EV_USE_PORT |
3041 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3111 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3042 | #endif |
3112 | #endif |
3043 | #if EV_USE_KQUEUE |
3113 | #if EV_USE_KQUEUE |
3044 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3114 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3115 | #endif |
|
|
3116 | #if EV_USE_LINUXAIO |
|
|
3117 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3045 | #endif |
3118 | #endif |
3046 | #if EV_USE_EPOLL |
3119 | #if EV_USE_EPOLL |
3047 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3120 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3048 | #endif |
3121 | #endif |
3049 | #if EV_USE_INOTIFY |
3122 | #if EV_USE_INOTIFY |
3050 | infy_fork (EV_A); |
3123 | infy_fork (EV_A); |
3051 | #endif |
3124 | #endif |
3052 | |
3125 | |
… | |
… | |
3070 | postfork = 0; |
3143 | postfork = 0; |
3071 | } |
3144 | } |
3072 | |
3145 | |
3073 | #if EV_MULTIPLICITY |
3146 | #if EV_MULTIPLICITY |
3074 | |
3147 | |
|
|
3148 | ecb_cold |
3075 | struct ev_loop * ecb_cold |
3149 | struct ev_loop * |
3076 | ev_loop_new (unsigned int flags) EV_THROW |
3150 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3077 | { |
3151 | { |
3078 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3152 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3079 | |
3153 | |
3080 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3154 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3081 | loop_init (EV_A_ flags); |
3155 | loop_init (EV_A_ flags); |
… | |
… | |
3088 | } |
3162 | } |
3089 | |
3163 | |
3090 | #endif /* multiplicity */ |
3164 | #endif /* multiplicity */ |
3091 | |
3165 | |
3092 | #if EV_VERIFY |
3166 | #if EV_VERIFY |
3093 | static void noinline ecb_cold |
3167 | noinline ecb_cold |
|
|
3168 | static void |
3094 | verify_watcher (EV_P_ W w) |
3169 | verify_watcher (EV_P_ W w) |
3095 | { |
3170 | { |
3096 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3171 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3097 | |
3172 | |
3098 | if (w->pending) |
3173 | if (w->pending) |
3099 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3174 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3100 | } |
3175 | } |
3101 | |
3176 | |
3102 | static void noinline ecb_cold |
3177 | noinline ecb_cold |
|
|
3178 | static void |
3103 | verify_heap (EV_P_ ANHE *heap, int N) |
3179 | verify_heap (EV_P_ ANHE *heap, int N) |
3104 | { |
3180 | { |
3105 | int i; |
3181 | int i; |
3106 | |
3182 | |
3107 | for (i = HEAP0; i < N + HEAP0; ++i) |
3183 | for (i = HEAP0; i < N + HEAP0; ++i) |
… | |
… | |
3112 | |
3188 | |
3113 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3189 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3114 | } |
3190 | } |
3115 | } |
3191 | } |
3116 | |
3192 | |
3117 | static void noinline ecb_cold |
3193 | noinline ecb_cold |
|
|
3194 | static void |
3118 | array_verify (EV_P_ W *ws, int cnt) |
3195 | array_verify (EV_P_ W *ws, int cnt) |
3119 | { |
3196 | { |
3120 | while (cnt--) |
3197 | while (cnt--) |
3121 | { |
3198 | { |
3122 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
3199 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
… | |
… | |
3125 | } |
3202 | } |
3126 | #endif |
3203 | #endif |
3127 | |
3204 | |
3128 | #if EV_FEATURE_API |
3205 | #if EV_FEATURE_API |
3129 | void ecb_cold |
3206 | void ecb_cold |
3130 | ev_verify (EV_P) EV_THROW |
3207 | ev_verify (EV_P) EV_NOEXCEPT |
3131 | { |
3208 | { |
3132 | #if EV_VERIFY |
3209 | #if EV_VERIFY |
3133 | int i; |
3210 | int i; |
3134 | WL w, w2; |
3211 | WL w, w2; |
3135 | |
3212 | |
… | |
… | |
3211 | #endif |
3288 | #endif |
3212 | } |
3289 | } |
3213 | #endif |
3290 | #endif |
3214 | |
3291 | |
3215 | #if EV_MULTIPLICITY |
3292 | #if EV_MULTIPLICITY |
|
|
3293 | ecb_cold |
3216 | struct ev_loop * ecb_cold |
3294 | struct ev_loop * |
3217 | #else |
3295 | #else |
3218 | int |
3296 | int |
3219 | #endif |
3297 | #endif |
3220 | ev_default_loop (unsigned int flags) EV_THROW |
3298 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3221 | { |
3299 | { |
3222 | if (!ev_default_loop_ptr) |
3300 | if (!ev_default_loop_ptr) |
3223 | { |
3301 | { |
3224 | #if EV_MULTIPLICITY |
3302 | #if EV_MULTIPLICITY |
3225 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3303 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3244 | |
3322 | |
3245 | return ev_default_loop_ptr; |
3323 | return ev_default_loop_ptr; |
3246 | } |
3324 | } |
3247 | |
3325 | |
3248 | void |
3326 | void |
3249 | ev_loop_fork (EV_P) EV_THROW |
3327 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3250 | { |
3328 | { |
3251 | postfork = 1; |
3329 | postfork = 1; |
3252 | } |
3330 | } |
3253 | |
3331 | |
3254 | /*****************************************************************************/ |
3332 | /*****************************************************************************/ |
… | |
… | |
3258 | { |
3336 | { |
3259 | EV_CB_INVOKE ((W)w, revents); |
3337 | EV_CB_INVOKE ((W)w, revents); |
3260 | } |
3338 | } |
3261 | |
3339 | |
3262 | unsigned int |
3340 | unsigned int |
3263 | ev_pending_count (EV_P) EV_THROW |
3341 | ev_pending_count (EV_P) EV_NOEXCEPT |
3264 | { |
3342 | { |
3265 | int pri; |
3343 | int pri; |
3266 | unsigned int count = 0; |
3344 | unsigned int count = 0; |
3267 | |
3345 | |
3268 | for (pri = NUMPRI; pri--; ) |
3346 | for (pri = NUMPRI; pri--; ) |
3269 | count += pendingcnt [pri]; |
3347 | count += pendingcnt [pri]; |
3270 | |
3348 | |
3271 | return count; |
3349 | return count; |
3272 | } |
3350 | } |
3273 | |
3351 | |
3274 | void noinline |
3352 | noinline |
|
|
3353 | void |
3275 | ev_invoke_pending (EV_P) |
3354 | ev_invoke_pending (EV_P) |
3276 | { |
3355 | { |
3277 | pendingpri = NUMPRI; |
3356 | pendingpri = NUMPRI; |
3278 | |
3357 | |
3279 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3358 | do |
3280 | { |
3359 | { |
3281 | --pendingpri; |
3360 | --pendingpri; |
3282 | |
3361 | |
|
|
3362 | /* pendingpri possibly gets modified in the inner loop */ |
3283 | while (pendingcnt [pendingpri]) |
3363 | while (pendingcnt [pendingpri]) |
3284 | { |
3364 | { |
3285 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3365 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3286 | |
3366 | |
3287 | p->w->pending = 0; |
3367 | p->w->pending = 0; |
3288 | EV_CB_INVOKE (p->w, p->events); |
3368 | EV_CB_INVOKE (p->w, p->events); |
3289 | EV_FREQUENT_CHECK; |
3369 | EV_FREQUENT_CHECK; |
3290 | } |
3370 | } |
3291 | } |
3371 | } |
|
|
3372 | while (pendingpri); |
3292 | } |
3373 | } |
3293 | |
3374 | |
3294 | #if EV_IDLE_ENABLE |
3375 | #if EV_IDLE_ENABLE |
3295 | /* make idle watchers pending. this handles the "call-idle */ |
3376 | /* make idle watchers pending. this handles the "call-idle */ |
3296 | /* only when higher priorities are idle" logic */ |
3377 | /* only when higher priorities are idle" logic */ |
… | |
… | |
3354 | } |
3435 | } |
3355 | } |
3436 | } |
3356 | |
3437 | |
3357 | #if EV_PERIODIC_ENABLE |
3438 | #if EV_PERIODIC_ENABLE |
3358 | |
3439 | |
3359 | static void noinline |
3440 | noinline |
|
|
3441 | static void |
3360 | periodic_recalc (EV_P_ ev_periodic *w) |
3442 | periodic_recalc (EV_P_ ev_periodic *w) |
3361 | { |
3443 | { |
3362 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3444 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3363 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3445 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3364 | |
3446 | |
… | |
… | |
3422 | } |
3504 | } |
3423 | } |
3505 | } |
3424 | |
3506 | |
3425 | /* simply recalculate all periodics */ |
3507 | /* simply recalculate all periodics */ |
3426 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3508 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3427 | static void noinline ecb_cold |
3509 | noinline ecb_cold |
|
|
3510 | static void |
3428 | periodics_reschedule (EV_P) |
3511 | periodics_reschedule (EV_P) |
3429 | { |
3512 | { |
3430 | int i; |
3513 | int i; |
3431 | |
3514 | |
3432 | /* adjust periodics after time jump */ |
3515 | /* adjust periodics after time jump */ |
… | |
… | |
3445 | reheap (periodics, periodiccnt); |
3528 | reheap (periodics, periodiccnt); |
3446 | } |
3529 | } |
3447 | #endif |
3530 | #endif |
3448 | |
3531 | |
3449 | /* adjust all timers by a given offset */ |
3532 | /* adjust all timers by a given offset */ |
3450 | static void noinline ecb_cold |
3533 | noinline ecb_cold |
|
|
3534 | static void |
3451 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3535 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3452 | { |
3536 | { |
3453 | int i; |
3537 | int i; |
3454 | |
3538 | |
3455 | for (i = 0; i < timercnt; ++i) |
3539 | for (i = 0; i < timercnt; ++i) |
… | |
… | |
3702 | |
3786 | |
3703 | return activecnt; |
3787 | return activecnt; |
3704 | } |
3788 | } |
3705 | |
3789 | |
3706 | void |
3790 | void |
3707 | ev_break (EV_P_ int how) EV_THROW |
3791 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3708 | { |
3792 | { |
3709 | loop_done = how; |
3793 | loop_done = how; |
3710 | } |
3794 | } |
3711 | |
3795 | |
3712 | void |
3796 | void |
3713 | ev_ref (EV_P) EV_THROW |
3797 | ev_ref (EV_P) EV_NOEXCEPT |
3714 | { |
3798 | { |
3715 | ++activecnt; |
3799 | ++activecnt; |
3716 | } |
3800 | } |
3717 | |
3801 | |
3718 | void |
3802 | void |
3719 | ev_unref (EV_P) EV_THROW |
3803 | ev_unref (EV_P) EV_NOEXCEPT |
3720 | { |
3804 | { |
3721 | --activecnt; |
3805 | --activecnt; |
3722 | } |
3806 | } |
3723 | |
3807 | |
3724 | void |
3808 | void |
3725 | ev_now_update (EV_P) EV_THROW |
3809 | ev_now_update (EV_P) EV_NOEXCEPT |
3726 | { |
3810 | { |
3727 | time_update (EV_A_ 1e100); |
3811 | time_update (EV_A_ 1e100); |
3728 | } |
3812 | } |
3729 | |
3813 | |
3730 | void |
3814 | void |
3731 | ev_suspend (EV_P) EV_THROW |
3815 | ev_suspend (EV_P) EV_NOEXCEPT |
3732 | { |
3816 | { |
3733 | ev_now_update (EV_A); |
3817 | ev_now_update (EV_A); |
3734 | } |
3818 | } |
3735 | |
3819 | |
3736 | void |
3820 | void |
3737 | ev_resume (EV_P) EV_THROW |
3821 | ev_resume (EV_P) EV_NOEXCEPT |
3738 | { |
3822 | { |
3739 | ev_tstamp mn_prev = mn_now; |
3823 | ev_tstamp mn_prev = mn_now; |
3740 | |
3824 | |
3741 | ev_now_update (EV_A); |
3825 | ev_now_update (EV_A); |
3742 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3826 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3781 | w->pending = 0; |
3865 | w->pending = 0; |
3782 | } |
3866 | } |
3783 | } |
3867 | } |
3784 | |
3868 | |
3785 | int |
3869 | int |
3786 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3870 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3787 | { |
3871 | { |
3788 | W w_ = (W)w; |
3872 | W w_ = (W)w; |
3789 | int pending = w_->pending; |
3873 | int pending = w_->pending; |
3790 | |
3874 | |
3791 | if (expect_true (pending)) |
3875 | if (expect_true (pending)) |
… | |
… | |
3823 | w->active = 0; |
3907 | w->active = 0; |
3824 | } |
3908 | } |
3825 | |
3909 | |
3826 | /*****************************************************************************/ |
3910 | /*****************************************************************************/ |
3827 | |
3911 | |
3828 | void noinline |
3912 | noinline |
|
|
3913 | void |
3829 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3914 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3830 | { |
3915 | { |
3831 | int fd = w->fd; |
3916 | int fd = w->fd; |
3832 | |
3917 | |
3833 | if (expect_false (ev_is_active (w))) |
3918 | if (expect_false (ev_is_active (w))) |
3834 | return; |
3919 | return; |
… | |
… | |
3837 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3922 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3838 | |
3923 | |
3839 | EV_FREQUENT_CHECK; |
3924 | EV_FREQUENT_CHECK; |
3840 | |
3925 | |
3841 | ev_start (EV_A_ (W)w, 1); |
3926 | ev_start (EV_A_ (W)w, 1); |
3842 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3927 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3843 | wlist_add (&anfds[fd].head, (WL)w); |
3928 | wlist_add (&anfds[fd].head, (WL)w); |
3844 | |
3929 | |
3845 | /* common bug, apparently */ |
3930 | /* common bug, apparently */ |
3846 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3931 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3847 | |
3932 | |
… | |
… | |
3849 | w->events &= ~EV__IOFDSET; |
3934 | w->events &= ~EV__IOFDSET; |
3850 | |
3935 | |
3851 | EV_FREQUENT_CHECK; |
3936 | EV_FREQUENT_CHECK; |
3852 | } |
3937 | } |
3853 | |
3938 | |
3854 | void noinline |
3939 | noinline |
|
|
3940 | void |
3855 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3941 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3856 | { |
3942 | { |
3857 | clear_pending (EV_A_ (W)w); |
3943 | clear_pending (EV_A_ (W)w); |
3858 | if (expect_false (!ev_is_active (w))) |
3944 | if (expect_false (!ev_is_active (w))) |
3859 | return; |
3945 | return; |
3860 | |
3946 | |
… | |
… | |
3868 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3954 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3869 | |
3955 | |
3870 | EV_FREQUENT_CHECK; |
3956 | EV_FREQUENT_CHECK; |
3871 | } |
3957 | } |
3872 | |
3958 | |
3873 | void noinline |
3959 | noinline |
|
|
3960 | void |
3874 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3961 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3875 | { |
3962 | { |
3876 | if (expect_false (ev_is_active (w))) |
3963 | if (expect_false (ev_is_active (w))) |
3877 | return; |
3964 | return; |
3878 | |
3965 | |
3879 | ev_at (w) += mn_now; |
3966 | ev_at (w) += mn_now; |
… | |
… | |
3882 | |
3969 | |
3883 | EV_FREQUENT_CHECK; |
3970 | EV_FREQUENT_CHECK; |
3884 | |
3971 | |
3885 | ++timercnt; |
3972 | ++timercnt; |
3886 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3973 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3887 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
3974 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3888 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3975 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3889 | ANHE_at_cache (timers [ev_active (w)]); |
3976 | ANHE_at_cache (timers [ev_active (w)]); |
3890 | upheap (timers, ev_active (w)); |
3977 | upheap (timers, ev_active (w)); |
3891 | |
3978 | |
3892 | EV_FREQUENT_CHECK; |
3979 | EV_FREQUENT_CHECK; |
3893 | |
3980 | |
3894 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3981 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3895 | } |
3982 | } |
3896 | |
3983 | |
3897 | void noinline |
3984 | noinline |
|
|
3985 | void |
3898 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3986 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3899 | { |
3987 | { |
3900 | clear_pending (EV_A_ (W)w); |
3988 | clear_pending (EV_A_ (W)w); |
3901 | if (expect_false (!ev_is_active (w))) |
3989 | if (expect_false (!ev_is_active (w))) |
3902 | return; |
3990 | return; |
3903 | |
3991 | |
… | |
… | |
3922 | ev_stop (EV_A_ (W)w); |
4010 | ev_stop (EV_A_ (W)w); |
3923 | |
4011 | |
3924 | EV_FREQUENT_CHECK; |
4012 | EV_FREQUENT_CHECK; |
3925 | } |
4013 | } |
3926 | |
4014 | |
3927 | void noinline |
4015 | noinline |
|
|
4016 | void |
3928 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4017 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3929 | { |
4018 | { |
3930 | EV_FREQUENT_CHECK; |
4019 | EV_FREQUENT_CHECK; |
3931 | |
4020 | |
3932 | clear_pending (EV_A_ (W)w); |
4021 | clear_pending (EV_A_ (W)w); |
3933 | |
4022 | |
… | |
… | |
3950 | |
4039 | |
3951 | EV_FREQUENT_CHECK; |
4040 | EV_FREQUENT_CHECK; |
3952 | } |
4041 | } |
3953 | |
4042 | |
3954 | ev_tstamp |
4043 | ev_tstamp |
3955 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4044 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3956 | { |
4045 | { |
3957 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4046 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3958 | } |
4047 | } |
3959 | |
4048 | |
3960 | #if EV_PERIODIC_ENABLE |
4049 | #if EV_PERIODIC_ENABLE |
3961 | void noinline |
4050 | noinline |
|
|
4051 | void |
3962 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4052 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3963 | { |
4053 | { |
3964 | if (expect_false (ev_is_active (w))) |
4054 | if (expect_false (ev_is_active (w))) |
3965 | return; |
4055 | return; |
3966 | |
4056 | |
3967 | if (w->reschedule_cb) |
4057 | if (w->reschedule_cb) |
… | |
… | |
3976 | |
4066 | |
3977 | EV_FREQUENT_CHECK; |
4067 | EV_FREQUENT_CHECK; |
3978 | |
4068 | |
3979 | ++periodiccnt; |
4069 | ++periodiccnt; |
3980 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4070 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
3981 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4071 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
3982 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4072 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
3983 | ANHE_at_cache (periodics [ev_active (w)]); |
4073 | ANHE_at_cache (periodics [ev_active (w)]); |
3984 | upheap (periodics, ev_active (w)); |
4074 | upheap (periodics, ev_active (w)); |
3985 | |
4075 | |
3986 | EV_FREQUENT_CHECK; |
4076 | EV_FREQUENT_CHECK; |
3987 | |
4077 | |
3988 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4078 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3989 | } |
4079 | } |
3990 | |
4080 | |
3991 | void noinline |
4081 | noinline |
|
|
4082 | void |
3992 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4083 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3993 | { |
4084 | { |
3994 | clear_pending (EV_A_ (W)w); |
4085 | clear_pending (EV_A_ (W)w); |
3995 | if (expect_false (!ev_is_active (w))) |
4086 | if (expect_false (!ev_is_active (w))) |
3996 | return; |
4087 | return; |
3997 | |
4088 | |
… | |
… | |
4014 | ev_stop (EV_A_ (W)w); |
4105 | ev_stop (EV_A_ (W)w); |
4015 | |
4106 | |
4016 | EV_FREQUENT_CHECK; |
4107 | EV_FREQUENT_CHECK; |
4017 | } |
4108 | } |
4018 | |
4109 | |
4019 | void noinline |
4110 | noinline |
|
|
4111 | void |
4020 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4112 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4021 | { |
4113 | { |
4022 | /* TODO: use adjustheap and recalculation */ |
4114 | /* TODO: use adjustheap and recalculation */ |
4023 | ev_periodic_stop (EV_A_ w); |
4115 | ev_periodic_stop (EV_A_ w); |
4024 | ev_periodic_start (EV_A_ w); |
4116 | ev_periodic_start (EV_A_ w); |
4025 | } |
4117 | } |
… | |
… | |
4029 | # define SA_RESTART 0 |
4121 | # define SA_RESTART 0 |
4030 | #endif |
4122 | #endif |
4031 | |
4123 | |
4032 | #if EV_SIGNAL_ENABLE |
4124 | #if EV_SIGNAL_ENABLE |
4033 | |
4125 | |
4034 | void noinline |
4126 | noinline |
|
|
4127 | void |
4035 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4128 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4036 | { |
4129 | { |
4037 | if (expect_false (ev_is_active (w))) |
4130 | if (expect_false (ev_is_active (w))) |
4038 | return; |
4131 | return; |
4039 | |
4132 | |
4040 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4133 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
4111 | } |
4204 | } |
4112 | |
4205 | |
4113 | EV_FREQUENT_CHECK; |
4206 | EV_FREQUENT_CHECK; |
4114 | } |
4207 | } |
4115 | |
4208 | |
4116 | void noinline |
4209 | noinline |
|
|
4210 | void |
4117 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4211 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4118 | { |
4212 | { |
4119 | clear_pending (EV_A_ (W)w); |
4213 | clear_pending (EV_A_ (W)w); |
4120 | if (expect_false (!ev_is_active (w))) |
4214 | if (expect_false (!ev_is_active (w))) |
4121 | return; |
4215 | return; |
4122 | |
4216 | |
… | |
… | |
4153 | #endif |
4247 | #endif |
4154 | |
4248 | |
4155 | #if EV_CHILD_ENABLE |
4249 | #if EV_CHILD_ENABLE |
4156 | |
4250 | |
4157 | void |
4251 | void |
4158 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4252 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4159 | { |
4253 | { |
4160 | #if EV_MULTIPLICITY |
4254 | #if EV_MULTIPLICITY |
4161 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4255 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4162 | #endif |
4256 | #endif |
4163 | if (expect_false (ev_is_active (w))) |
4257 | if (expect_false (ev_is_active (w))) |
… | |
… | |
4170 | |
4264 | |
4171 | EV_FREQUENT_CHECK; |
4265 | EV_FREQUENT_CHECK; |
4172 | } |
4266 | } |
4173 | |
4267 | |
4174 | void |
4268 | void |
4175 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4269 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4176 | { |
4270 | { |
4177 | clear_pending (EV_A_ (W)w); |
4271 | clear_pending (EV_A_ (W)w); |
4178 | if (expect_false (!ev_is_active (w))) |
4272 | if (expect_false (!ev_is_active (w))) |
4179 | return; |
4273 | return; |
4180 | |
4274 | |
… | |
… | |
4197 | |
4291 | |
4198 | #define DEF_STAT_INTERVAL 5.0074891 |
4292 | #define DEF_STAT_INTERVAL 5.0074891 |
4199 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4293 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4200 | #define MIN_STAT_INTERVAL 0.1074891 |
4294 | #define MIN_STAT_INTERVAL 0.1074891 |
4201 | |
4295 | |
4202 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4296 | noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4203 | |
4297 | |
4204 | #if EV_USE_INOTIFY |
4298 | #if EV_USE_INOTIFY |
4205 | |
4299 | |
4206 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4300 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4207 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4301 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4208 | |
4302 | |
4209 | static void noinline |
4303 | noinline |
|
|
4304 | static void |
4210 | infy_add (EV_P_ ev_stat *w) |
4305 | infy_add (EV_P_ ev_stat *w) |
4211 | { |
4306 | { |
4212 | w->wd = inotify_add_watch (fs_fd, w->path, |
4307 | w->wd = inotify_add_watch (fs_fd, w->path, |
4213 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4308 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4214 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
4309 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
… | |
… | |
4278 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4373 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4279 | ev_timer_again (EV_A_ &w->timer); |
4374 | ev_timer_again (EV_A_ &w->timer); |
4280 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4375 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4281 | } |
4376 | } |
4282 | |
4377 | |
4283 | static void noinline |
4378 | noinline |
|
|
4379 | static void |
4284 | infy_del (EV_P_ ev_stat *w) |
4380 | infy_del (EV_P_ ev_stat *w) |
4285 | { |
4381 | { |
4286 | int slot; |
4382 | int slot; |
4287 | int wd = w->wd; |
4383 | int wd = w->wd; |
4288 | |
4384 | |
… | |
… | |
4295 | |
4391 | |
4296 | /* remove this watcher, if others are watching it, they will rearm */ |
4392 | /* remove this watcher, if others are watching it, they will rearm */ |
4297 | inotify_rm_watch (fs_fd, wd); |
4393 | inotify_rm_watch (fs_fd, wd); |
4298 | } |
4394 | } |
4299 | |
4395 | |
4300 | static void noinline |
4396 | noinline |
|
|
4397 | static void |
4301 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4398 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4302 | { |
4399 | { |
4303 | if (slot < 0) |
4400 | if (slot < 0) |
4304 | /* overflow, need to check for all hash slots */ |
4401 | /* overflow, need to check for all hash slots */ |
4305 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
4402 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
… | |
… | |
4341 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4438 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4342 | ofs += sizeof (struct inotify_event) + ev->len; |
4439 | ofs += sizeof (struct inotify_event) + ev->len; |
4343 | } |
4440 | } |
4344 | } |
4441 | } |
4345 | |
4442 | |
4346 | inline_size void ecb_cold |
4443 | inline_size ecb_cold |
|
|
4444 | void |
4347 | ev_check_2625 (EV_P) |
4445 | ev_check_2625 (EV_P) |
4348 | { |
4446 | { |
4349 | /* kernels < 2.6.25 are borked |
4447 | /* kernels < 2.6.25 are borked |
4350 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4448 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4351 | */ |
4449 | */ |
… | |
… | |
4441 | #else |
4539 | #else |
4442 | # define EV_LSTAT(p,b) lstat (p, b) |
4540 | # define EV_LSTAT(p,b) lstat (p, b) |
4443 | #endif |
4541 | #endif |
4444 | |
4542 | |
4445 | void |
4543 | void |
4446 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4544 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4447 | { |
4545 | { |
4448 | if (lstat (w->path, &w->attr) < 0) |
4546 | if (lstat (w->path, &w->attr) < 0) |
4449 | w->attr.st_nlink = 0; |
4547 | w->attr.st_nlink = 0; |
4450 | else if (!w->attr.st_nlink) |
4548 | else if (!w->attr.st_nlink) |
4451 | w->attr.st_nlink = 1; |
4549 | w->attr.st_nlink = 1; |
4452 | } |
4550 | } |
4453 | |
4551 | |
4454 | static void noinline |
4552 | noinline |
|
|
4553 | static void |
4455 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4554 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4456 | { |
4555 | { |
4457 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4556 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4458 | |
4557 | |
4459 | ev_statdata prev = w->attr; |
4558 | ev_statdata prev = w->attr; |
… | |
… | |
4490 | ev_feed_event (EV_A_ w, EV_STAT); |
4589 | ev_feed_event (EV_A_ w, EV_STAT); |
4491 | } |
4590 | } |
4492 | } |
4591 | } |
4493 | |
4592 | |
4494 | void |
4593 | void |
4495 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4594 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4496 | { |
4595 | { |
4497 | if (expect_false (ev_is_active (w))) |
4596 | if (expect_false (ev_is_active (w))) |
4498 | return; |
4597 | return; |
4499 | |
4598 | |
4500 | ev_stat_stat (EV_A_ w); |
4599 | ev_stat_stat (EV_A_ w); |
… | |
… | |
4521 | |
4620 | |
4522 | EV_FREQUENT_CHECK; |
4621 | EV_FREQUENT_CHECK; |
4523 | } |
4622 | } |
4524 | |
4623 | |
4525 | void |
4624 | void |
4526 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4625 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4527 | { |
4626 | { |
4528 | clear_pending (EV_A_ (W)w); |
4627 | clear_pending (EV_A_ (W)w); |
4529 | if (expect_false (!ev_is_active (w))) |
4628 | if (expect_false (!ev_is_active (w))) |
4530 | return; |
4629 | return; |
4531 | |
4630 | |
… | |
… | |
4547 | } |
4646 | } |
4548 | #endif |
4647 | #endif |
4549 | |
4648 | |
4550 | #if EV_IDLE_ENABLE |
4649 | #if EV_IDLE_ENABLE |
4551 | void |
4650 | void |
4552 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4651 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4553 | { |
4652 | { |
4554 | if (expect_false (ev_is_active (w))) |
4653 | if (expect_false (ev_is_active (w))) |
4555 | return; |
4654 | return; |
4556 | |
4655 | |
4557 | pri_adjust (EV_A_ (W)w); |
4656 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
4562 | int active = ++idlecnt [ABSPRI (w)]; |
4661 | int active = ++idlecnt [ABSPRI (w)]; |
4563 | |
4662 | |
4564 | ++idleall; |
4663 | ++idleall; |
4565 | ev_start (EV_A_ (W)w, active); |
4664 | ev_start (EV_A_ (W)w, active); |
4566 | |
4665 | |
4567 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4666 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4568 | idles [ABSPRI (w)][active - 1] = w; |
4667 | idles [ABSPRI (w)][active - 1] = w; |
4569 | } |
4668 | } |
4570 | |
4669 | |
4571 | EV_FREQUENT_CHECK; |
4670 | EV_FREQUENT_CHECK; |
4572 | } |
4671 | } |
4573 | |
4672 | |
4574 | void |
4673 | void |
4575 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4674 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4576 | { |
4675 | { |
4577 | clear_pending (EV_A_ (W)w); |
4676 | clear_pending (EV_A_ (W)w); |
4578 | if (expect_false (!ev_is_active (w))) |
4677 | if (expect_false (!ev_is_active (w))) |
4579 | return; |
4678 | return; |
4580 | |
4679 | |
… | |
… | |
4594 | } |
4693 | } |
4595 | #endif |
4694 | #endif |
4596 | |
4695 | |
4597 | #if EV_PREPARE_ENABLE |
4696 | #if EV_PREPARE_ENABLE |
4598 | void |
4697 | void |
4599 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4698 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4600 | { |
4699 | { |
4601 | if (expect_false (ev_is_active (w))) |
4700 | if (expect_false (ev_is_active (w))) |
4602 | return; |
4701 | return; |
4603 | |
4702 | |
4604 | EV_FREQUENT_CHECK; |
4703 | EV_FREQUENT_CHECK; |
4605 | |
4704 | |
4606 | ev_start (EV_A_ (W)w, ++preparecnt); |
4705 | ev_start (EV_A_ (W)w, ++preparecnt); |
4607 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4706 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4608 | prepares [preparecnt - 1] = w; |
4707 | prepares [preparecnt - 1] = w; |
4609 | |
4708 | |
4610 | EV_FREQUENT_CHECK; |
4709 | EV_FREQUENT_CHECK; |
4611 | } |
4710 | } |
4612 | |
4711 | |
4613 | void |
4712 | void |
4614 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4713 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4615 | { |
4714 | { |
4616 | clear_pending (EV_A_ (W)w); |
4715 | clear_pending (EV_A_ (W)w); |
4617 | if (expect_false (!ev_is_active (w))) |
4716 | if (expect_false (!ev_is_active (w))) |
4618 | return; |
4717 | return; |
4619 | |
4718 | |
… | |
… | |
4632 | } |
4731 | } |
4633 | #endif |
4732 | #endif |
4634 | |
4733 | |
4635 | #if EV_CHECK_ENABLE |
4734 | #if EV_CHECK_ENABLE |
4636 | void |
4735 | void |
4637 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4736 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4638 | { |
4737 | { |
4639 | if (expect_false (ev_is_active (w))) |
4738 | if (expect_false (ev_is_active (w))) |
4640 | return; |
4739 | return; |
4641 | |
4740 | |
4642 | EV_FREQUENT_CHECK; |
4741 | EV_FREQUENT_CHECK; |
4643 | |
4742 | |
4644 | ev_start (EV_A_ (W)w, ++checkcnt); |
4743 | ev_start (EV_A_ (W)w, ++checkcnt); |
4645 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4744 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4646 | checks [checkcnt - 1] = w; |
4745 | checks [checkcnt - 1] = w; |
4647 | |
4746 | |
4648 | EV_FREQUENT_CHECK; |
4747 | EV_FREQUENT_CHECK; |
4649 | } |
4748 | } |
4650 | |
4749 | |
4651 | void |
4750 | void |
4652 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4751 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4653 | { |
4752 | { |
4654 | clear_pending (EV_A_ (W)w); |
4753 | clear_pending (EV_A_ (W)w); |
4655 | if (expect_false (!ev_is_active (w))) |
4754 | if (expect_false (!ev_is_active (w))) |
4656 | return; |
4755 | return; |
4657 | |
4756 | |
… | |
… | |
4669 | EV_FREQUENT_CHECK; |
4768 | EV_FREQUENT_CHECK; |
4670 | } |
4769 | } |
4671 | #endif |
4770 | #endif |
4672 | |
4771 | |
4673 | #if EV_EMBED_ENABLE |
4772 | #if EV_EMBED_ENABLE |
4674 | void noinline |
4773 | noinline |
|
|
4774 | void |
4675 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4775 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4676 | { |
4776 | { |
4677 | ev_run (w->other, EVRUN_NOWAIT); |
4777 | ev_run (w->other, EVRUN_NOWAIT); |
4678 | } |
4778 | } |
4679 | |
4779 | |
4680 | static void |
4780 | static void |
… | |
… | |
4728 | ev_idle_stop (EV_A_ idle); |
4828 | ev_idle_stop (EV_A_ idle); |
4729 | } |
4829 | } |
4730 | #endif |
4830 | #endif |
4731 | |
4831 | |
4732 | void |
4832 | void |
4733 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4833 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4734 | { |
4834 | { |
4735 | if (expect_false (ev_is_active (w))) |
4835 | if (expect_false (ev_is_active (w))) |
4736 | return; |
4836 | return; |
4737 | |
4837 | |
4738 | { |
4838 | { |
… | |
… | |
4759 | |
4859 | |
4760 | EV_FREQUENT_CHECK; |
4860 | EV_FREQUENT_CHECK; |
4761 | } |
4861 | } |
4762 | |
4862 | |
4763 | void |
4863 | void |
4764 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4864 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4765 | { |
4865 | { |
4766 | clear_pending (EV_A_ (W)w); |
4866 | clear_pending (EV_A_ (W)w); |
4767 | if (expect_false (!ev_is_active (w))) |
4867 | if (expect_false (!ev_is_active (w))) |
4768 | return; |
4868 | return; |
4769 | |
4869 | |
… | |
… | |
4779 | } |
4879 | } |
4780 | #endif |
4880 | #endif |
4781 | |
4881 | |
4782 | #if EV_FORK_ENABLE |
4882 | #if EV_FORK_ENABLE |
4783 | void |
4883 | void |
4784 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4884 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4785 | { |
4885 | { |
4786 | if (expect_false (ev_is_active (w))) |
4886 | if (expect_false (ev_is_active (w))) |
4787 | return; |
4887 | return; |
4788 | |
4888 | |
4789 | EV_FREQUENT_CHECK; |
4889 | EV_FREQUENT_CHECK; |
4790 | |
4890 | |
4791 | ev_start (EV_A_ (W)w, ++forkcnt); |
4891 | ev_start (EV_A_ (W)w, ++forkcnt); |
4792 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
4892 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4793 | forks [forkcnt - 1] = w; |
4893 | forks [forkcnt - 1] = w; |
4794 | |
4894 | |
4795 | EV_FREQUENT_CHECK; |
4895 | EV_FREQUENT_CHECK; |
4796 | } |
4896 | } |
4797 | |
4897 | |
4798 | void |
4898 | void |
4799 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4899 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4800 | { |
4900 | { |
4801 | clear_pending (EV_A_ (W)w); |
4901 | clear_pending (EV_A_ (W)w); |
4802 | if (expect_false (!ev_is_active (w))) |
4902 | if (expect_false (!ev_is_active (w))) |
4803 | return; |
4903 | return; |
4804 | |
4904 | |
… | |
… | |
4817 | } |
4917 | } |
4818 | #endif |
4918 | #endif |
4819 | |
4919 | |
4820 | #if EV_CLEANUP_ENABLE |
4920 | #if EV_CLEANUP_ENABLE |
4821 | void |
4921 | void |
4822 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4922 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4823 | { |
4923 | { |
4824 | if (expect_false (ev_is_active (w))) |
4924 | if (expect_false (ev_is_active (w))) |
4825 | return; |
4925 | return; |
4826 | |
4926 | |
4827 | EV_FREQUENT_CHECK; |
4927 | EV_FREQUENT_CHECK; |
4828 | |
4928 | |
4829 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4929 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4830 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
4930 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4831 | cleanups [cleanupcnt - 1] = w; |
4931 | cleanups [cleanupcnt - 1] = w; |
4832 | |
4932 | |
4833 | /* cleanup watchers should never keep a refcount on the loop */ |
4933 | /* cleanup watchers should never keep a refcount on the loop */ |
4834 | ev_unref (EV_A); |
4934 | ev_unref (EV_A); |
4835 | EV_FREQUENT_CHECK; |
4935 | EV_FREQUENT_CHECK; |
4836 | } |
4936 | } |
4837 | |
4937 | |
4838 | void |
4938 | void |
4839 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4939 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4840 | { |
4940 | { |
4841 | clear_pending (EV_A_ (W)w); |
4941 | clear_pending (EV_A_ (W)w); |
4842 | if (expect_false (!ev_is_active (w))) |
4942 | if (expect_false (!ev_is_active (w))) |
4843 | return; |
4943 | return; |
4844 | |
4944 | |
… | |
… | |
4858 | } |
4958 | } |
4859 | #endif |
4959 | #endif |
4860 | |
4960 | |
4861 | #if EV_ASYNC_ENABLE |
4961 | #if EV_ASYNC_ENABLE |
4862 | void |
4962 | void |
4863 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4963 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4864 | { |
4964 | { |
4865 | if (expect_false (ev_is_active (w))) |
4965 | if (expect_false (ev_is_active (w))) |
4866 | return; |
4966 | return; |
4867 | |
4967 | |
4868 | w->sent = 0; |
4968 | w->sent = 0; |
… | |
… | |
4870 | evpipe_init (EV_A); |
4970 | evpipe_init (EV_A); |
4871 | |
4971 | |
4872 | EV_FREQUENT_CHECK; |
4972 | EV_FREQUENT_CHECK; |
4873 | |
4973 | |
4874 | ev_start (EV_A_ (W)w, ++asynccnt); |
4974 | ev_start (EV_A_ (W)w, ++asynccnt); |
4875 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
4975 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4876 | asyncs [asynccnt - 1] = w; |
4976 | asyncs [asynccnt - 1] = w; |
4877 | |
4977 | |
4878 | EV_FREQUENT_CHECK; |
4978 | EV_FREQUENT_CHECK; |
4879 | } |
4979 | } |
4880 | |
4980 | |
4881 | void |
4981 | void |
4882 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4982 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4883 | { |
4983 | { |
4884 | clear_pending (EV_A_ (W)w); |
4984 | clear_pending (EV_A_ (W)w); |
4885 | if (expect_false (!ev_is_active (w))) |
4985 | if (expect_false (!ev_is_active (w))) |
4886 | return; |
4986 | return; |
4887 | |
4987 | |
… | |
… | |
4898 | |
4998 | |
4899 | EV_FREQUENT_CHECK; |
4999 | EV_FREQUENT_CHECK; |
4900 | } |
5000 | } |
4901 | |
5001 | |
4902 | void |
5002 | void |
4903 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
5003 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4904 | { |
5004 | { |
4905 | w->sent = 1; |
5005 | w->sent = 1; |
4906 | evpipe_write (EV_A_ &async_pending); |
5006 | evpipe_write (EV_A_ &async_pending); |
4907 | } |
5007 | } |
4908 | #endif |
5008 | #endif |
… | |
… | |
4945 | |
5045 | |
4946 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5046 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4947 | } |
5047 | } |
4948 | |
5048 | |
4949 | void |
5049 | void |
4950 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5050 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4951 | { |
5051 | { |
4952 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5052 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4953 | |
|
|
4954 | if (expect_false (!once)) |
|
|
4955 | { |
|
|
4956 | cb (EV_ERROR | EV_READ | EV_WRITE | EV_TIMER, arg); |
|
|
4957 | return; |
|
|
4958 | } |
|
|
4959 | |
5053 | |
4960 | once->cb = cb; |
5054 | once->cb = cb; |
4961 | once->arg = arg; |
5055 | once->arg = arg; |
4962 | |
5056 | |
4963 | ev_init (&once->io, once_cb_io); |
5057 | ev_init (&once->io, once_cb_io); |
… | |
… | |
4976 | } |
5070 | } |
4977 | |
5071 | |
4978 | /*****************************************************************************/ |
5072 | /*****************************************************************************/ |
4979 | |
5073 | |
4980 | #if EV_WALK_ENABLE |
5074 | #if EV_WALK_ENABLE |
4981 | void ecb_cold |
5075 | ecb_cold |
|
|
5076 | void |
4982 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5077 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
4983 | { |
5078 | { |
4984 | int i, j; |
5079 | int i, j; |
4985 | ev_watcher_list *wl, *wn; |
5080 | ev_watcher_list *wl, *wn; |
4986 | |
5081 | |
4987 | if (types & (EV_IO | EV_EMBED)) |
5082 | if (types & (EV_IO | EV_EMBED)) |