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 | |
|
|
129 | # if HAVE_LINUX_FS_H && HAVE_SYS_TIMERFD_H && HAVE_KERNEL_RWF_T |
|
|
130 | # ifndef EV_USE_IOURING |
|
|
131 | # define EV_USE_IOURING EV_FEATURE_BACKENDS |
|
|
132 | # endif |
|
|
133 | # else |
|
|
134 | # undef EV_USE_IOURING |
|
|
135 | # define EV_USE_IOURING 0 |
|
|
136 | # endif |
|
|
137 | |
120 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
138 | # if HAVE_KQUEUE && HAVE_SYS_EVENT_H |
121 | # ifndef EV_USE_KQUEUE |
139 | # ifndef EV_USE_KQUEUE |
122 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
140 | # define EV_USE_KQUEUE EV_FEATURE_BACKENDS |
123 | # endif |
141 | # endif |
124 | # else |
142 | # else |
… | |
… | |
159 | # endif |
177 | # endif |
160 | # else |
178 | # else |
161 | # undef EV_USE_EVENTFD |
179 | # undef EV_USE_EVENTFD |
162 | # define EV_USE_EVENTFD 0 |
180 | # define EV_USE_EVENTFD 0 |
163 | # endif |
181 | # endif |
164 | |
182 | |
165 | #endif |
183 | #endif |
|
|
184 | |
|
|
185 | /* OS X, in its infinite idiocy, actually HARDCODES |
|
|
186 | * a limit of 1024 into their select. Where people have brains, |
|
|
187 | * OS X engineers apparently have a vacuum. Or maybe they were |
|
|
188 | * ordered to have a vacuum, or they do anything for money. |
|
|
189 | * This might help. Or not. |
|
|
190 | * Note that this must be defined early, as other include files |
|
|
191 | * will rely on this define as well. |
|
|
192 | */ |
|
|
193 | #define _DARWIN_UNLIMITED_SELECT 1 |
166 | |
194 | |
167 | #include <stdlib.h> |
195 | #include <stdlib.h> |
168 | #include <string.h> |
196 | #include <string.h> |
169 | #include <fcntl.h> |
197 | #include <fcntl.h> |
170 | #include <stddef.h> |
198 | #include <stddef.h> |
… | |
… | |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
236 | # ifndef EV_SELECT_IS_WINSOCKET |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
237 | # define EV_SELECT_IS_WINSOCKET 1 |
210 | # endif |
238 | # endif |
211 | # undef EV_AVOID_STDIO |
239 | # undef EV_AVOID_STDIO |
212 | #endif |
240 | #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 | |
241 | |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
242 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
223 | |
243 | |
224 | /* try to deduce the maximum number of signals on this platform */ |
244 | /* try to deduce the maximum number of signals on this platform */ |
225 | #if defined EV_NSIG |
245 | #if defined EV_NSIG |
… | |
… | |
313 | |
333 | |
314 | #ifndef EV_USE_PORT |
334 | #ifndef EV_USE_PORT |
315 | # define EV_USE_PORT 0 |
335 | # define EV_USE_PORT 0 |
316 | #endif |
336 | #endif |
317 | |
337 | |
|
|
338 | #ifndef EV_USE_LINUXAIO |
|
|
339 | # if __linux /* libev currently assumes linux/aio_abi.h is always available on linux */ |
|
|
340 | # define EV_USE_LINUXAIO 1 |
|
|
341 | # else |
|
|
342 | # define EV_USE_LINUXAIO 0 |
|
|
343 | # endif |
|
|
344 | #endif |
|
|
345 | |
|
|
346 | #ifndef EV_USE_IOURING |
|
|
347 | # if __linux /* later checks might disable again */ |
|
|
348 | # define EV_USE_IOURING 1 |
|
|
349 | # else |
|
|
350 | # define EV_USE_IOURING 0 |
|
|
351 | # endif |
|
|
352 | #endif |
|
|
353 | |
318 | #ifndef EV_USE_INOTIFY |
354 | #ifndef EV_USE_INOTIFY |
319 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
355 | # if __linux && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 4)) |
320 | # define EV_USE_INOTIFY EV_FEATURE_OS |
356 | # define EV_USE_INOTIFY EV_FEATURE_OS |
321 | # else |
357 | # else |
322 | # define EV_USE_INOTIFY 0 |
358 | # define EV_USE_INOTIFY 0 |
… | |
… | |
363 | |
399 | |
364 | #ifndef EV_HEAP_CACHE_AT |
400 | #ifndef EV_HEAP_CACHE_AT |
365 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
401 | # define EV_HEAP_CACHE_AT EV_FEATURE_DATA |
366 | #endif |
402 | #endif |
367 | |
403 | |
368 | #ifdef ANDROID |
404 | #ifdef __ANDROID__ |
369 | /* supposedly, android doesn't typedef fd_mask */ |
405 | /* supposedly, android doesn't typedef fd_mask */ |
370 | # undef EV_USE_SELECT |
406 | # undef EV_USE_SELECT |
371 | # define EV_USE_SELECT 0 |
407 | # define EV_USE_SELECT 0 |
372 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
408 | /* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */ |
373 | # undef EV_USE_CLOCK_SYSCALL |
409 | # undef EV_USE_CLOCK_SYSCALL |
… | |
… | |
387 | # include <sys/syscall.h> |
423 | # include <sys/syscall.h> |
388 | # ifdef SYS_clock_gettime |
424 | # ifdef SYS_clock_gettime |
389 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
425 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
390 | # undef EV_USE_MONOTONIC |
426 | # undef EV_USE_MONOTONIC |
391 | # define EV_USE_MONOTONIC 1 |
427 | # define EV_USE_MONOTONIC 1 |
|
|
428 | # define EV_NEED_SYSCALL 1 |
392 | # else |
429 | # else |
393 | # undef EV_USE_CLOCK_SYSCALL |
430 | # undef EV_USE_CLOCK_SYSCALL |
394 | # define EV_USE_CLOCK_SYSCALL 0 |
431 | # define EV_USE_CLOCK_SYSCALL 0 |
395 | # endif |
432 | # endif |
396 | #endif |
433 | #endif |
… | |
… | |
410 | #if !EV_STAT_ENABLE |
447 | #if !EV_STAT_ENABLE |
411 | # undef EV_USE_INOTIFY |
448 | # undef EV_USE_INOTIFY |
412 | # define EV_USE_INOTIFY 0 |
449 | # define EV_USE_INOTIFY 0 |
413 | #endif |
450 | #endif |
414 | |
451 | |
|
|
452 | #if __linux && EV_USE_IOURING |
|
|
453 | # include <linux/version.h> |
|
|
454 | # if LINUX_VERSION_CODE < KERNEL_VERSION(4,14,0) |
|
|
455 | # undef EV_USE_IOURING |
|
|
456 | # define EV_USE_IOURING 0 |
|
|
457 | # endif |
|
|
458 | #endif |
|
|
459 | |
415 | #if !EV_USE_NANOSLEEP |
460 | #if !EV_USE_NANOSLEEP |
416 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
461 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
417 | # if !defined _WIN32 && !defined __hpux |
462 | # if !defined _WIN32 && !defined __hpux |
418 | # include <sys/select.h> |
463 | # include <sys/select.h> |
|
|
464 | # endif |
|
|
465 | #endif |
|
|
466 | |
|
|
467 | #if EV_USE_LINUXAIO |
|
|
468 | # include <sys/syscall.h> |
|
|
469 | # if SYS_io_getevents && EV_USE_EPOLL /* linuxaio backend requires epoll backend */ |
|
|
470 | # define EV_NEED_SYSCALL 1 |
|
|
471 | # else |
|
|
472 | # undef EV_USE_LINUXAIO |
|
|
473 | # define EV_USE_LINUXAIO 0 |
|
|
474 | # endif |
|
|
475 | #endif |
|
|
476 | |
|
|
477 | #if EV_USE_IOURING |
|
|
478 | # include <sys/syscall.h> |
|
|
479 | # if !SYS_io_uring_setup && __linux && !__alpha |
|
|
480 | # define SYS_io_uring_setup 425 |
|
|
481 | # define SYS_io_uring_enter 426 |
|
|
482 | # define SYS_io_uring_wregister 427 |
|
|
483 | # endif |
|
|
484 | # if SYS_io_uring_setup && EV_USE_EPOLL /* iouring backend requires epoll backend */ |
|
|
485 | # define EV_NEED_SYSCALL 1 |
|
|
486 | # else |
|
|
487 | # undef EV_USE_IOURING |
|
|
488 | # define EV_USE_IOURING 0 |
419 | # endif |
489 | # endif |
420 | #endif |
490 | #endif |
421 | |
491 | |
422 | #if EV_USE_INOTIFY |
492 | #if EV_USE_INOTIFY |
423 | # include <sys/statfs.h> |
493 | # include <sys/statfs.h> |
… | |
… | |
465 | uint32_t ssi_signo; |
535 | uint32_t ssi_signo; |
466 | char pad[128 - sizeof (uint32_t)]; |
536 | char pad[128 - sizeof (uint32_t)]; |
467 | }; |
537 | }; |
468 | #endif |
538 | #endif |
469 | |
539 | |
470 | /**/ |
540 | /*****************************************************************************/ |
471 | |
541 | |
472 | #if EV_VERIFY >= 3 |
542 | #if EV_VERIFY >= 3 |
473 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
543 | # define EV_FREQUENT_CHECK ev_verify (EV_A) |
474 | #else |
544 | #else |
475 | # define EV_FREQUENT_CHECK do { } while (0) |
545 | # define EV_FREQUENT_CHECK do { } while (0) |
… | |
… | |
480 | * This value is good at least till the year 4000. |
550 | * This value is good at least till the year 4000. |
481 | */ |
551 | */ |
482 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
552 | #define MIN_INTERVAL 0.0001220703125 /* 1/2**13, good till 4000 */ |
483 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
553 | /*#define MIN_INTERVAL 0.00000095367431640625 /* 1/2**20, good till 2200 */ |
484 | |
554 | |
485 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
555 | #define MIN_TIMEJUMP 1. /* minimum timejump that gets detected (if monotonic clock available) */ |
486 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
556 | #define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ |
487 | |
557 | |
|
|
558 | /* find a portable timestamp that is "always" in the future but fits into time_t. |
|
|
559 | * this is quite hard, and we are mostly guessing - we handle 32 bit signed/unsigned time_t, |
|
|
560 | * and sizes larger than 32 bit, and maybe the unlikely floating point time_t */ |
|
|
561 | #define EV_TSTAMP_HUGE \ |
|
|
562 | (sizeof (time_t) >= 8 ? 10000000000000. \ |
|
|
563 | : 0 < (time_t)4294967295 ? 4294967295. \ |
|
|
564 | : 2147483647.) \ |
|
|
565 | |
|
|
566 | #ifndef EV_TS_CONST |
|
|
567 | # define EV_TS_CONST(nv) nv |
|
|
568 | # define EV_TS_TO_MSEC(a) a * 1e3 + 0.9999 |
|
|
569 | # define EV_TS_FROM_USEC(us) us * 1e-6 |
488 | #define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
570 | # define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) |
489 | #define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
571 | # define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) |
|
|
572 | # define EV_TV_GET(tv) ((tv).tv_sec + (tv).tv_usec * 1e-6) |
|
|
573 | # define EV_TS_GET(ts) ((ts).tv_sec + (ts).tv_nsec * 1e-9) |
|
|
574 | #endif |
490 | |
575 | |
491 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
576 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
492 | /* ECB.H BEGIN */ |
577 | /* ECB.H BEGIN */ |
493 | /* |
578 | /* |
494 | * libecb - http://software.schmorp.de/pkg/libecb |
579 | * libecb - http://software.schmorp.de/pkg/libecb |
… | |
… | |
532 | |
617 | |
533 | #ifndef ECB_H |
618 | #ifndef ECB_H |
534 | #define ECB_H |
619 | #define ECB_H |
535 | |
620 | |
536 | /* 16 bits major, 16 bits minor */ |
621 | /* 16 bits major, 16 bits minor */ |
537 | #define ECB_VERSION 0x00010005 |
622 | #define ECB_VERSION 0x00010006 |
538 | |
623 | |
539 | #ifdef _WIN32 |
624 | #ifdef _WIN32 |
540 | typedef signed char int8_t; |
625 | typedef signed char int8_t; |
541 | typedef unsigned char uint8_t; |
626 | typedef unsigned char uint8_t; |
542 | typedef signed short int16_t; |
627 | typedef signed short int16_t; |
… | |
… | |
607 | #define ECB_CLANG_EXTENSION(x) 0 |
692 | #define ECB_CLANG_EXTENSION(x) 0 |
608 | #endif |
693 | #endif |
609 | |
694 | |
610 | #define ECB_CPP (__cplusplus+0) |
695 | #define ECB_CPP (__cplusplus+0) |
611 | #define ECB_CPP11 (__cplusplus >= 201103L) |
696 | #define ECB_CPP11 (__cplusplus >= 201103L) |
|
|
697 | #define ECB_CPP14 (__cplusplus >= 201402L) |
|
|
698 | #define ECB_CPP17 (__cplusplus >= 201703L) |
612 | |
699 | |
613 | #if ECB_CPP |
700 | #if ECB_CPP |
614 | #define ECB_C 0 |
701 | #define ECB_C 0 |
615 | #define ECB_STDC_VERSION 0 |
702 | #define ECB_STDC_VERSION 0 |
616 | #else |
703 | #else |
… | |
… | |
618 | #define ECB_STDC_VERSION __STDC_VERSION__ |
705 | #define ECB_STDC_VERSION __STDC_VERSION__ |
619 | #endif |
706 | #endif |
620 | |
707 | |
621 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
708 | #define ECB_C99 (ECB_STDC_VERSION >= 199901L) |
622 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
709 | #define ECB_C11 (ECB_STDC_VERSION >= 201112L) |
|
|
710 | #define ECB_C17 (ECB_STDC_VERSION >= 201710L) |
623 | |
711 | |
624 | #if ECB_CPP |
712 | #if ECB_CPP |
625 | #define ECB_EXTERN_C extern "C" |
713 | #define ECB_EXTERN_C extern "C" |
626 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
714 | #define ECB_EXTERN_C_BEG ECB_EXTERN_C { |
627 | #define ECB_EXTERN_C_END } |
715 | #define ECB_EXTERN_C_END } |
… | |
… | |
653 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
741 | #include <intrin.h> /* fence functions _ReadBarrier, also bit search functions _BitScanReverse */ |
654 | #endif |
742 | #endif |
655 | |
743 | |
656 | #ifndef ECB_MEMORY_FENCE |
744 | #ifndef ECB_MEMORY_FENCE |
657 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
745 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
746 | #define ECB_MEMORY_FENCE_RELAXED __asm__ __volatile__ ("" : : : "memory") |
658 | #if __i386 || __i386__ |
747 | #if __i386 || __i386__ |
659 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
748 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
660 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
749 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
661 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
750 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
662 | #elif ECB_GCC_AMD64 |
751 | #elif ECB_GCC_AMD64 |
663 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
752 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
664 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
753 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("" : : : "memory") |
665 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") |
754 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("" : : : "memory") |
666 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
755 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
667 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
756 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
668 | #elif defined __ARM_ARCH_2__ \ |
757 | #elif defined __ARM_ARCH_2__ \ |
669 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
758 | || defined __ARM_ARCH_3__ || defined __ARM_ARCH_3M__ \ |
670 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
759 | || defined __ARM_ARCH_4__ || defined __ARM_ARCH_4T__ \ |
… | |
… | |
712 | #if ECB_GCC_VERSION(4,7) |
801 | #if ECB_GCC_VERSION(4,7) |
713 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
802 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
714 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
803 | #define ECB_MEMORY_FENCE __atomic_thread_fence (__ATOMIC_SEQ_CST) |
715 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
804 | #define ECB_MEMORY_FENCE_ACQUIRE __atomic_thread_fence (__ATOMIC_ACQUIRE) |
716 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
805 | #define ECB_MEMORY_FENCE_RELEASE __atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
806 | #define ECB_MEMORY_FENCE_RELAXED __atomic_thread_fence (__ATOMIC_RELAXED) |
717 | |
807 | |
718 | #elif ECB_CLANG_EXTENSION(c_atomic) |
808 | #elif ECB_CLANG_EXTENSION(c_atomic) |
719 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
809 | /* see comment below (stdatomic.h) about the C11 memory model. */ |
720 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
810 | #define ECB_MEMORY_FENCE __c11_atomic_thread_fence (__ATOMIC_SEQ_CST) |
721 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
811 | #define ECB_MEMORY_FENCE_ACQUIRE __c11_atomic_thread_fence (__ATOMIC_ACQUIRE) |
722 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
812 | #define ECB_MEMORY_FENCE_RELEASE __c11_atomic_thread_fence (__ATOMIC_RELEASE) |
|
|
813 | #define ECB_MEMORY_FENCE_RELAXED __c11_atomic_thread_fence (__ATOMIC_RELAXED) |
723 | |
814 | |
724 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
815 | #elif ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
725 | #define ECB_MEMORY_FENCE __sync_synchronize () |
816 | #define ECB_MEMORY_FENCE __sync_synchronize () |
726 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
817 | #elif _MSC_VER >= 1500 /* VC++ 2008 */ |
727 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
818 | /* apparently, microsoft broke all the memory barrier stuff in Visual Studio 2008... */ |
… | |
… | |
737 | #elif defined _WIN32 |
828 | #elif defined _WIN32 |
738 | #include <WinNT.h> |
829 | #include <WinNT.h> |
739 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
830 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
740 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
831 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
741 | #include <mbarrier.h> |
832 | #include <mbarrier.h> |
742 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
833 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
743 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
834 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_acq_barrier () |
744 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
835 | #define ECB_MEMORY_FENCE_RELEASE __machine_rel_barrier () |
|
|
836 | #define ECB_MEMORY_FENCE_RELAXED __compiler_barrier () |
745 | #elif __xlC__ |
837 | #elif __xlC__ |
746 | #define ECB_MEMORY_FENCE __sync () |
838 | #define ECB_MEMORY_FENCE __sync () |
747 | #endif |
839 | #endif |
748 | #endif |
840 | #endif |
749 | |
841 | |
750 | #ifndef ECB_MEMORY_FENCE |
842 | #ifndef ECB_MEMORY_FENCE |
751 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
843 | #if ECB_C11 && !defined __STDC_NO_ATOMICS__ |
752 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
844 | /* we assume that these memory fences work on all variables/all memory accesses, */ |
753 | /* not just C11 atomics and atomic accesses */ |
845 | /* not just C11 atomics and atomic accesses */ |
754 | #include <stdatomic.h> |
846 | #include <stdatomic.h> |
755 | /* Unfortunately, neither gcc 4.7 nor clang 3.1 generate any instructions for */ |
|
|
756 | /* any fence other than seq_cst, which isn't very efficient for us. */ |
|
|
757 | /* Why that is, we don't know - either the C11 memory model is quite useless */ |
|
|
758 | /* for most usages, or gcc and clang have a bug */ |
|
|
759 | /* I *currently* lean towards the latter, and inefficiently implement */ |
|
|
760 | /* all three of ecb's fences as a seq_cst fence */ |
|
|
761 | /* Update, gcc-4.8 generates mfence for all c++ fences, but nothing */ |
|
|
762 | /* for all __atomic_thread_fence's except seq_cst */ |
|
|
763 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
847 | #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_seq_cst) |
|
|
848 | #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire) |
|
|
849 | #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release) |
764 | #endif |
850 | #endif |
765 | #endif |
851 | #endif |
766 | |
852 | |
767 | #ifndef ECB_MEMORY_FENCE |
853 | #ifndef ECB_MEMORY_FENCE |
768 | #if !ECB_AVOID_PTHREADS |
854 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
786 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
872 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
787 | #endif |
873 | #endif |
788 | |
874 | |
789 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
875 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
790 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
876 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
|
|
877 | #endif |
|
|
878 | |
|
|
879 | #if !defined ECB_MEMORY_FENCE_RELAXED && defined ECB_MEMORY_FENCE |
|
|
880 | #define ECB_MEMORY_FENCE_RELAXED ECB_MEMORY_FENCE /* very heavy-handed */ |
791 | #endif |
881 | #endif |
792 | |
882 | |
793 | /*****************************************************************************/ |
883 | /*****************************************************************************/ |
794 | |
884 | |
795 | #if ECB_CPP |
885 | #if ECB_CPP |
… | |
… | |
1504 | /* ECB.H END */ |
1594 | /* ECB.H END */ |
1505 | |
1595 | |
1506 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1596 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
1507 | /* if your architecture doesn't need memory fences, e.g. because it is |
1597 | /* if your architecture doesn't need memory fences, e.g. because it is |
1508 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
1598 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
1509 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
1599 | * from multiple threads, then you can define ECB_NO_THREADS when compiling |
1510 | * libev, in which cases the memory fences become nops. |
1600 | * libev, in which cases the memory fences become nops. |
1511 | * alternatively, you can remove this #error and link against libpthread, |
1601 | * alternatively, you can remove this #error and link against libpthread, |
1512 | * which will then provide the memory fences. |
1602 | * which will then provide the memory fences. |
1513 | */ |
1603 | */ |
1514 | # error "memory fences not defined for your architecture, please report" |
1604 | # error "memory fences not defined for your architecture, please report" |
… | |
… | |
1518 | # define ECB_MEMORY_FENCE do { } while (0) |
1608 | # define ECB_MEMORY_FENCE do { } while (0) |
1519 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1609 | # define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
1520 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1610 | # define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
1521 | #endif |
1611 | #endif |
1522 | |
1612 | |
1523 | #define expect_false(cond) ecb_expect_false (cond) |
|
|
1524 | #define expect_true(cond) ecb_expect_true (cond) |
|
|
1525 | #define noinline ecb_noinline |
|
|
1526 | |
|
|
1527 | #define inline_size ecb_inline |
1613 | #define inline_size ecb_inline |
1528 | |
1614 | |
1529 | #if EV_FEATURE_CODE |
1615 | #if EV_FEATURE_CODE |
1530 | # define inline_speed ecb_inline |
1616 | # define inline_speed ecb_inline |
1531 | #else |
1617 | #else |
1532 | # define inline_speed static noinline |
1618 | # define inline_speed ecb_noinline static |
1533 | #endif |
1619 | #endif |
|
|
1620 | |
|
|
1621 | /*****************************************************************************/ |
|
|
1622 | /* raw syscall wrappers */ |
|
|
1623 | |
|
|
1624 | #if EV_NEED_SYSCALL |
|
|
1625 | |
|
|
1626 | #include <sys/syscall.h> |
|
|
1627 | |
|
|
1628 | /* |
|
|
1629 | * define some syscall wrappers for common architectures |
|
|
1630 | * this is mostly for nice looks during debugging, not performance. |
|
|
1631 | * our syscalls return < 0, not == -1, on error. which is good |
|
|
1632 | * enough for linux aio. |
|
|
1633 | * TODO: arm is also common nowadays, maybe even mips and x86 |
|
|
1634 | * TODO: after implementing this, it suddenly looks like overkill, but its hard to remove... |
|
|
1635 | */ |
|
|
1636 | #if __GNUC__ && __linux && ECB_AMD64 && !defined __OPTIMIZE_SIZE__ |
|
|
1637 | /* the costly errno access probably kills this for size optimisation */ |
|
|
1638 | |
|
|
1639 | #define ev_syscall(nr,narg,arg1,arg2,arg3,arg4,arg5,arg6) \ |
|
|
1640 | ({ \ |
|
|
1641 | long res; \ |
|
|
1642 | register unsigned long r6 __asm__ ("r9" ); \ |
|
|
1643 | register unsigned long r5 __asm__ ("r8" ); \ |
|
|
1644 | register unsigned long r4 __asm__ ("r10"); \ |
|
|
1645 | register unsigned long r3 __asm__ ("rdx"); \ |
|
|
1646 | register unsigned long r2 __asm__ ("rsi"); \ |
|
|
1647 | register unsigned long r1 __asm__ ("rdi"); \ |
|
|
1648 | if (narg >= 6) r6 = (unsigned long)(arg6); \ |
|
|
1649 | if (narg >= 5) r5 = (unsigned long)(arg5); \ |
|
|
1650 | if (narg >= 4) r4 = (unsigned long)(arg4); \ |
|
|
1651 | if (narg >= 3) r3 = (unsigned long)(arg3); \ |
|
|
1652 | if (narg >= 2) r2 = (unsigned long)(arg2); \ |
|
|
1653 | if (narg >= 1) r1 = (unsigned long)(arg1); \ |
|
|
1654 | __asm__ __volatile__ ( \ |
|
|
1655 | "syscall\n\t" \ |
|
|
1656 | : "=a" (res) \ |
|
|
1657 | : "0" (nr), "r" (r1), "r" (r2), "r" (r3), "r" (r4), "r" (r5) \ |
|
|
1658 | : "cc", "r11", "cx", "memory"); \ |
|
|
1659 | errno = -res; \ |
|
|
1660 | res; \ |
|
|
1661 | }) |
|
|
1662 | |
|
|
1663 | #endif |
|
|
1664 | |
|
|
1665 | #ifdef ev_syscall |
|
|
1666 | #define ev_syscall0(nr) ev_syscall (nr, 0, 0, 0, 0, 0, 0, 0) |
|
|
1667 | #define ev_syscall1(nr,arg1) ev_syscall (nr, 1, arg1, 0, 0, 0, 0, 0) |
|
|
1668 | #define ev_syscall2(nr,arg1,arg2) ev_syscall (nr, 2, arg1, arg2, 0, 0, 0, 0) |
|
|
1669 | #define ev_syscall3(nr,arg1,arg2,arg3) ev_syscall (nr, 3, arg1, arg2, arg3, 0, 0, 0) |
|
|
1670 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) ev_syscall (nr, 3, arg1, arg2, arg3, arg4, 0, 0) |
|
|
1671 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) ev_syscall (nr, 5, arg1, arg2, arg3, arg4, arg5, 0) |
|
|
1672 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) ev_syscall (nr, 6, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1673 | #else |
|
|
1674 | #define ev_syscall0(nr) syscall (nr) |
|
|
1675 | #define ev_syscall1(nr,arg1) syscall (nr, arg1) |
|
|
1676 | #define ev_syscall2(nr,arg1,arg2) syscall (nr, arg1, arg2) |
|
|
1677 | #define ev_syscall3(nr,arg1,arg2,arg3) syscall (nr, arg1, arg2, arg3) |
|
|
1678 | #define ev_syscall4(nr,arg1,arg2,arg3,arg4) syscall (nr, arg1, arg2, arg3, arg4) |
|
|
1679 | #define ev_syscall5(nr,arg1,arg2,arg3,arg4,arg5) syscall (nr, arg1, arg2, arg3, arg4, arg5) |
|
|
1680 | #define ev_syscall6(nr,arg1,arg2,arg3,arg4,arg5,arg6) syscall (nr, arg1, arg2, arg3, arg4, arg5,arg6) |
|
|
1681 | #endif |
|
|
1682 | |
|
|
1683 | #endif |
|
|
1684 | |
|
|
1685 | /*****************************************************************************/ |
1534 | |
1686 | |
1535 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1687 | #define NUMPRI (EV_MAXPRI - EV_MINPRI + 1) |
1536 | |
1688 | |
1537 | #if EV_MINPRI == EV_MAXPRI |
1689 | #if EV_MINPRI == EV_MAXPRI |
1538 | # define ABSPRI(w) (((W)w), 0) |
1690 | # define ABSPRI(w) (((W)w), 0) |
1539 | #else |
1691 | #else |
1540 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1692 | # define ABSPRI(w) (((W)w)->priority - EV_MINPRI) |
1541 | #endif |
1693 | #endif |
1542 | |
1694 | |
1543 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1695 | #define EMPTY /* required for microsofts broken pseudo-c compiler */ |
1544 | #define EMPTY2(a,b) /* used to suppress some warnings */ |
|
|
1545 | |
1696 | |
1546 | typedef ev_watcher *W; |
1697 | typedef ev_watcher *W; |
1547 | typedef ev_watcher_list *WL; |
1698 | typedef ev_watcher_list *WL; |
1548 | typedef ev_watcher_time *WT; |
1699 | typedef ev_watcher_time *WT; |
1549 | |
1700 | |
… | |
… | |
1574 | # include "ev_win32.c" |
1725 | # include "ev_win32.c" |
1575 | #endif |
1726 | #endif |
1576 | |
1727 | |
1577 | /*****************************************************************************/ |
1728 | /*****************************************************************************/ |
1578 | |
1729 | |
|
|
1730 | #if EV_USE_LINUXAIO |
|
|
1731 | # include <linux/aio_abi.h> /* probably only needed for aio_context_t */ |
|
|
1732 | #endif |
|
|
1733 | |
1579 | /* define a suitable floor function (only used by periodics atm) */ |
1734 | /* define a suitable floor function (only used by periodics atm) */ |
1580 | |
1735 | |
1581 | #if EV_USE_FLOOR |
1736 | #if EV_USE_FLOOR |
1582 | # include <math.h> |
1737 | # include <math.h> |
1583 | # define ev_floor(v) floor (v) |
1738 | # define ev_floor(v) floor (v) |
1584 | #else |
1739 | #else |
1585 | |
1740 | |
1586 | #include <float.h> |
1741 | #include <float.h> |
1587 | |
1742 | |
1588 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
1743 | /* a floor() replacement function, should be independent of ev_tstamp type */ |
|
|
1744 | ecb_noinline |
1589 | static ev_tstamp noinline |
1745 | static ev_tstamp |
1590 | ev_floor (ev_tstamp v) |
1746 | ev_floor (ev_tstamp v) |
1591 | { |
1747 | { |
1592 | /* the choice of shift factor is not terribly important */ |
1748 | /* the choice of shift factor is not terribly important */ |
1593 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1749 | #if FLT_RADIX != 2 /* assume FLT_RADIX == 10 */ |
1594 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1750 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 10000000000000000000. : 1000000000.; |
1595 | #else |
1751 | #else |
1596 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1752 | const ev_tstamp shift = sizeof (unsigned long) >= 8 ? 18446744073709551616. : 4294967296.; |
1597 | #endif |
1753 | #endif |
1598 | |
1754 | |
|
|
1755 | /* special treatment for negative arguments */ |
|
|
1756 | if (ecb_expect_false (v < 0.)) |
|
|
1757 | { |
|
|
1758 | ev_tstamp f = -ev_floor (-v); |
|
|
1759 | |
|
|
1760 | return f - (f == v ? 0 : 1); |
|
|
1761 | } |
|
|
1762 | |
1599 | /* argument too large for an unsigned long? */ |
1763 | /* argument too large for an unsigned long? then reduce it */ |
1600 | if (expect_false (v >= shift)) |
1764 | if (ecb_expect_false (v >= shift)) |
1601 | { |
1765 | { |
1602 | ev_tstamp f; |
1766 | ev_tstamp f; |
1603 | |
1767 | |
1604 | if (v == v - 1.) |
1768 | if (v == v - 1.) |
1605 | return v; /* very large number */ |
1769 | return v; /* very large numbers are assumed to be integer */ |
1606 | |
1770 | |
1607 | f = shift * ev_floor (v * (1. / shift)); |
1771 | f = shift * ev_floor (v * (1. / shift)); |
1608 | return f + ev_floor (v - f); |
1772 | return f + ev_floor (v - f); |
1609 | } |
1773 | } |
1610 | |
1774 | |
1611 | /* special treatment for negative args? */ |
|
|
1612 | if (expect_false (v < 0.)) |
|
|
1613 | { |
|
|
1614 | ev_tstamp f = -ev_floor (-v); |
|
|
1615 | |
|
|
1616 | return f - (f == v ? 0 : 1); |
|
|
1617 | } |
|
|
1618 | |
|
|
1619 | /* fits into an unsigned long */ |
1775 | /* fits into an unsigned long */ |
1620 | return (unsigned long)v; |
1776 | return (unsigned long)v; |
1621 | } |
1777 | } |
1622 | |
1778 | |
1623 | #endif |
1779 | #endif |
… | |
… | |
1626 | |
1782 | |
1627 | #ifdef __linux |
1783 | #ifdef __linux |
1628 | # include <sys/utsname.h> |
1784 | # include <sys/utsname.h> |
1629 | #endif |
1785 | #endif |
1630 | |
1786 | |
1631 | static unsigned int noinline ecb_cold |
1787 | ecb_noinline ecb_cold |
|
|
1788 | static unsigned int |
1632 | ev_linux_version (void) |
1789 | ev_linux_version (void) |
1633 | { |
1790 | { |
1634 | #ifdef __linux |
1791 | #ifdef __linux |
1635 | unsigned int v = 0; |
1792 | unsigned int v = 0; |
1636 | struct utsname buf; |
1793 | struct utsname buf; |
… | |
… | |
1665 | } |
1822 | } |
1666 | |
1823 | |
1667 | /*****************************************************************************/ |
1824 | /*****************************************************************************/ |
1668 | |
1825 | |
1669 | #if EV_AVOID_STDIO |
1826 | #if EV_AVOID_STDIO |
1670 | static void noinline ecb_cold |
1827 | ecb_noinline ecb_cold |
|
|
1828 | static void |
1671 | ev_printerr (const char *msg) |
1829 | ev_printerr (const char *msg) |
1672 | { |
1830 | { |
1673 | write (STDERR_FILENO, msg, strlen (msg)); |
1831 | write (STDERR_FILENO, msg, strlen (msg)); |
1674 | } |
1832 | } |
1675 | #endif |
1833 | #endif |
1676 | |
1834 | |
1677 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1835 | static void (*syserr_cb)(const char *msg) EV_NOEXCEPT; |
1678 | |
1836 | |
1679 | void ecb_cold |
1837 | ecb_cold |
|
|
1838 | void |
1680 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1839 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_NOEXCEPT) EV_NOEXCEPT |
1681 | { |
1840 | { |
1682 | syserr_cb = cb; |
1841 | syserr_cb = cb; |
1683 | } |
1842 | } |
1684 | |
1843 | |
1685 | static void noinline ecb_cold |
1844 | ecb_noinline ecb_cold |
|
|
1845 | static void |
1686 | ev_syserr (const char *msg) |
1846 | ev_syserr (const char *msg) |
1687 | { |
1847 | { |
1688 | if (!msg) |
1848 | if (!msg) |
1689 | msg = "(libev) system error"; |
1849 | msg = "(libev) system error"; |
1690 | |
1850 | |
… | |
… | |
1703 | abort (); |
1863 | abort (); |
1704 | } |
1864 | } |
1705 | } |
1865 | } |
1706 | |
1866 | |
1707 | static void * |
1867 | static void * |
1708 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1868 | ev_realloc_emul (void *ptr, long size) EV_NOEXCEPT |
1709 | { |
1869 | { |
1710 | /* some systems, notably openbsd and darwin, fail to properly |
1870 | /* some systems, notably openbsd and darwin, fail to properly |
1711 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1871 | * implement realloc (x, 0) (as required by both ansi c-89 and |
1712 | * the single unix specification, so work around them here. |
1872 | * the single unix specification, so work around them here. |
1713 | * recently, also (at least) fedora and debian started breaking it, |
1873 | * recently, also (at least) fedora and debian started breaking it, |
… | |
… | |
1719 | |
1879 | |
1720 | free (ptr); |
1880 | free (ptr); |
1721 | return 0; |
1881 | return 0; |
1722 | } |
1882 | } |
1723 | |
1883 | |
1724 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1884 | static void *(*alloc)(void *ptr, long size) EV_NOEXCEPT = ev_realloc_emul; |
1725 | |
1885 | |
1726 | void ecb_cold |
1886 | ecb_cold |
|
|
1887 | void |
1727 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1888 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_NOEXCEPT) EV_NOEXCEPT |
1728 | { |
1889 | { |
1729 | alloc = cb; |
1890 | alloc = cb; |
1730 | } |
1891 | } |
1731 | |
1892 | |
1732 | inline_speed void * |
1893 | inline_speed void * |
… | |
… | |
1759 | typedef struct |
1920 | typedef struct |
1760 | { |
1921 | { |
1761 | WL head; |
1922 | WL head; |
1762 | unsigned char events; /* the events watched for */ |
1923 | unsigned char events; /* the events watched for */ |
1763 | unsigned char reify; /* flag set when this ANFD needs reification (EV_ANFD_REIFY, EV__IOFDSET) */ |
1924 | 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 */ |
1925 | unsigned char emask; /* some backends store the actual kernel mask in here */ |
1765 | unsigned char unused; |
1926 | unsigned char eflags; /* flags field for use by backends */ |
1766 | #if EV_USE_EPOLL |
1927 | #if EV_USE_EPOLL |
1767 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1928 | unsigned int egen; /* generation counter to counter epoll bugs */ |
1768 | #endif |
1929 | #endif |
1769 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1930 | #if EV_SELECT_IS_WINSOCKET || EV_USE_IOCP |
1770 | SOCKET handle; |
1931 | SOCKET handle; |
… | |
… | |
1824 | static struct ev_loop default_loop_struct; |
1985 | static struct ev_loop default_loop_struct; |
1825 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1986 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1826 | |
1987 | |
1827 | #else |
1988 | #else |
1828 | |
1989 | |
1829 | EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */ |
1990 | EV_API_DECL ev_tstamp ev_rt_now = EV_TS_CONST (0.); /* needs to be initialised to make it a definition despite extern */ |
1830 | #define VAR(name,decl) static decl; |
1991 | #define VAR(name,decl) static decl; |
1831 | #include "ev_vars.h" |
1992 | #include "ev_vars.h" |
1832 | #undef VAR |
1993 | #undef VAR |
1833 | |
1994 | |
1834 | static int ev_default_loop_ptr; |
1995 | static int ev_default_loop_ptr; |
1835 | |
1996 | |
1836 | #endif |
1997 | #endif |
1837 | |
1998 | |
1838 | #if EV_FEATURE_API |
1999 | #if EV_FEATURE_API |
1839 | # define EV_RELEASE_CB if (expect_false (release_cb)) release_cb (EV_A) |
2000 | # define EV_RELEASE_CB if (ecb_expect_false (release_cb)) release_cb (EV_A) |
1840 | # define EV_ACQUIRE_CB if (expect_false (acquire_cb)) acquire_cb (EV_A) |
2001 | # define EV_ACQUIRE_CB if (ecb_expect_false (acquire_cb)) acquire_cb (EV_A) |
1841 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
2002 | # define EV_INVOKE_PENDING invoke_cb (EV_A) |
1842 | #else |
2003 | #else |
1843 | # define EV_RELEASE_CB (void)0 |
2004 | # define EV_RELEASE_CB (void)0 |
1844 | # define EV_ACQUIRE_CB (void)0 |
2005 | # define EV_ACQUIRE_CB (void)0 |
1845 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
2006 | # define EV_INVOKE_PENDING ev_invoke_pending (EV_A) |
… | |
… | |
1849 | |
2010 | |
1850 | /*****************************************************************************/ |
2011 | /*****************************************************************************/ |
1851 | |
2012 | |
1852 | #ifndef EV_HAVE_EV_TIME |
2013 | #ifndef EV_HAVE_EV_TIME |
1853 | ev_tstamp |
2014 | ev_tstamp |
1854 | ev_time (void) EV_THROW |
2015 | ev_time (void) EV_NOEXCEPT |
1855 | { |
2016 | { |
1856 | #if EV_USE_REALTIME |
2017 | #if EV_USE_REALTIME |
1857 | if (expect_true (have_realtime)) |
2018 | if (ecb_expect_true (have_realtime)) |
1858 | { |
2019 | { |
1859 | struct timespec ts; |
2020 | struct timespec ts; |
1860 | clock_gettime (CLOCK_REALTIME, &ts); |
2021 | clock_gettime (CLOCK_REALTIME, &ts); |
1861 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2022 | return EV_TS_GET (ts); |
1862 | } |
2023 | } |
1863 | #endif |
2024 | #endif |
1864 | |
2025 | |
|
|
2026 | { |
1865 | struct timeval tv; |
2027 | struct timeval tv; |
1866 | gettimeofday (&tv, 0); |
2028 | gettimeofday (&tv, 0); |
1867 | return tv.tv_sec + tv.tv_usec * 1e-6; |
2029 | return EV_TV_GET (tv); |
|
|
2030 | } |
1868 | } |
2031 | } |
1869 | #endif |
2032 | #endif |
1870 | |
2033 | |
1871 | inline_size ev_tstamp |
2034 | inline_size ev_tstamp |
1872 | get_clock (void) |
2035 | get_clock (void) |
1873 | { |
2036 | { |
1874 | #if EV_USE_MONOTONIC |
2037 | #if EV_USE_MONOTONIC |
1875 | if (expect_true (have_monotonic)) |
2038 | if (ecb_expect_true (have_monotonic)) |
1876 | { |
2039 | { |
1877 | struct timespec ts; |
2040 | struct timespec ts; |
1878 | clock_gettime (CLOCK_MONOTONIC, &ts); |
2041 | clock_gettime (CLOCK_MONOTONIC, &ts); |
1879 | return ts.tv_sec + ts.tv_nsec * 1e-9; |
2042 | return EV_TS_GET (ts); |
1880 | } |
2043 | } |
1881 | #endif |
2044 | #endif |
1882 | |
2045 | |
1883 | return ev_time (); |
2046 | return ev_time (); |
1884 | } |
2047 | } |
1885 | |
2048 | |
1886 | #if EV_MULTIPLICITY |
2049 | #if EV_MULTIPLICITY |
1887 | ev_tstamp |
2050 | ev_tstamp |
1888 | ev_now (EV_P) EV_THROW |
2051 | ev_now (EV_P) EV_NOEXCEPT |
1889 | { |
2052 | { |
1890 | return ev_rt_now; |
2053 | return ev_rt_now; |
1891 | } |
2054 | } |
1892 | #endif |
2055 | #endif |
1893 | |
2056 | |
1894 | void |
2057 | void |
1895 | ev_sleep (ev_tstamp delay) EV_THROW |
2058 | ev_sleep (ev_tstamp delay) EV_NOEXCEPT |
1896 | { |
2059 | { |
1897 | if (delay > 0.) |
2060 | if (delay > EV_TS_CONST (0.)) |
1898 | { |
2061 | { |
1899 | #if EV_USE_NANOSLEEP |
2062 | #if EV_USE_NANOSLEEP |
1900 | struct timespec ts; |
2063 | struct timespec ts; |
1901 | |
2064 | |
1902 | EV_TS_SET (ts, delay); |
2065 | EV_TS_SET (ts, delay); |
1903 | nanosleep (&ts, 0); |
2066 | nanosleep (&ts, 0); |
1904 | #elif defined _WIN32 |
2067 | #elif defined _WIN32 |
|
|
2068 | /* maybe this should round up, as ms is very low resolution */ |
|
|
2069 | /* compared to select (µs) or nanosleep (ns) */ |
1905 | Sleep ((unsigned long)(delay * 1e3)); |
2070 | Sleep ((unsigned long)(EV_TS_TO_MSEC (delay))); |
1906 | #else |
2071 | #else |
1907 | struct timeval tv; |
2072 | struct timeval tv; |
1908 | |
2073 | |
1909 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
2074 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1910 | /* something not guaranteed by newer posix versions, but guaranteed */ |
2075 | /* something not guaranteed by newer posix versions, but guaranteed */ |
… | |
… | |
1940 | } |
2105 | } |
1941 | |
2106 | |
1942 | return ncur; |
2107 | return ncur; |
1943 | } |
2108 | } |
1944 | |
2109 | |
1945 | static void * noinline ecb_cold |
2110 | ecb_noinline ecb_cold |
|
|
2111 | static void * |
1946 | array_realloc (int elem, void *base, int *cur, int cnt) |
2112 | array_realloc (int elem, void *base, int *cur, int cnt) |
1947 | { |
2113 | { |
1948 | *cur = array_nextsize (elem, *cur, cnt); |
2114 | *cur = array_nextsize (elem, *cur, cnt); |
1949 | return ev_realloc (base, elem * *cur); |
2115 | return ev_realloc (base, elem * *cur); |
1950 | } |
2116 | } |
1951 | |
2117 | |
|
|
2118 | #define array_needsize_noinit(base,offset,count) |
|
|
2119 | |
1952 | #define array_init_zero(base,count) \ |
2120 | #define array_needsize_zerofill(base,offset,count) \ |
1953 | memset ((void *)(base), 0, sizeof (*(base)) * (count)) |
2121 | memset ((void *)(base + offset), 0, sizeof (*(base)) * (count)) |
1954 | |
2122 | |
1955 | #define array_needsize(type,base,cur,cnt,init) \ |
2123 | #define array_needsize(type,base,cur,cnt,init) \ |
1956 | if (expect_false ((cnt) > (cur))) \ |
2124 | if (ecb_expect_false ((cnt) > (cur))) \ |
1957 | { \ |
2125 | { \ |
1958 | int ecb_unused ocur_ = (cur); \ |
2126 | ecb_unused int ocur_ = (cur); \ |
1959 | (base) = (type *)array_realloc \ |
2127 | (base) = (type *)array_realloc \ |
1960 | (sizeof (type), (base), &(cur), (cnt)); \ |
2128 | (sizeof (type), (base), &(cur), (cnt)); \ |
1961 | init ((base) + (ocur_), (cur) - ocur_); \ |
2129 | init ((base), ocur_, ((cur) - ocur_)); \ |
1962 | } |
2130 | } |
1963 | |
2131 | |
1964 | #if 0 |
2132 | #if 0 |
1965 | #define array_slim(type,stem) \ |
2133 | #define array_slim(type,stem) \ |
1966 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
2134 | if (stem ## max < array_roundsize (stem ## cnt >> 2)) \ |
… | |
… | |
1975 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
2143 | ev_free (stem ## s idx); stem ## cnt idx = stem ## max idx = 0; stem ## s idx = 0 |
1976 | |
2144 | |
1977 | /*****************************************************************************/ |
2145 | /*****************************************************************************/ |
1978 | |
2146 | |
1979 | /* dummy callback for pending events */ |
2147 | /* dummy callback for pending events */ |
1980 | static void noinline |
2148 | ecb_noinline |
|
|
2149 | static void |
1981 | pendingcb (EV_P_ ev_prepare *w, int revents) |
2150 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1982 | { |
2151 | { |
1983 | } |
2152 | } |
1984 | |
2153 | |
1985 | void noinline |
2154 | ecb_noinline |
|
|
2155 | void |
1986 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
2156 | ev_feed_event (EV_P_ void *w, int revents) EV_NOEXCEPT |
1987 | { |
2157 | { |
1988 | W w_ = (W)w; |
2158 | W w_ = (W)w; |
1989 | int pri = ABSPRI (w_); |
2159 | int pri = ABSPRI (w_); |
1990 | |
2160 | |
1991 | if (expect_false (w_->pending)) |
2161 | if (ecb_expect_false (w_->pending)) |
1992 | pendings [pri][w_->pending - 1].events |= revents; |
2162 | pendings [pri][w_->pending - 1].events |= revents; |
1993 | else |
2163 | else |
1994 | { |
2164 | { |
1995 | w_->pending = ++pendingcnt [pri]; |
2165 | w_->pending = ++pendingcnt [pri]; |
1996 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
2166 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, array_needsize_noinit); |
1997 | pendings [pri][w_->pending - 1].w = w_; |
2167 | pendings [pri][w_->pending - 1].w = w_; |
1998 | pendings [pri][w_->pending - 1].events = revents; |
2168 | pendings [pri][w_->pending - 1].events = revents; |
1999 | } |
2169 | } |
2000 | |
2170 | |
2001 | pendingpri = NUMPRI - 1; |
2171 | pendingpri = NUMPRI - 1; |
2002 | } |
2172 | } |
2003 | |
2173 | |
2004 | inline_speed void |
2174 | inline_speed void |
2005 | feed_reverse (EV_P_ W w) |
2175 | feed_reverse (EV_P_ W w) |
2006 | { |
2176 | { |
2007 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, EMPTY2); |
2177 | array_needsize (W, rfeeds, rfeedmax, rfeedcnt + 1, array_needsize_noinit); |
2008 | rfeeds [rfeedcnt++] = w; |
2178 | rfeeds [rfeedcnt++] = w; |
2009 | } |
2179 | } |
2010 | |
2180 | |
2011 | inline_size void |
2181 | inline_size void |
2012 | feed_reverse_done (EV_P_ int revents) |
2182 | feed_reverse_done (EV_P_ int revents) |
… | |
… | |
2047 | inline_speed void |
2217 | inline_speed void |
2048 | fd_event (EV_P_ int fd, int revents) |
2218 | fd_event (EV_P_ int fd, int revents) |
2049 | { |
2219 | { |
2050 | ANFD *anfd = anfds + fd; |
2220 | ANFD *anfd = anfds + fd; |
2051 | |
2221 | |
2052 | if (expect_true (!anfd->reify)) |
2222 | if (ecb_expect_true (!anfd->reify)) |
2053 | fd_event_nocheck (EV_A_ fd, revents); |
2223 | fd_event_nocheck (EV_A_ fd, revents); |
2054 | } |
2224 | } |
2055 | |
2225 | |
2056 | void |
2226 | void |
2057 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
2227 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_NOEXCEPT |
2058 | { |
2228 | { |
2059 | if (fd >= 0 && fd < anfdmax) |
2229 | if (fd >= 0 && fd < anfdmax) |
2060 | fd_event_nocheck (EV_A_ fd, revents); |
2230 | fd_event_nocheck (EV_A_ fd, revents); |
2061 | } |
2231 | } |
2062 | |
2232 | |
… | |
… | |
2099 | ev_io *w; |
2269 | ev_io *w; |
2100 | |
2270 | |
2101 | unsigned char o_events = anfd->events; |
2271 | unsigned char o_events = anfd->events; |
2102 | unsigned char o_reify = anfd->reify; |
2272 | unsigned char o_reify = anfd->reify; |
2103 | |
2273 | |
2104 | anfd->reify = 0; |
2274 | anfd->reify = 0; |
2105 | |
2275 | |
2106 | /*if (expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2276 | /*if (ecb_expect_true (o_reify & EV_ANFD_REIFY)) probably a deoptimisation */ |
2107 | { |
2277 | { |
2108 | anfd->events = 0; |
2278 | anfd->events = 0; |
2109 | |
2279 | |
2110 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2280 | for (w = (ev_io *)anfd->head; w; w = (ev_io *)((WL)w)->next) |
2111 | anfd->events |= (unsigned char)w->events; |
2281 | anfd->events |= (unsigned char)w->events; |
… | |
… | |
2120 | |
2290 | |
2121 | fdchangecnt = 0; |
2291 | fdchangecnt = 0; |
2122 | } |
2292 | } |
2123 | |
2293 | |
2124 | /* something about the given fd changed */ |
2294 | /* something about the given fd changed */ |
2125 | inline_size void |
2295 | inline_size |
|
|
2296 | void |
2126 | fd_change (EV_P_ int fd, int flags) |
2297 | fd_change (EV_P_ int fd, int flags) |
2127 | { |
2298 | { |
2128 | unsigned char reify = anfds [fd].reify; |
2299 | unsigned char reify = anfds [fd].reify; |
2129 | anfds [fd].reify |= flags; |
2300 | anfds [fd].reify |= flags; |
2130 | |
2301 | |
2131 | if (expect_true (!reify)) |
2302 | if (ecb_expect_true (!reify)) |
2132 | { |
2303 | { |
2133 | ++fdchangecnt; |
2304 | ++fdchangecnt; |
2134 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, EMPTY2); |
2305 | array_needsize (int, fdchanges, fdchangemax, fdchangecnt, array_needsize_noinit); |
2135 | fdchanges [fdchangecnt - 1] = fd; |
2306 | fdchanges [fdchangecnt - 1] = fd; |
2136 | } |
2307 | } |
2137 | } |
2308 | } |
2138 | |
2309 | |
2139 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2310 | /* the given fd is invalid/unusable, so make sure it doesn't hurt us anymore */ |
2140 | inline_speed void ecb_cold |
2311 | inline_speed ecb_cold void |
2141 | fd_kill (EV_P_ int fd) |
2312 | fd_kill (EV_P_ int fd) |
2142 | { |
2313 | { |
2143 | ev_io *w; |
2314 | ev_io *w; |
2144 | |
2315 | |
2145 | while ((w = (ev_io *)anfds [fd].head)) |
2316 | while ((w = (ev_io *)anfds [fd].head)) |
… | |
… | |
2148 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2319 | ev_feed_event (EV_A_ (W)w, EV_ERROR | EV_READ | EV_WRITE); |
2149 | } |
2320 | } |
2150 | } |
2321 | } |
2151 | |
2322 | |
2152 | /* check whether the given fd is actually valid, for error recovery */ |
2323 | /* check whether the given fd is actually valid, for error recovery */ |
2153 | inline_size int ecb_cold |
2324 | inline_size ecb_cold int |
2154 | fd_valid (int fd) |
2325 | fd_valid (int fd) |
2155 | { |
2326 | { |
2156 | #ifdef _WIN32 |
2327 | #ifdef _WIN32 |
2157 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2328 | return EV_FD_TO_WIN32_HANDLE (fd) != -1; |
2158 | #else |
2329 | #else |
2159 | return fcntl (fd, F_GETFD) != -1; |
2330 | return fcntl (fd, F_GETFD) != -1; |
2160 | #endif |
2331 | #endif |
2161 | } |
2332 | } |
2162 | |
2333 | |
2163 | /* called on EBADF to verify fds */ |
2334 | /* called on EBADF to verify fds */ |
2164 | static void noinline ecb_cold |
2335 | ecb_noinline ecb_cold |
|
|
2336 | static void |
2165 | fd_ebadf (EV_P) |
2337 | fd_ebadf (EV_P) |
2166 | { |
2338 | { |
2167 | int fd; |
2339 | int fd; |
2168 | |
2340 | |
2169 | for (fd = 0; fd < anfdmax; ++fd) |
2341 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2171 | if (!fd_valid (fd) && errno == EBADF) |
2343 | if (!fd_valid (fd) && errno == EBADF) |
2172 | fd_kill (EV_A_ fd); |
2344 | fd_kill (EV_A_ fd); |
2173 | } |
2345 | } |
2174 | |
2346 | |
2175 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2347 | /* called on ENOMEM in select/poll to kill some fds and retry */ |
2176 | static void noinline ecb_cold |
2348 | ecb_noinline ecb_cold |
|
|
2349 | static void |
2177 | fd_enomem (EV_P) |
2350 | fd_enomem (EV_P) |
2178 | { |
2351 | { |
2179 | int fd; |
2352 | int fd; |
2180 | |
2353 | |
2181 | for (fd = anfdmax; fd--; ) |
2354 | for (fd = anfdmax; fd--; ) |
… | |
… | |
2185 | break; |
2358 | break; |
2186 | } |
2359 | } |
2187 | } |
2360 | } |
2188 | |
2361 | |
2189 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2362 | /* usually called after fork if backend needs to re-arm all fds from scratch */ |
2190 | static void noinline |
2363 | ecb_noinline |
|
|
2364 | static void |
2191 | fd_rearm_all (EV_P) |
2365 | fd_rearm_all (EV_P) |
2192 | { |
2366 | { |
2193 | int fd; |
2367 | int fd; |
2194 | |
2368 | |
2195 | for (fd = 0; fd < anfdmax; ++fd) |
2369 | for (fd = 0; fd < anfdmax; ++fd) |
… | |
… | |
2248 | ev_tstamp minat; |
2422 | ev_tstamp minat; |
2249 | ANHE *minpos; |
2423 | ANHE *minpos; |
2250 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2424 | ANHE *pos = heap + DHEAP * (k - HEAP0) + HEAP0 + 1; |
2251 | |
2425 | |
2252 | /* find minimum child */ |
2426 | /* find minimum child */ |
2253 | if (expect_true (pos + DHEAP - 1 < E)) |
2427 | if (ecb_expect_true (pos + DHEAP - 1 < E)) |
2254 | { |
2428 | { |
2255 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2429 | /* fast path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2256 | if ( ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2430 | if ( minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2257 | if ( ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2431 | if ( minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2258 | if ( ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2432 | if ( minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2259 | } |
2433 | } |
2260 | else if (pos < E) |
2434 | else if (pos < E) |
2261 | { |
2435 | { |
2262 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2436 | /* slow path */ (minpos = pos + 0), (minat = ANHE_at (*minpos)); |
2263 | if (pos + 1 < E && ANHE_at (pos [1]) < minat) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2437 | if (pos + 1 < E && minat > ANHE_at (pos [1])) (minpos = pos + 1), (minat = ANHE_at (*minpos)); |
2264 | if (pos + 2 < E && ANHE_at (pos [2]) < minat) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2438 | if (pos + 2 < E && minat > ANHE_at (pos [2])) (minpos = pos + 2), (minat = ANHE_at (*minpos)); |
2265 | if (pos + 3 < E && ANHE_at (pos [3]) < minat) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2439 | if (pos + 3 < E && minat > ANHE_at (pos [3])) (minpos = pos + 3), (minat = ANHE_at (*minpos)); |
2266 | } |
2440 | } |
2267 | else |
2441 | else |
2268 | break; |
2442 | break; |
2269 | |
2443 | |
2270 | if (ANHE_at (he) <= minat) |
2444 | if (ANHE_at (he) <= minat) |
… | |
… | |
2278 | |
2452 | |
2279 | heap [k] = he; |
2453 | heap [k] = he; |
2280 | ev_active (ANHE_w (he)) = k; |
2454 | ev_active (ANHE_w (he)) = k; |
2281 | } |
2455 | } |
2282 | |
2456 | |
2283 | #else /* 4HEAP */ |
2457 | #else /* not 4HEAP */ |
2284 | |
2458 | |
2285 | #define HEAP0 1 |
2459 | #define HEAP0 1 |
2286 | #define HPARENT(k) ((k) >> 1) |
2460 | #define HPARENT(k) ((k) >> 1) |
2287 | #define UPHEAP_DONE(p,k) (!(p)) |
2461 | #define UPHEAP_DONE(p,k) (!(p)) |
2288 | |
2462 | |
… | |
… | |
2376 | |
2550 | |
2377 | /*****************************************************************************/ |
2551 | /*****************************************************************************/ |
2378 | |
2552 | |
2379 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2553 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
2380 | |
2554 | |
2381 | static void noinline ecb_cold |
2555 | ecb_noinline ecb_cold |
|
|
2556 | static void |
2382 | evpipe_init (EV_P) |
2557 | evpipe_init (EV_P) |
2383 | { |
2558 | { |
2384 | if (!ev_is_active (&pipe_w)) |
2559 | if (!ev_is_active (&pipe_w)) |
2385 | { |
2560 | { |
2386 | int fds [2]; |
2561 | int fds [2]; |
… | |
… | |
2426 | inline_speed void |
2601 | inline_speed void |
2427 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2602 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
2428 | { |
2603 | { |
2429 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2604 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
2430 | |
2605 | |
2431 | if (expect_true (*flag)) |
2606 | if (ecb_expect_true (*flag)) |
2432 | return; |
2607 | return; |
2433 | |
2608 | |
2434 | *flag = 1; |
2609 | *flag = 1; |
2435 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2610 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
2436 | |
2611 | |
… | |
… | |
2457 | #endif |
2632 | #endif |
2458 | { |
2633 | { |
2459 | #ifdef _WIN32 |
2634 | #ifdef _WIN32 |
2460 | WSABUF buf; |
2635 | WSABUF buf; |
2461 | DWORD sent; |
2636 | DWORD sent; |
2462 | buf.buf = &buf; |
2637 | buf.buf = (char *)&buf; |
2463 | buf.len = 1; |
2638 | buf.len = 1; |
2464 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2639 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
2465 | #else |
2640 | #else |
2466 | write (evpipe [1], &(evpipe [1]), 1); |
2641 | write (evpipe [1], &(evpipe [1]), 1); |
2467 | #endif |
2642 | #endif |
… | |
… | |
2513 | sig_pending = 0; |
2688 | sig_pending = 0; |
2514 | |
2689 | |
2515 | ECB_MEMORY_FENCE; |
2690 | ECB_MEMORY_FENCE; |
2516 | |
2691 | |
2517 | for (i = EV_NSIG - 1; i--; ) |
2692 | for (i = EV_NSIG - 1; i--; ) |
2518 | if (expect_false (signals [i].pending)) |
2693 | if (ecb_expect_false (signals [i].pending)) |
2519 | ev_feed_signal_event (EV_A_ i + 1); |
2694 | ev_feed_signal_event (EV_A_ i + 1); |
2520 | } |
2695 | } |
2521 | #endif |
2696 | #endif |
2522 | |
2697 | |
2523 | #if EV_ASYNC_ENABLE |
2698 | #if EV_ASYNC_ENABLE |
… | |
… | |
2539 | } |
2714 | } |
2540 | |
2715 | |
2541 | /*****************************************************************************/ |
2716 | /*****************************************************************************/ |
2542 | |
2717 | |
2543 | void |
2718 | void |
2544 | ev_feed_signal (int signum) EV_THROW |
2719 | ev_feed_signal (int signum) EV_NOEXCEPT |
2545 | { |
2720 | { |
2546 | #if EV_MULTIPLICITY |
2721 | #if EV_MULTIPLICITY |
2547 | EV_P; |
2722 | EV_P; |
2548 | ECB_MEMORY_FENCE_ACQUIRE; |
2723 | ECB_MEMORY_FENCE_ACQUIRE; |
2549 | EV_A = signals [signum - 1].loop; |
2724 | EV_A = signals [signum - 1].loop; |
… | |
… | |
2564 | #endif |
2739 | #endif |
2565 | |
2740 | |
2566 | ev_feed_signal (signum); |
2741 | ev_feed_signal (signum); |
2567 | } |
2742 | } |
2568 | |
2743 | |
2569 | void noinline |
2744 | ecb_noinline |
|
|
2745 | void |
2570 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
2746 | ev_feed_signal_event (EV_P_ int signum) EV_NOEXCEPT |
2571 | { |
2747 | { |
2572 | WL w; |
2748 | WL w; |
2573 | |
2749 | |
2574 | if (expect_false (signum <= 0 || signum >= EV_NSIG)) |
2750 | if (ecb_expect_false (signum <= 0 || signum >= EV_NSIG)) |
2575 | return; |
2751 | return; |
2576 | |
2752 | |
2577 | --signum; |
2753 | --signum; |
2578 | |
2754 | |
2579 | #if EV_MULTIPLICITY |
2755 | #if EV_MULTIPLICITY |
2580 | /* it is permissible to try to feed a signal to the wrong loop */ |
2756 | /* it is permissible to try to feed a signal to the wrong loop */ |
2581 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
2757 | /* or, likely more useful, feeding a signal nobody is waiting for */ |
2582 | |
2758 | |
2583 | if (expect_false (signals [signum].loop != EV_A)) |
2759 | if (ecb_expect_false (signals [signum].loop != EV_A)) |
2584 | return; |
2760 | return; |
2585 | #endif |
2761 | #endif |
2586 | |
2762 | |
2587 | signals [signum].pending = 0; |
2763 | signals [signum].pending = 0; |
2588 | ECB_MEMORY_FENCE_RELEASE; |
2764 | ECB_MEMORY_FENCE_RELEASE; |
… | |
… | |
2684 | # include "ev_kqueue.c" |
2860 | # include "ev_kqueue.c" |
2685 | #endif |
2861 | #endif |
2686 | #if EV_USE_EPOLL |
2862 | #if EV_USE_EPOLL |
2687 | # include "ev_epoll.c" |
2863 | # include "ev_epoll.c" |
2688 | #endif |
2864 | #endif |
|
|
2865 | #if EV_USE_LINUXAIO |
|
|
2866 | # include "ev_linuxaio.c" |
|
|
2867 | #endif |
|
|
2868 | #if EV_USE_IOURING |
|
|
2869 | # include "ev_iouring.c" |
|
|
2870 | #endif |
2689 | #if EV_USE_POLL |
2871 | #if EV_USE_POLL |
2690 | # include "ev_poll.c" |
2872 | # include "ev_poll.c" |
2691 | #endif |
2873 | #endif |
2692 | #if EV_USE_SELECT |
2874 | #if EV_USE_SELECT |
2693 | # include "ev_select.c" |
2875 | # include "ev_select.c" |
2694 | #endif |
2876 | #endif |
2695 | |
2877 | |
2696 | int ecb_cold |
2878 | ecb_cold int |
2697 | ev_version_major (void) EV_THROW |
2879 | ev_version_major (void) EV_NOEXCEPT |
2698 | { |
2880 | { |
2699 | return EV_VERSION_MAJOR; |
2881 | return EV_VERSION_MAJOR; |
2700 | } |
2882 | } |
2701 | |
2883 | |
2702 | int ecb_cold |
2884 | ecb_cold int |
2703 | ev_version_minor (void) EV_THROW |
2885 | ev_version_minor (void) EV_NOEXCEPT |
2704 | { |
2886 | { |
2705 | return EV_VERSION_MINOR; |
2887 | return EV_VERSION_MINOR; |
2706 | } |
2888 | } |
2707 | |
2889 | |
2708 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2890 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2709 | int inline_size ecb_cold |
2891 | inline_size ecb_cold int |
2710 | enable_secure (void) |
2892 | enable_secure (void) |
2711 | { |
2893 | { |
2712 | #ifdef _WIN32 |
2894 | #ifdef _WIN32 |
2713 | return 0; |
2895 | return 0; |
2714 | #else |
2896 | #else |
2715 | return getuid () != geteuid () |
2897 | return getuid () != geteuid () |
2716 | || getgid () != getegid (); |
2898 | || getgid () != getegid (); |
2717 | #endif |
2899 | #endif |
2718 | } |
2900 | } |
2719 | |
2901 | |
2720 | unsigned int ecb_cold |
2902 | ecb_cold |
|
|
2903 | unsigned int |
2721 | ev_supported_backends (void) EV_THROW |
2904 | ev_supported_backends (void) EV_NOEXCEPT |
2722 | { |
2905 | { |
2723 | unsigned int flags = 0; |
2906 | unsigned int flags = 0; |
2724 | |
2907 | |
2725 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2908 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2726 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2909 | if (EV_USE_KQUEUE ) flags |= EVBACKEND_KQUEUE; |
2727 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
2910 | if (EV_USE_EPOLL ) flags |= EVBACKEND_EPOLL; |
|
|
2911 | if (EV_USE_LINUXAIO) flags |= EVBACKEND_LINUXAIO; |
|
|
2912 | if (EV_USE_IOURING ) flags |= EVBACKEND_IOURING; |
2728 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2913 | if (EV_USE_POLL ) flags |= EVBACKEND_POLL; |
2729 | if (EV_USE_SELECT) flags |= EVBACKEND_SELECT; |
2914 | if (EV_USE_SELECT ) flags |= EVBACKEND_SELECT; |
2730 | |
2915 | |
2731 | return flags; |
2916 | return flags; |
2732 | } |
2917 | } |
2733 | |
2918 | |
2734 | unsigned int ecb_cold |
2919 | ecb_cold |
|
|
2920 | unsigned int |
2735 | ev_recommended_backends (void) EV_THROW |
2921 | ev_recommended_backends (void) EV_NOEXCEPT |
2736 | { |
2922 | { |
2737 | unsigned int flags = ev_supported_backends (); |
2923 | unsigned int flags = ev_supported_backends (); |
2738 | |
2924 | |
2739 | #ifndef __NetBSD__ |
2925 | #ifndef __NetBSD__ |
2740 | /* kqueue is borked on everything but netbsd apparently */ |
2926 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2748 | #endif |
2934 | #endif |
2749 | #ifdef __FreeBSD__ |
2935 | #ifdef __FreeBSD__ |
2750 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2936 | flags &= ~EVBACKEND_POLL; /* poll return value is unusable (http://forums.freebsd.org/archive/index.php/t-10270.html) */ |
2751 | #endif |
2937 | #endif |
2752 | |
2938 | |
|
|
2939 | /* TODO: linuxaio is very experimental */ |
|
|
2940 | #if !EV_RECOMMEND_LINUXAIO |
|
|
2941 | flags &= ~EVBACKEND_LINUXAIO; |
|
|
2942 | #endif |
|
|
2943 | /* TODO: linuxaio is super experimental */ |
|
|
2944 | #if !EV_RECOMMEND_IOURING |
|
|
2945 | flags &= ~EVBACKEND_IOURING; |
|
|
2946 | #endif |
|
|
2947 | |
2753 | return flags; |
2948 | return flags; |
2754 | } |
2949 | } |
2755 | |
2950 | |
2756 | unsigned int ecb_cold |
2951 | ecb_cold |
|
|
2952 | unsigned int |
2757 | ev_embeddable_backends (void) EV_THROW |
2953 | ev_embeddable_backends (void) EV_NOEXCEPT |
2758 | { |
2954 | { |
2759 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2955 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2760 | |
2956 | |
2761 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2957 | /* 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 */ |
2958 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2763 | flags &= ~EVBACKEND_EPOLL; |
2959 | flags &= ~EVBACKEND_EPOLL; |
2764 | |
2960 | |
|
|
2961 | /* EVBACKEND_LINUXAIO is theoretically embeddable, but suffers from a performance overhead */ |
|
|
2962 | |
|
|
2963 | /* EVBACKEND_IOURING is practically embeddable, but the current implementation is not |
|
|
2964 | * because our backend_fd is the epoll fd we need as fallback. |
|
|
2965 | * if the kernel ever is fixed, this might change... |
|
|
2966 | */ |
|
|
2967 | |
2765 | return flags; |
2968 | return flags; |
2766 | } |
2969 | } |
2767 | |
2970 | |
2768 | unsigned int |
2971 | unsigned int |
2769 | ev_backend (EV_P) EV_THROW |
2972 | ev_backend (EV_P) EV_NOEXCEPT |
2770 | { |
2973 | { |
2771 | return backend; |
2974 | return backend; |
2772 | } |
2975 | } |
2773 | |
2976 | |
2774 | #if EV_FEATURE_API |
2977 | #if EV_FEATURE_API |
2775 | unsigned int |
2978 | unsigned int |
2776 | ev_iteration (EV_P) EV_THROW |
2979 | ev_iteration (EV_P) EV_NOEXCEPT |
2777 | { |
2980 | { |
2778 | return loop_count; |
2981 | return loop_count; |
2779 | } |
2982 | } |
2780 | |
2983 | |
2781 | unsigned int |
2984 | unsigned int |
2782 | ev_depth (EV_P) EV_THROW |
2985 | ev_depth (EV_P) EV_NOEXCEPT |
2783 | { |
2986 | { |
2784 | return loop_depth; |
2987 | return loop_depth; |
2785 | } |
2988 | } |
2786 | |
2989 | |
2787 | void |
2990 | void |
2788 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2991 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2789 | { |
2992 | { |
2790 | io_blocktime = interval; |
2993 | io_blocktime = interval; |
2791 | } |
2994 | } |
2792 | |
2995 | |
2793 | void |
2996 | void |
2794 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2997 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_NOEXCEPT |
2795 | { |
2998 | { |
2796 | timeout_blocktime = interval; |
2999 | timeout_blocktime = interval; |
2797 | } |
3000 | } |
2798 | |
3001 | |
2799 | void |
3002 | void |
2800 | ev_set_userdata (EV_P_ void *data) EV_THROW |
3003 | ev_set_userdata (EV_P_ void *data) EV_NOEXCEPT |
2801 | { |
3004 | { |
2802 | userdata = data; |
3005 | userdata = data; |
2803 | } |
3006 | } |
2804 | |
3007 | |
2805 | void * |
3008 | void * |
2806 | ev_userdata (EV_P) EV_THROW |
3009 | ev_userdata (EV_P) EV_NOEXCEPT |
2807 | { |
3010 | { |
2808 | return userdata; |
3011 | return userdata; |
2809 | } |
3012 | } |
2810 | |
3013 | |
2811 | void |
3014 | void |
2812 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_THROW |
3015 | ev_set_invoke_pending_cb (EV_P_ ev_loop_callback invoke_pending_cb) EV_NOEXCEPT |
2813 | { |
3016 | { |
2814 | invoke_cb = invoke_pending_cb; |
3017 | invoke_cb = invoke_pending_cb; |
2815 | } |
3018 | } |
2816 | |
3019 | |
2817 | void |
3020 | void |
2818 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
3021 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_NOEXCEPT, void (*acquire)(EV_P) EV_NOEXCEPT) EV_NOEXCEPT |
2819 | { |
3022 | { |
2820 | release_cb = release; |
3023 | release_cb = release; |
2821 | acquire_cb = acquire; |
3024 | acquire_cb = acquire; |
2822 | } |
3025 | } |
2823 | #endif |
3026 | #endif |
2824 | |
3027 | |
2825 | /* initialise a loop structure, must be zero-initialised */ |
3028 | /* initialise a loop structure, must be zero-initialised */ |
2826 | static void noinline ecb_cold |
3029 | ecb_noinline ecb_cold |
|
|
3030 | static void |
2827 | loop_init (EV_P_ unsigned int flags) EV_THROW |
3031 | loop_init (EV_P_ unsigned int flags) EV_NOEXCEPT |
2828 | { |
3032 | { |
2829 | if (!backend) |
3033 | if (!backend) |
2830 | { |
3034 | { |
2831 | origflags = flags; |
3035 | origflags = flags; |
2832 | |
3036 | |
… | |
… | |
2890 | |
3094 | |
2891 | if (!(flags & EVBACKEND_MASK)) |
3095 | if (!(flags & EVBACKEND_MASK)) |
2892 | flags |= ev_recommended_backends (); |
3096 | flags |= ev_recommended_backends (); |
2893 | |
3097 | |
2894 | #if EV_USE_IOCP |
3098 | #if EV_USE_IOCP |
2895 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
3099 | if (!backend && (flags & EVBACKEND_IOCP )) backend = iocp_init (EV_A_ flags); |
2896 | #endif |
3100 | #endif |
2897 | #if EV_USE_PORT |
3101 | #if EV_USE_PORT |
2898 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
3102 | if (!backend && (flags & EVBACKEND_PORT )) backend = port_init (EV_A_ flags); |
2899 | #endif |
3103 | #endif |
2900 | #if EV_USE_KQUEUE |
3104 | #if EV_USE_KQUEUE |
2901 | if (!backend && (flags & EVBACKEND_KQUEUE)) backend = kqueue_init (EV_A_ flags); |
3105 | if (!backend && (flags & EVBACKEND_KQUEUE )) backend = kqueue_init (EV_A_ flags); |
|
|
3106 | #endif |
|
|
3107 | #if EV_USE_IOURING |
|
|
3108 | if (!backend && (flags & EVBACKEND_IOURING )) backend = iouring_init (EV_A_ flags); |
|
|
3109 | #endif |
|
|
3110 | #if EV_USE_LINUXAIO |
|
|
3111 | if (!backend && (flags & EVBACKEND_LINUXAIO)) backend = linuxaio_init (EV_A_ flags); |
2902 | #endif |
3112 | #endif |
2903 | #if EV_USE_EPOLL |
3113 | #if EV_USE_EPOLL |
2904 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
3114 | if (!backend && (flags & EVBACKEND_EPOLL )) backend = epoll_init (EV_A_ flags); |
2905 | #endif |
3115 | #endif |
2906 | #if EV_USE_POLL |
3116 | #if EV_USE_POLL |
2907 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
3117 | if (!backend && (flags & EVBACKEND_POLL )) backend = poll_init (EV_A_ flags); |
2908 | #endif |
3118 | #endif |
2909 | #if EV_USE_SELECT |
3119 | #if EV_USE_SELECT |
2910 | if (!backend && (flags & EVBACKEND_SELECT)) backend = select_init (EV_A_ flags); |
3120 | if (!backend && (flags & EVBACKEND_SELECT )) backend = select_init (EV_A_ flags); |
2911 | #endif |
3121 | #endif |
2912 | |
3122 | |
2913 | ev_prepare_init (&pending_w, pendingcb); |
3123 | ev_prepare_init (&pending_w, pendingcb); |
2914 | |
3124 | |
2915 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
3125 | #if EV_SIGNAL_ENABLE || EV_ASYNC_ENABLE |
… | |
… | |
2918 | #endif |
3128 | #endif |
2919 | } |
3129 | } |
2920 | } |
3130 | } |
2921 | |
3131 | |
2922 | /* free up a loop structure */ |
3132 | /* free up a loop structure */ |
2923 | void ecb_cold |
3133 | ecb_cold |
|
|
3134 | void |
2924 | ev_loop_destroy (EV_P) |
3135 | ev_loop_destroy (EV_P) |
2925 | { |
3136 | { |
2926 | int i; |
3137 | int i; |
2927 | |
3138 | |
2928 | #if EV_MULTIPLICITY |
3139 | #if EV_MULTIPLICITY |
… | |
… | |
2931 | return; |
3142 | return; |
2932 | #endif |
3143 | #endif |
2933 | |
3144 | |
2934 | #if EV_CLEANUP_ENABLE |
3145 | #if EV_CLEANUP_ENABLE |
2935 | /* queue cleanup watchers (and execute them) */ |
3146 | /* queue cleanup watchers (and execute them) */ |
2936 | if (expect_false (cleanupcnt)) |
3147 | if (ecb_expect_false (cleanupcnt)) |
2937 | { |
3148 | { |
2938 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
3149 | queue_events (EV_A_ (W *)cleanups, cleanupcnt, EV_CLEANUP); |
2939 | EV_INVOKE_PENDING; |
3150 | EV_INVOKE_PENDING; |
2940 | } |
3151 | } |
2941 | #endif |
3152 | #endif |
… | |
… | |
2969 | |
3180 | |
2970 | if (backend_fd >= 0) |
3181 | if (backend_fd >= 0) |
2971 | close (backend_fd); |
3182 | close (backend_fd); |
2972 | |
3183 | |
2973 | #if EV_USE_IOCP |
3184 | #if EV_USE_IOCP |
2974 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
3185 | if (backend == EVBACKEND_IOCP ) iocp_destroy (EV_A); |
2975 | #endif |
3186 | #endif |
2976 | #if EV_USE_PORT |
3187 | #if EV_USE_PORT |
2977 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
3188 | if (backend == EVBACKEND_PORT ) port_destroy (EV_A); |
2978 | #endif |
3189 | #endif |
2979 | #if EV_USE_KQUEUE |
3190 | #if EV_USE_KQUEUE |
2980 | if (backend == EVBACKEND_KQUEUE) kqueue_destroy (EV_A); |
3191 | if (backend == EVBACKEND_KQUEUE ) kqueue_destroy (EV_A); |
|
|
3192 | #endif |
|
|
3193 | #if EV_USE_IOURING |
|
|
3194 | if (backend == EVBACKEND_IOURING ) iouring_destroy (EV_A); |
|
|
3195 | #endif |
|
|
3196 | #if EV_USE_LINUXAIO |
|
|
3197 | if (backend == EVBACKEND_LINUXAIO) linuxaio_destroy (EV_A); |
2981 | #endif |
3198 | #endif |
2982 | #if EV_USE_EPOLL |
3199 | #if EV_USE_EPOLL |
2983 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
3200 | if (backend == EVBACKEND_EPOLL ) epoll_destroy (EV_A); |
2984 | #endif |
3201 | #endif |
2985 | #if EV_USE_POLL |
3202 | #if EV_USE_POLL |
2986 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
3203 | if (backend == EVBACKEND_POLL ) poll_destroy (EV_A); |
2987 | #endif |
3204 | #endif |
2988 | #if EV_USE_SELECT |
3205 | #if EV_USE_SELECT |
2989 | if (backend == EVBACKEND_SELECT) select_destroy (EV_A); |
3206 | if (backend == EVBACKEND_SELECT ) select_destroy (EV_A); |
2990 | #endif |
3207 | #endif |
2991 | |
3208 | |
2992 | for (i = NUMPRI; i--; ) |
3209 | for (i = NUMPRI; i--; ) |
2993 | { |
3210 | { |
2994 | array_free (pending, [i]); |
3211 | array_free (pending, [i]); |
… | |
… | |
3036 | |
3253 | |
3037 | inline_size void |
3254 | inline_size void |
3038 | loop_fork (EV_P) |
3255 | loop_fork (EV_P) |
3039 | { |
3256 | { |
3040 | #if EV_USE_PORT |
3257 | #if EV_USE_PORT |
3041 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3258 | if (backend == EVBACKEND_PORT ) port_fork (EV_A); |
3042 | #endif |
3259 | #endif |
3043 | #if EV_USE_KQUEUE |
3260 | #if EV_USE_KQUEUE |
3044 | if (backend == EVBACKEND_KQUEUE) kqueue_fork (EV_A); |
3261 | if (backend == EVBACKEND_KQUEUE ) kqueue_fork (EV_A); |
|
|
3262 | #endif |
|
|
3263 | #if EV_USE_IOURING |
|
|
3264 | if (backend == EVBACKEND_IOURING ) iouring_fork (EV_A); |
|
|
3265 | #endif |
|
|
3266 | #if EV_USE_LINUXAIO |
|
|
3267 | if (backend == EVBACKEND_LINUXAIO) linuxaio_fork (EV_A); |
3045 | #endif |
3268 | #endif |
3046 | #if EV_USE_EPOLL |
3269 | #if EV_USE_EPOLL |
3047 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3270 | if (backend == EVBACKEND_EPOLL ) epoll_fork (EV_A); |
3048 | #endif |
3271 | #endif |
3049 | #if EV_USE_INOTIFY |
3272 | #if EV_USE_INOTIFY |
3050 | infy_fork (EV_A); |
3273 | infy_fork (EV_A); |
3051 | #endif |
3274 | #endif |
3052 | |
3275 | |
… | |
… | |
3070 | postfork = 0; |
3293 | postfork = 0; |
3071 | } |
3294 | } |
3072 | |
3295 | |
3073 | #if EV_MULTIPLICITY |
3296 | #if EV_MULTIPLICITY |
3074 | |
3297 | |
|
|
3298 | ecb_cold |
3075 | struct ev_loop * ecb_cold |
3299 | struct ev_loop * |
3076 | ev_loop_new (unsigned int flags) EV_THROW |
3300 | ev_loop_new (unsigned int flags) EV_NOEXCEPT |
3077 | { |
3301 | { |
3078 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3302 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
3079 | |
3303 | |
3080 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3304 | memset (EV_A, 0, sizeof (struct ev_loop)); |
3081 | loop_init (EV_A_ flags); |
3305 | loop_init (EV_A_ flags); |
… | |
… | |
3088 | } |
3312 | } |
3089 | |
3313 | |
3090 | #endif /* multiplicity */ |
3314 | #endif /* multiplicity */ |
3091 | |
3315 | |
3092 | #if EV_VERIFY |
3316 | #if EV_VERIFY |
3093 | static void noinline ecb_cold |
3317 | ecb_noinline ecb_cold |
|
|
3318 | static void |
3094 | verify_watcher (EV_P_ W w) |
3319 | verify_watcher (EV_P_ W w) |
3095 | { |
3320 | { |
3096 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3321 | assert (("libev: watcher has invalid priority", ABSPRI (w) >= 0 && ABSPRI (w) < NUMPRI)); |
3097 | |
3322 | |
3098 | if (w->pending) |
3323 | if (w->pending) |
3099 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3324 | assert (("libev: pending watcher not on pending queue", pendings [ABSPRI (w)][w->pending - 1].w == w)); |
3100 | } |
3325 | } |
3101 | |
3326 | |
3102 | static void noinline ecb_cold |
3327 | ecb_noinline ecb_cold |
|
|
3328 | static void |
3103 | verify_heap (EV_P_ ANHE *heap, int N) |
3329 | verify_heap (EV_P_ ANHE *heap, int N) |
3104 | { |
3330 | { |
3105 | int i; |
3331 | int i; |
3106 | |
3332 | |
3107 | for (i = HEAP0; i < N + HEAP0; ++i) |
3333 | for (i = HEAP0; i < N + HEAP0; ++i) |
… | |
… | |
3112 | |
3338 | |
3113 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3339 | verify_watcher (EV_A_ (W)ANHE_w (heap [i])); |
3114 | } |
3340 | } |
3115 | } |
3341 | } |
3116 | |
3342 | |
3117 | static void noinline ecb_cold |
3343 | ecb_noinline ecb_cold |
|
|
3344 | static void |
3118 | array_verify (EV_P_ W *ws, int cnt) |
3345 | array_verify (EV_P_ W *ws, int cnt) |
3119 | { |
3346 | { |
3120 | while (cnt--) |
3347 | while (cnt--) |
3121 | { |
3348 | { |
3122 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
3349 | assert (("libev: active index mismatch", ev_active (ws [cnt]) == cnt + 1)); |
… | |
… | |
3125 | } |
3352 | } |
3126 | #endif |
3353 | #endif |
3127 | |
3354 | |
3128 | #if EV_FEATURE_API |
3355 | #if EV_FEATURE_API |
3129 | void ecb_cold |
3356 | void ecb_cold |
3130 | ev_verify (EV_P) EV_THROW |
3357 | ev_verify (EV_P) EV_NOEXCEPT |
3131 | { |
3358 | { |
3132 | #if EV_VERIFY |
3359 | #if EV_VERIFY |
3133 | int i; |
3360 | int i; |
3134 | WL w, w2; |
3361 | WL w, w2; |
3135 | |
3362 | |
… | |
… | |
3211 | #endif |
3438 | #endif |
3212 | } |
3439 | } |
3213 | #endif |
3440 | #endif |
3214 | |
3441 | |
3215 | #if EV_MULTIPLICITY |
3442 | #if EV_MULTIPLICITY |
|
|
3443 | ecb_cold |
3216 | struct ev_loop * ecb_cold |
3444 | struct ev_loop * |
3217 | #else |
3445 | #else |
3218 | int |
3446 | int |
3219 | #endif |
3447 | #endif |
3220 | ev_default_loop (unsigned int flags) EV_THROW |
3448 | ev_default_loop (unsigned int flags) EV_NOEXCEPT |
3221 | { |
3449 | { |
3222 | if (!ev_default_loop_ptr) |
3450 | if (!ev_default_loop_ptr) |
3223 | { |
3451 | { |
3224 | #if EV_MULTIPLICITY |
3452 | #if EV_MULTIPLICITY |
3225 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
3453 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
3244 | |
3472 | |
3245 | return ev_default_loop_ptr; |
3473 | return ev_default_loop_ptr; |
3246 | } |
3474 | } |
3247 | |
3475 | |
3248 | void |
3476 | void |
3249 | ev_loop_fork (EV_P) EV_THROW |
3477 | ev_loop_fork (EV_P) EV_NOEXCEPT |
3250 | { |
3478 | { |
3251 | postfork = 1; |
3479 | postfork = 1; |
3252 | } |
3480 | } |
3253 | |
3481 | |
3254 | /*****************************************************************************/ |
3482 | /*****************************************************************************/ |
… | |
… | |
3258 | { |
3486 | { |
3259 | EV_CB_INVOKE ((W)w, revents); |
3487 | EV_CB_INVOKE ((W)w, revents); |
3260 | } |
3488 | } |
3261 | |
3489 | |
3262 | unsigned int |
3490 | unsigned int |
3263 | ev_pending_count (EV_P) EV_THROW |
3491 | ev_pending_count (EV_P) EV_NOEXCEPT |
3264 | { |
3492 | { |
3265 | int pri; |
3493 | int pri; |
3266 | unsigned int count = 0; |
3494 | unsigned int count = 0; |
3267 | |
3495 | |
3268 | for (pri = NUMPRI; pri--; ) |
3496 | for (pri = NUMPRI; pri--; ) |
3269 | count += pendingcnt [pri]; |
3497 | count += pendingcnt [pri]; |
3270 | |
3498 | |
3271 | return count; |
3499 | return count; |
3272 | } |
3500 | } |
3273 | |
3501 | |
3274 | void noinline |
3502 | ecb_noinline |
|
|
3503 | void |
3275 | ev_invoke_pending (EV_P) |
3504 | ev_invoke_pending (EV_P) |
3276 | { |
3505 | { |
3277 | pendingpri = NUMPRI; |
3506 | pendingpri = NUMPRI; |
3278 | |
3507 | |
3279 | while (pendingpri) /* pendingpri possibly gets modified in the inner loop */ |
3508 | do |
3280 | { |
3509 | { |
3281 | --pendingpri; |
3510 | --pendingpri; |
3282 | |
3511 | |
|
|
3512 | /* pendingpri possibly gets modified in the inner loop */ |
3283 | while (pendingcnt [pendingpri]) |
3513 | while (pendingcnt [pendingpri]) |
3284 | { |
3514 | { |
3285 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3515 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
3286 | |
3516 | |
3287 | p->w->pending = 0; |
3517 | p->w->pending = 0; |
3288 | EV_CB_INVOKE (p->w, p->events); |
3518 | EV_CB_INVOKE (p->w, p->events); |
3289 | EV_FREQUENT_CHECK; |
3519 | EV_FREQUENT_CHECK; |
3290 | } |
3520 | } |
3291 | } |
3521 | } |
|
|
3522 | while (pendingpri); |
3292 | } |
3523 | } |
3293 | |
3524 | |
3294 | #if EV_IDLE_ENABLE |
3525 | #if EV_IDLE_ENABLE |
3295 | /* make idle watchers pending. this handles the "call-idle */ |
3526 | /* make idle watchers pending. this handles the "call-idle */ |
3296 | /* only when higher priorities are idle" logic */ |
3527 | /* only when higher priorities are idle" logic */ |
3297 | inline_size void |
3528 | inline_size void |
3298 | idle_reify (EV_P) |
3529 | idle_reify (EV_P) |
3299 | { |
3530 | { |
3300 | if (expect_false (idleall)) |
3531 | if (ecb_expect_false (idleall)) |
3301 | { |
3532 | { |
3302 | int pri; |
3533 | int pri; |
3303 | |
3534 | |
3304 | for (pri = NUMPRI; pri--; ) |
3535 | for (pri = NUMPRI; pri--; ) |
3305 | { |
3536 | { |
… | |
… | |
3335 | { |
3566 | { |
3336 | ev_at (w) += w->repeat; |
3567 | ev_at (w) += w->repeat; |
3337 | if (ev_at (w) < mn_now) |
3568 | if (ev_at (w) < mn_now) |
3338 | ev_at (w) = mn_now; |
3569 | ev_at (w) = mn_now; |
3339 | |
3570 | |
3340 | assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > 0.)); |
3571 | assert (("libev: negative ev_timer repeat value found while processing timers", w->repeat > EV_TS_CONST (0.))); |
3341 | |
3572 | |
3342 | ANHE_at_cache (timers [HEAP0]); |
3573 | ANHE_at_cache (timers [HEAP0]); |
3343 | downheap (timers, timercnt, HEAP0); |
3574 | downheap (timers, timercnt, HEAP0); |
3344 | } |
3575 | } |
3345 | else |
3576 | else |
… | |
… | |
3354 | } |
3585 | } |
3355 | } |
3586 | } |
3356 | |
3587 | |
3357 | #if EV_PERIODIC_ENABLE |
3588 | #if EV_PERIODIC_ENABLE |
3358 | |
3589 | |
3359 | static void noinline |
3590 | ecb_noinline |
|
|
3591 | static void |
3360 | periodic_recalc (EV_P_ ev_periodic *w) |
3592 | periodic_recalc (EV_P_ ev_periodic *w) |
3361 | { |
3593 | { |
3362 | ev_tstamp interval = w->interval > MIN_INTERVAL ? w->interval : MIN_INTERVAL; |
3594 | 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); |
3595 | ev_tstamp at = w->offset + interval * ev_floor ((ev_rt_now - w->offset) / interval); |
3364 | |
3596 | |
… | |
… | |
3366 | while (at <= ev_rt_now) |
3598 | while (at <= ev_rt_now) |
3367 | { |
3599 | { |
3368 | ev_tstamp nat = at + w->interval; |
3600 | ev_tstamp nat = at + w->interval; |
3369 | |
3601 | |
3370 | /* when resolution fails us, we use ev_rt_now */ |
3602 | /* when resolution fails us, we use ev_rt_now */ |
3371 | if (expect_false (nat == at)) |
3603 | if (ecb_expect_false (nat == at)) |
3372 | { |
3604 | { |
3373 | at = ev_rt_now; |
3605 | at = ev_rt_now; |
3374 | break; |
3606 | break; |
3375 | } |
3607 | } |
3376 | |
3608 | |
… | |
… | |
3422 | } |
3654 | } |
3423 | } |
3655 | } |
3424 | |
3656 | |
3425 | /* simply recalculate all periodics */ |
3657 | /* simply recalculate all periodics */ |
3426 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3658 | /* TODO: maybe ensure that at least one event happens when jumping forward? */ |
3427 | static void noinline ecb_cold |
3659 | ecb_noinline ecb_cold |
|
|
3660 | static void |
3428 | periodics_reschedule (EV_P) |
3661 | periodics_reschedule (EV_P) |
3429 | { |
3662 | { |
3430 | int i; |
3663 | int i; |
3431 | |
3664 | |
3432 | /* adjust periodics after time jump */ |
3665 | /* adjust periodics after time jump */ |
… | |
… | |
3445 | reheap (periodics, periodiccnt); |
3678 | reheap (periodics, periodiccnt); |
3446 | } |
3679 | } |
3447 | #endif |
3680 | #endif |
3448 | |
3681 | |
3449 | /* adjust all timers by a given offset */ |
3682 | /* adjust all timers by a given offset */ |
3450 | static void noinline ecb_cold |
3683 | ecb_noinline ecb_cold |
|
|
3684 | static void |
3451 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3685 | timers_reschedule (EV_P_ ev_tstamp adjust) |
3452 | { |
3686 | { |
3453 | int i; |
3687 | int i; |
3454 | |
3688 | |
3455 | for (i = 0; i < timercnt; ++i) |
3689 | for (i = 0; i < timercnt; ++i) |
… | |
… | |
3464 | /* also detect if there was a timejump, and act accordingly */ |
3698 | /* also detect if there was a timejump, and act accordingly */ |
3465 | inline_speed void |
3699 | inline_speed void |
3466 | time_update (EV_P_ ev_tstamp max_block) |
3700 | time_update (EV_P_ ev_tstamp max_block) |
3467 | { |
3701 | { |
3468 | #if EV_USE_MONOTONIC |
3702 | #if EV_USE_MONOTONIC |
3469 | if (expect_true (have_monotonic)) |
3703 | if (ecb_expect_true (have_monotonic)) |
3470 | { |
3704 | { |
3471 | int i; |
3705 | int i; |
3472 | ev_tstamp odiff = rtmn_diff; |
3706 | ev_tstamp odiff = rtmn_diff; |
3473 | |
3707 | |
3474 | mn_now = get_clock (); |
3708 | mn_now = get_clock (); |
3475 | |
3709 | |
3476 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3710 | /* only fetch the realtime clock every 0.5*MIN_TIMEJUMP seconds */ |
3477 | /* interpolate in the meantime */ |
3711 | /* interpolate in the meantime */ |
3478 | if (expect_true (mn_now - now_floor < MIN_TIMEJUMP * .5)) |
3712 | if (ecb_expect_true (mn_now - now_floor < EV_TS_CONST (MIN_TIMEJUMP * .5))) |
3479 | { |
3713 | { |
3480 | ev_rt_now = rtmn_diff + mn_now; |
3714 | ev_rt_now = rtmn_diff + mn_now; |
3481 | return; |
3715 | return; |
3482 | } |
3716 | } |
3483 | |
3717 | |
… | |
… | |
3497 | ev_tstamp diff; |
3731 | ev_tstamp diff; |
3498 | rtmn_diff = ev_rt_now - mn_now; |
3732 | rtmn_diff = ev_rt_now - mn_now; |
3499 | |
3733 | |
3500 | diff = odiff - rtmn_diff; |
3734 | diff = odiff - rtmn_diff; |
3501 | |
3735 | |
3502 | if (expect_true ((diff < 0. ? -diff : diff) < MIN_TIMEJUMP)) |
3736 | if (ecb_expect_true ((diff < EV_TS_CONST (0.) ? -diff : diff) < EV_TS_CONST (MIN_TIMEJUMP))) |
3503 | return; /* all is well */ |
3737 | return; /* all is well */ |
3504 | |
3738 | |
3505 | ev_rt_now = ev_time (); |
3739 | ev_rt_now = ev_time (); |
3506 | mn_now = get_clock (); |
3740 | mn_now = get_clock (); |
3507 | now_floor = mn_now; |
3741 | now_floor = mn_now; |
… | |
… | |
3516 | else |
3750 | else |
3517 | #endif |
3751 | #endif |
3518 | { |
3752 | { |
3519 | ev_rt_now = ev_time (); |
3753 | ev_rt_now = ev_time (); |
3520 | |
3754 | |
3521 | if (expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + MIN_TIMEJUMP)) |
3755 | if (ecb_expect_false (mn_now > ev_rt_now || ev_rt_now > mn_now + max_block + EV_TS_CONST (MIN_TIMEJUMP))) |
3522 | { |
3756 | { |
3523 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
3757 | /* adjust timers. this is easy, as the offset is the same for all of them */ |
3524 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3758 | timers_reschedule (EV_A_ ev_rt_now - mn_now); |
3525 | #if EV_PERIODIC_ENABLE |
3759 | #if EV_PERIODIC_ENABLE |
3526 | periodics_reschedule (EV_A); |
3760 | periodics_reschedule (EV_A); |
… | |
… | |
3549 | #if EV_VERIFY >= 2 |
3783 | #if EV_VERIFY >= 2 |
3550 | ev_verify (EV_A); |
3784 | ev_verify (EV_A); |
3551 | #endif |
3785 | #endif |
3552 | |
3786 | |
3553 | #ifndef _WIN32 |
3787 | #ifndef _WIN32 |
3554 | if (expect_false (curpid)) /* penalise the forking check even more */ |
3788 | if (ecb_expect_false (curpid)) /* penalise the forking check even more */ |
3555 | if (expect_false (getpid () != curpid)) |
3789 | if (ecb_expect_false (getpid () != curpid)) |
3556 | { |
3790 | { |
3557 | curpid = getpid (); |
3791 | curpid = getpid (); |
3558 | postfork = 1; |
3792 | postfork = 1; |
3559 | } |
3793 | } |
3560 | #endif |
3794 | #endif |
3561 | |
3795 | |
3562 | #if EV_FORK_ENABLE |
3796 | #if EV_FORK_ENABLE |
3563 | /* we might have forked, so queue fork handlers */ |
3797 | /* we might have forked, so queue fork handlers */ |
3564 | if (expect_false (postfork)) |
3798 | if (ecb_expect_false (postfork)) |
3565 | if (forkcnt) |
3799 | if (forkcnt) |
3566 | { |
3800 | { |
3567 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3801 | queue_events (EV_A_ (W *)forks, forkcnt, EV_FORK); |
3568 | EV_INVOKE_PENDING; |
3802 | EV_INVOKE_PENDING; |
3569 | } |
3803 | } |
3570 | #endif |
3804 | #endif |
3571 | |
3805 | |
3572 | #if EV_PREPARE_ENABLE |
3806 | #if EV_PREPARE_ENABLE |
3573 | /* queue prepare watchers (and execute them) */ |
3807 | /* queue prepare watchers (and execute them) */ |
3574 | if (expect_false (preparecnt)) |
3808 | if (ecb_expect_false (preparecnt)) |
3575 | { |
3809 | { |
3576 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3810 | queue_events (EV_A_ (W *)prepares, preparecnt, EV_PREPARE); |
3577 | EV_INVOKE_PENDING; |
3811 | EV_INVOKE_PENDING; |
3578 | } |
3812 | } |
3579 | #endif |
3813 | #endif |
3580 | |
3814 | |
3581 | if (expect_false (loop_done)) |
3815 | if (ecb_expect_false (loop_done)) |
3582 | break; |
3816 | break; |
3583 | |
3817 | |
3584 | /* we might have forked, so reify kernel state if necessary */ |
3818 | /* we might have forked, so reify kernel state if necessary */ |
3585 | if (expect_false (postfork)) |
3819 | if (ecb_expect_false (postfork)) |
3586 | loop_fork (EV_A); |
3820 | loop_fork (EV_A); |
3587 | |
3821 | |
3588 | /* update fd-related kernel structures */ |
3822 | /* update fd-related kernel structures */ |
3589 | fd_reify (EV_A); |
3823 | fd_reify (EV_A); |
3590 | |
3824 | |
… | |
… | |
3595 | |
3829 | |
3596 | /* remember old timestamp for io_blocktime calculation */ |
3830 | /* remember old timestamp for io_blocktime calculation */ |
3597 | ev_tstamp prev_mn_now = mn_now; |
3831 | ev_tstamp prev_mn_now = mn_now; |
3598 | |
3832 | |
3599 | /* update time to cancel out callback processing overhead */ |
3833 | /* update time to cancel out callback processing overhead */ |
3600 | time_update (EV_A_ 1e100); |
3834 | time_update (EV_A_ EV_TS_CONST (EV_TSTAMP_HUGE)); |
3601 | |
3835 | |
3602 | /* from now on, we want a pipe-wake-up */ |
3836 | /* from now on, we want a pipe-wake-up */ |
3603 | pipe_write_wanted = 1; |
3837 | pipe_write_wanted = 1; |
3604 | |
3838 | |
3605 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3839 | ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */ |
3606 | |
3840 | |
3607 | if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3841 | if (ecb_expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) |
3608 | { |
3842 | { |
3609 | waittime = MAX_BLOCKTIME; |
3843 | waittime = EV_TS_CONST (MAX_BLOCKTIME); |
3610 | |
3844 | |
3611 | if (timercnt) |
3845 | if (timercnt) |
3612 | { |
3846 | { |
3613 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3847 | ev_tstamp to = ANHE_at (timers [HEAP0]) - mn_now; |
3614 | if (waittime > to) waittime = to; |
3848 | if (waittime > to) waittime = to; |
… | |
… | |
3621 | if (waittime > to) waittime = to; |
3855 | if (waittime > to) waittime = to; |
3622 | } |
3856 | } |
3623 | #endif |
3857 | #endif |
3624 | |
3858 | |
3625 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3859 | /* don't let timeouts decrease the waittime below timeout_blocktime */ |
3626 | if (expect_false (waittime < timeout_blocktime)) |
3860 | if (ecb_expect_false (waittime < timeout_blocktime)) |
3627 | waittime = timeout_blocktime; |
3861 | waittime = timeout_blocktime; |
3628 | |
3862 | |
3629 | /* at this point, we NEED to wait, so we have to ensure */ |
3863 | /* now there are two more special cases left, either we have |
3630 | /* to pass a minimum nonzero value to the backend */ |
3864 | * already-expired timers, so we should not sleep, or we have timers |
|
|
3865 | * that expire very soon, in which case we need to weait for a minimum |
|
|
3866 | * amount of time for some event loop backends |
|
|
3867 | */ |
3631 | if (expect_false (waittime < backend_mintime)) |
3868 | if (ecb_expect_false (waittime < backend_mintime)) |
|
|
3869 | waittime = waittime <= EV_TS_CONST (0.) |
|
|
3870 | ? EV_TS_CONST (0.) |
3632 | waittime = backend_mintime; |
3871 | : backend_mintime; |
3633 | |
3872 | |
3634 | /* extra check because io_blocktime is commonly 0 */ |
3873 | /* extra check because io_blocktime is commonly 0 */ |
3635 | if (expect_false (io_blocktime)) |
3874 | if (ecb_expect_false (io_blocktime)) |
3636 | { |
3875 | { |
3637 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3876 | sleeptime = io_blocktime - (mn_now - prev_mn_now); |
3638 | |
3877 | |
3639 | if (sleeptime > waittime - backend_mintime) |
3878 | if (sleeptime > waittime - backend_mintime) |
3640 | sleeptime = waittime - backend_mintime; |
3879 | sleeptime = waittime - backend_mintime; |
3641 | |
3880 | |
3642 | if (expect_true (sleeptime > 0.)) |
3881 | if (ecb_expect_true (sleeptime > EV_TS_CONST (0.))) |
3643 | { |
3882 | { |
3644 | ev_sleep (sleeptime); |
3883 | ev_sleep (sleeptime); |
3645 | waittime -= sleeptime; |
3884 | waittime -= sleeptime; |
3646 | } |
3885 | } |
3647 | } |
3886 | } |
… | |
… | |
3661 | { |
3900 | { |
3662 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3901 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3663 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3902 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3664 | } |
3903 | } |
3665 | |
3904 | |
3666 | |
|
|
3667 | /* update ev_rt_now, do magic */ |
3905 | /* update ev_rt_now, do magic */ |
3668 | time_update (EV_A_ waittime + sleeptime); |
3906 | time_update (EV_A_ waittime + sleeptime); |
3669 | } |
3907 | } |
3670 | |
3908 | |
3671 | /* queue pending timers and reschedule them */ |
3909 | /* queue pending timers and reschedule them */ |
… | |
… | |
3679 | idle_reify (EV_A); |
3917 | idle_reify (EV_A); |
3680 | #endif |
3918 | #endif |
3681 | |
3919 | |
3682 | #if EV_CHECK_ENABLE |
3920 | #if EV_CHECK_ENABLE |
3683 | /* queue check watchers, to be executed first */ |
3921 | /* queue check watchers, to be executed first */ |
3684 | if (expect_false (checkcnt)) |
3922 | if (ecb_expect_false (checkcnt)) |
3685 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3923 | queue_events (EV_A_ (W *)checks, checkcnt, EV_CHECK); |
3686 | #endif |
3924 | #endif |
3687 | |
3925 | |
3688 | EV_INVOKE_PENDING; |
3926 | EV_INVOKE_PENDING; |
3689 | } |
3927 | } |
3690 | while (expect_true ( |
3928 | while (ecb_expect_true ( |
3691 | activecnt |
3929 | activecnt |
3692 | && !loop_done |
3930 | && !loop_done |
3693 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3931 | && !(flags & (EVRUN_ONCE | EVRUN_NOWAIT)) |
3694 | )); |
3932 | )); |
3695 | |
3933 | |
… | |
… | |
3702 | |
3940 | |
3703 | return activecnt; |
3941 | return activecnt; |
3704 | } |
3942 | } |
3705 | |
3943 | |
3706 | void |
3944 | void |
3707 | ev_break (EV_P_ int how) EV_THROW |
3945 | ev_break (EV_P_ int how) EV_NOEXCEPT |
3708 | { |
3946 | { |
3709 | loop_done = how; |
3947 | loop_done = how; |
3710 | } |
3948 | } |
3711 | |
3949 | |
3712 | void |
3950 | void |
3713 | ev_ref (EV_P) EV_THROW |
3951 | ev_ref (EV_P) EV_NOEXCEPT |
3714 | { |
3952 | { |
3715 | ++activecnt; |
3953 | ++activecnt; |
3716 | } |
3954 | } |
3717 | |
3955 | |
3718 | void |
3956 | void |
3719 | ev_unref (EV_P) EV_THROW |
3957 | ev_unref (EV_P) EV_NOEXCEPT |
3720 | { |
3958 | { |
3721 | --activecnt; |
3959 | --activecnt; |
3722 | } |
3960 | } |
3723 | |
3961 | |
3724 | void |
3962 | void |
3725 | ev_now_update (EV_P) EV_THROW |
3963 | ev_now_update (EV_P) EV_NOEXCEPT |
3726 | { |
3964 | { |
3727 | time_update (EV_A_ 1e100); |
3965 | time_update (EV_A_ EV_TSTAMP_HUGE); |
3728 | } |
3966 | } |
3729 | |
3967 | |
3730 | void |
3968 | void |
3731 | ev_suspend (EV_P) EV_THROW |
3969 | ev_suspend (EV_P) EV_NOEXCEPT |
3732 | { |
3970 | { |
3733 | ev_now_update (EV_A); |
3971 | ev_now_update (EV_A); |
3734 | } |
3972 | } |
3735 | |
3973 | |
3736 | void |
3974 | void |
3737 | ev_resume (EV_P) EV_THROW |
3975 | ev_resume (EV_P) EV_NOEXCEPT |
3738 | { |
3976 | { |
3739 | ev_tstamp mn_prev = mn_now; |
3977 | ev_tstamp mn_prev = mn_now; |
3740 | |
3978 | |
3741 | ev_now_update (EV_A); |
3979 | ev_now_update (EV_A); |
3742 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3980 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3759 | inline_size void |
3997 | inline_size void |
3760 | wlist_del (WL *head, WL elem) |
3998 | wlist_del (WL *head, WL elem) |
3761 | { |
3999 | { |
3762 | while (*head) |
4000 | while (*head) |
3763 | { |
4001 | { |
3764 | if (expect_true (*head == elem)) |
4002 | if (ecb_expect_true (*head == elem)) |
3765 | { |
4003 | { |
3766 | *head = elem->next; |
4004 | *head = elem->next; |
3767 | break; |
4005 | break; |
3768 | } |
4006 | } |
3769 | |
4007 | |
… | |
… | |
3781 | w->pending = 0; |
4019 | w->pending = 0; |
3782 | } |
4020 | } |
3783 | } |
4021 | } |
3784 | |
4022 | |
3785 | int |
4023 | int |
3786 | ev_clear_pending (EV_P_ void *w) EV_THROW |
4024 | ev_clear_pending (EV_P_ void *w) EV_NOEXCEPT |
3787 | { |
4025 | { |
3788 | W w_ = (W)w; |
4026 | W w_ = (W)w; |
3789 | int pending = w_->pending; |
4027 | int pending = w_->pending; |
3790 | |
4028 | |
3791 | if (expect_true (pending)) |
4029 | if (ecb_expect_true (pending)) |
3792 | { |
4030 | { |
3793 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
4031 | ANPENDING *p = pendings [ABSPRI (w_)] + pending - 1; |
3794 | p->w = (W)&pending_w; |
4032 | p->w = (W)&pending_w; |
3795 | w_->pending = 0; |
4033 | w_->pending = 0; |
3796 | return p->events; |
4034 | return p->events; |
… | |
… | |
3823 | w->active = 0; |
4061 | w->active = 0; |
3824 | } |
4062 | } |
3825 | |
4063 | |
3826 | /*****************************************************************************/ |
4064 | /*****************************************************************************/ |
3827 | |
4065 | |
3828 | void noinline |
4066 | ecb_noinline |
|
|
4067 | void |
3829 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
4068 | ev_io_start (EV_P_ ev_io *w) EV_NOEXCEPT |
3830 | { |
4069 | { |
3831 | int fd = w->fd; |
4070 | int fd = w->fd; |
3832 | |
4071 | |
3833 | if (expect_false (ev_is_active (w))) |
4072 | if (ecb_expect_false (ev_is_active (w))) |
3834 | return; |
4073 | return; |
3835 | |
4074 | |
3836 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
4075 | assert (("libev: ev_io_start called with negative fd", fd >= 0)); |
3837 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
4076 | assert (("libev: ev_io_start called with illegal event mask", !(w->events & ~(EV__IOFDSET | EV_READ | EV_WRITE)))); |
3838 | |
4077 | |
|
|
4078 | #if EV_VERIFY >= 2 |
|
|
4079 | assert (("libev: ev_io_start called on watcher with invalid fd", fd_valid (fd))); |
|
|
4080 | #endif |
3839 | EV_FREQUENT_CHECK; |
4081 | EV_FREQUENT_CHECK; |
3840 | |
4082 | |
3841 | ev_start (EV_A_ (W)w, 1); |
4083 | ev_start (EV_A_ (W)w, 1); |
3842 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
4084 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_needsize_zerofill); |
3843 | wlist_add (&anfds[fd].head, (WL)w); |
4085 | wlist_add (&anfds[fd].head, (WL)w); |
3844 | |
4086 | |
3845 | /* common bug, apparently */ |
4087 | /* common bug, apparently */ |
3846 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
4088 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
3847 | |
4089 | |
… | |
… | |
3849 | w->events &= ~EV__IOFDSET; |
4091 | w->events &= ~EV__IOFDSET; |
3850 | |
4092 | |
3851 | EV_FREQUENT_CHECK; |
4093 | EV_FREQUENT_CHECK; |
3852 | } |
4094 | } |
3853 | |
4095 | |
3854 | void noinline |
4096 | ecb_noinline |
|
|
4097 | void |
3855 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
4098 | ev_io_stop (EV_P_ ev_io *w) EV_NOEXCEPT |
3856 | { |
4099 | { |
3857 | clear_pending (EV_A_ (W)w); |
4100 | clear_pending (EV_A_ (W)w); |
3858 | if (expect_false (!ev_is_active (w))) |
4101 | if (ecb_expect_false (!ev_is_active (w))) |
3859 | return; |
4102 | return; |
3860 | |
4103 | |
3861 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
4104 | assert (("libev: ev_io_stop called with illegal fd (must stay constant after start!)", w->fd >= 0 && w->fd < anfdmax)); |
3862 | |
4105 | |
|
|
4106 | #if EV_VERIFY >= 2 |
|
|
4107 | assert (("libev: ev_io_stop called on watcher with invalid fd", fd_valid (w->fd))); |
|
|
4108 | #endif |
3863 | EV_FREQUENT_CHECK; |
4109 | EV_FREQUENT_CHECK; |
3864 | |
4110 | |
3865 | wlist_del (&anfds[w->fd].head, (WL)w); |
4111 | wlist_del (&anfds[w->fd].head, (WL)w); |
3866 | ev_stop (EV_A_ (W)w); |
4112 | ev_stop (EV_A_ (W)w); |
3867 | |
4113 | |
3868 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
4114 | fd_change (EV_A_ w->fd, EV_ANFD_REIFY); |
3869 | |
4115 | |
3870 | EV_FREQUENT_CHECK; |
4116 | EV_FREQUENT_CHECK; |
3871 | } |
4117 | } |
3872 | |
4118 | |
3873 | void noinline |
4119 | ecb_noinline |
|
|
4120 | void |
3874 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
4121 | ev_timer_start (EV_P_ ev_timer *w) EV_NOEXCEPT |
3875 | { |
4122 | { |
3876 | if (expect_false (ev_is_active (w))) |
4123 | if (ecb_expect_false (ev_is_active (w))) |
3877 | return; |
4124 | return; |
3878 | |
4125 | |
3879 | ev_at (w) += mn_now; |
4126 | ev_at (w) += mn_now; |
3880 | |
4127 | |
3881 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
4128 | assert (("libev: ev_timer_start called with negative timer repeat value", w->repeat >= 0.)); |
3882 | |
4129 | |
3883 | EV_FREQUENT_CHECK; |
4130 | EV_FREQUENT_CHECK; |
3884 | |
4131 | |
3885 | ++timercnt; |
4132 | ++timercnt; |
3886 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
4133 | ev_start (EV_A_ (W)w, timercnt + HEAP0 - 1); |
3887 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, EMPTY2); |
4134 | array_needsize (ANHE, timers, timermax, ev_active (w) + 1, array_needsize_noinit); |
3888 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
4135 | ANHE_w (timers [ev_active (w)]) = (WT)w; |
3889 | ANHE_at_cache (timers [ev_active (w)]); |
4136 | ANHE_at_cache (timers [ev_active (w)]); |
3890 | upheap (timers, ev_active (w)); |
4137 | upheap (timers, ev_active (w)); |
3891 | |
4138 | |
3892 | EV_FREQUENT_CHECK; |
4139 | EV_FREQUENT_CHECK; |
3893 | |
4140 | |
3894 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
4141 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3895 | } |
4142 | } |
3896 | |
4143 | |
3897 | void noinline |
4144 | ecb_noinline |
|
|
4145 | void |
3898 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
4146 | ev_timer_stop (EV_P_ ev_timer *w) EV_NOEXCEPT |
3899 | { |
4147 | { |
3900 | clear_pending (EV_A_ (W)w); |
4148 | clear_pending (EV_A_ (W)w); |
3901 | if (expect_false (!ev_is_active (w))) |
4149 | if (ecb_expect_false (!ev_is_active (w))) |
3902 | return; |
4150 | return; |
3903 | |
4151 | |
3904 | EV_FREQUENT_CHECK; |
4152 | EV_FREQUENT_CHECK; |
3905 | |
4153 | |
3906 | { |
4154 | { |
… | |
… | |
3908 | |
4156 | |
3909 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
4157 | assert (("libev: internal timer heap corruption", ANHE_w (timers [active]) == (WT)w)); |
3910 | |
4158 | |
3911 | --timercnt; |
4159 | --timercnt; |
3912 | |
4160 | |
3913 | if (expect_true (active < timercnt + HEAP0)) |
4161 | if (ecb_expect_true (active < timercnt + HEAP0)) |
3914 | { |
4162 | { |
3915 | timers [active] = timers [timercnt + HEAP0]; |
4163 | timers [active] = timers [timercnt + HEAP0]; |
3916 | adjustheap (timers, timercnt, active); |
4164 | adjustheap (timers, timercnt, active); |
3917 | } |
4165 | } |
3918 | } |
4166 | } |
… | |
… | |
3922 | ev_stop (EV_A_ (W)w); |
4170 | ev_stop (EV_A_ (W)w); |
3923 | |
4171 | |
3924 | EV_FREQUENT_CHECK; |
4172 | EV_FREQUENT_CHECK; |
3925 | } |
4173 | } |
3926 | |
4174 | |
3927 | void noinline |
4175 | ecb_noinline |
|
|
4176 | void |
3928 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
4177 | ev_timer_again (EV_P_ ev_timer *w) EV_NOEXCEPT |
3929 | { |
4178 | { |
3930 | EV_FREQUENT_CHECK; |
4179 | EV_FREQUENT_CHECK; |
3931 | |
4180 | |
3932 | clear_pending (EV_A_ (W)w); |
4181 | clear_pending (EV_A_ (W)w); |
3933 | |
4182 | |
… | |
… | |
3950 | |
4199 | |
3951 | EV_FREQUENT_CHECK; |
4200 | EV_FREQUENT_CHECK; |
3952 | } |
4201 | } |
3953 | |
4202 | |
3954 | ev_tstamp |
4203 | ev_tstamp |
3955 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
4204 | ev_timer_remaining (EV_P_ ev_timer *w) EV_NOEXCEPT |
3956 | { |
4205 | { |
3957 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
4206 | return ev_at (w) - (ev_is_active (w) ? mn_now : EV_TS_CONST (0.)); |
3958 | } |
4207 | } |
3959 | |
4208 | |
3960 | #if EV_PERIODIC_ENABLE |
4209 | #if EV_PERIODIC_ENABLE |
3961 | void noinline |
4210 | ecb_noinline |
|
|
4211 | void |
3962 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
4212 | ev_periodic_start (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3963 | { |
4213 | { |
3964 | if (expect_false (ev_is_active (w))) |
4214 | if (ecb_expect_false (ev_is_active (w))) |
3965 | return; |
4215 | return; |
3966 | |
4216 | |
3967 | if (w->reschedule_cb) |
4217 | if (w->reschedule_cb) |
3968 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
4218 | ev_at (w) = w->reschedule_cb (w, ev_rt_now); |
3969 | else if (w->interval) |
4219 | else if (w->interval) |
… | |
… | |
3976 | |
4226 | |
3977 | EV_FREQUENT_CHECK; |
4227 | EV_FREQUENT_CHECK; |
3978 | |
4228 | |
3979 | ++periodiccnt; |
4229 | ++periodiccnt; |
3980 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
4230 | ev_start (EV_A_ (W)w, periodiccnt + HEAP0 - 1); |
3981 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, EMPTY2); |
4231 | array_needsize (ANHE, periodics, periodicmax, ev_active (w) + 1, array_needsize_noinit); |
3982 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
4232 | ANHE_w (periodics [ev_active (w)]) = (WT)w; |
3983 | ANHE_at_cache (periodics [ev_active (w)]); |
4233 | ANHE_at_cache (periodics [ev_active (w)]); |
3984 | upheap (periodics, ev_active (w)); |
4234 | upheap (periodics, ev_active (w)); |
3985 | |
4235 | |
3986 | EV_FREQUENT_CHECK; |
4236 | EV_FREQUENT_CHECK; |
3987 | |
4237 | |
3988 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
4238 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3989 | } |
4239 | } |
3990 | |
4240 | |
3991 | void noinline |
4241 | ecb_noinline |
|
|
4242 | void |
3992 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
4243 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_NOEXCEPT |
3993 | { |
4244 | { |
3994 | clear_pending (EV_A_ (W)w); |
4245 | clear_pending (EV_A_ (W)w); |
3995 | if (expect_false (!ev_is_active (w))) |
4246 | if (ecb_expect_false (!ev_is_active (w))) |
3996 | return; |
4247 | return; |
3997 | |
4248 | |
3998 | EV_FREQUENT_CHECK; |
4249 | EV_FREQUENT_CHECK; |
3999 | |
4250 | |
4000 | { |
4251 | { |
… | |
… | |
4002 | |
4253 | |
4003 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4254 | assert (("libev: internal periodic heap corruption", ANHE_w (periodics [active]) == (WT)w)); |
4004 | |
4255 | |
4005 | --periodiccnt; |
4256 | --periodiccnt; |
4006 | |
4257 | |
4007 | if (expect_true (active < periodiccnt + HEAP0)) |
4258 | if (ecb_expect_true (active < periodiccnt + HEAP0)) |
4008 | { |
4259 | { |
4009 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4260 | periodics [active] = periodics [periodiccnt + HEAP0]; |
4010 | adjustheap (periodics, periodiccnt, active); |
4261 | adjustheap (periodics, periodiccnt, active); |
4011 | } |
4262 | } |
4012 | } |
4263 | } |
… | |
… | |
4014 | ev_stop (EV_A_ (W)w); |
4265 | ev_stop (EV_A_ (W)w); |
4015 | |
4266 | |
4016 | EV_FREQUENT_CHECK; |
4267 | EV_FREQUENT_CHECK; |
4017 | } |
4268 | } |
4018 | |
4269 | |
4019 | void noinline |
4270 | ecb_noinline |
|
|
4271 | void |
4020 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
4272 | ev_periodic_again (EV_P_ ev_periodic *w) EV_NOEXCEPT |
4021 | { |
4273 | { |
4022 | /* TODO: use adjustheap and recalculation */ |
4274 | /* TODO: use adjustheap and recalculation */ |
4023 | ev_periodic_stop (EV_A_ w); |
4275 | ev_periodic_stop (EV_A_ w); |
4024 | ev_periodic_start (EV_A_ w); |
4276 | ev_periodic_start (EV_A_ w); |
4025 | } |
4277 | } |
… | |
… | |
4029 | # define SA_RESTART 0 |
4281 | # define SA_RESTART 0 |
4030 | #endif |
4282 | #endif |
4031 | |
4283 | |
4032 | #if EV_SIGNAL_ENABLE |
4284 | #if EV_SIGNAL_ENABLE |
4033 | |
4285 | |
4034 | void noinline |
4286 | ecb_noinline |
|
|
4287 | void |
4035 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
4288 | ev_signal_start (EV_P_ ev_signal *w) EV_NOEXCEPT |
4036 | { |
4289 | { |
4037 | if (expect_false (ev_is_active (w))) |
4290 | if (ecb_expect_false (ev_is_active (w))) |
4038 | return; |
4291 | return; |
4039 | |
4292 | |
4040 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4293 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
4041 | |
4294 | |
4042 | #if EV_MULTIPLICITY |
4295 | #if EV_MULTIPLICITY |
… | |
… | |
4111 | } |
4364 | } |
4112 | |
4365 | |
4113 | EV_FREQUENT_CHECK; |
4366 | EV_FREQUENT_CHECK; |
4114 | } |
4367 | } |
4115 | |
4368 | |
4116 | void noinline |
4369 | ecb_noinline |
|
|
4370 | void |
4117 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
4371 | ev_signal_stop (EV_P_ ev_signal *w) EV_NOEXCEPT |
4118 | { |
4372 | { |
4119 | clear_pending (EV_A_ (W)w); |
4373 | clear_pending (EV_A_ (W)w); |
4120 | if (expect_false (!ev_is_active (w))) |
4374 | if (ecb_expect_false (!ev_is_active (w))) |
4121 | return; |
4375 | return; |
4122 | |
4376 | |
4123 | EV_FREQUENT_CHECK; |
4377 | EV_FREQUENT_CHECK; |
4124 | |
4378 | |
4125 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
4379 | wlist_del (&signals [w->signum - 1].head, (WL)w); |
… | |
… | |
4153 | #endif |
4407 | #endif |
4154 | |
4408 | |
4155 | #if EV_CHILD_ENABLE |
4409 | #if EV_CHILD_ENABLE |
4156 | |
4410 | |
4157 | void |
4411 | void |
4158 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
4412 | ev_child_start (EV_P_ ev_child *w) EV_NOEXCEPT |
4159 | { |
4413 | { |
4160 | #if EV_MULTIPLICITY |
4414 | #if EV_MULTIPLICITY |
4161 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4415 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
4162 | #endif |
4416 | #endif |
4163 | if (expect_false (ev_is_active (w))) |
4417 | if (ecb_expect_false (ev_is_active (w))) |
4164 | return; |
4418 | return; |
4165 | |
4419 | |
4166 | EV_FREQUENT_CHECK; |
4420 | EV_FREQUENT_CHECK; |
4167 | |
4421 | |
4168 | ev_start (EV_A_ (W)w, 1); |
4422 | ev_start (EV_A_ (W)w, 1); |
… | |
… | |
4170 | |
4424 | |
4171 | EV_FREQUENT_CHECK; |
4425 | EV_FREQUENT_CHECK; |
4172 | } |
4426 | } |
4173 | |
4427 | |
4174 | void |
4428 | void |
4175 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
4429 | ev_child_stop (EV_P_ ev_child *w) EV_NOEXCEPT |
4176 | { |
4430 | { |
4177 | clear_pending (EV_A_ (W)w); |
4431 | clear_pending (EV_A_ (W)w); |
4178 | if (expect_false (!ev_is_active (w))) |
4432 | if (ecb_expect_false (!ev_is_active (w))) |
4179 | return; |
4433 | return; |
4180 | |
4434 | |
4181 | EV_FREQUENT_CHECK; |
4435 | EV_FREQUENT_CHECK; |
4182 | |
4436 | |
4183 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
4437 | wlist_del (&childs [w->pid & ((EV_PID_HASHSIZE) - 1)], (WL)w); |
… | |
… | |
4197 | |
4451 | |
4198 | #define DEF_STAT_INTERVAL 5.0074891 |
4452 | #define DEF_STAT_INTERVAL 5.0074891 |
4199 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4453 | #define NFS_STAT_INTERVAL 30.1074891 /* for filesystems potentially failing inotify */ |
4200 | #define MIN_STAT_INTERVAL 0.1074891 |
4454 | #define MIN_STAT_INTERVAL 0.1074891 |
4201 | |
4455 | |
4202 | static void noinline stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4456 | ecb_noinline static void stat_timer_cb (EV_P_ ev_timer *w_, int revents); |
4203 | |
4457 | |
4204 | #if EV_USE_INOTIFY |
4458 | #if EV_USE_INOTIFY |
4205 | |
4459 | |
4206 | /* the * 2 is to allow for alignment padding, which for some reason is >> 8 */ |
4460 | /* 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) |
4461 | # define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) |
4208 | |
4462 | |
4209 | static void noinline |
4463 | ecb_noinline |
|
|
4464 | static void |
4210 | infy_add (EV_P_ ev_stat *w) |
4465 | infy_add (EV_P_ ev_stat *w) |
4211 | { |
4466 | { |
4212 | w->wd = inotify_add_watch (fs_fd, w->path, |
4467 | w->wd = inotify_add_watch (fs_fd, w->path, |
4213 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4468 | IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY |
4214 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
4469 | | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO |
… | |
… | |
4278 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4533 | if (ev_is_active (&w->timer)) ev_ref (EV_A); |
4279 | ev_timer_again (EV_A_ &w->timer); |
4534 | ev_timer_again (EV_A_ &w->timer); |
4280 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4535 | if (ev_is_active (&w->timer)) ev_unref (EV_A); |
4281 | } |
4536 | } |
4282 | |
4537 | |
4283 | static void noinline |
4538 | ecb_noinline |
|
|
4539 | static void |
4284 | infy_del (EV_P_ ev_stat *w) |
4540 | infy_del (EV_P_ ev_stat *w) |
4285 | { |
4541 | { |
4286 | int slot; |
4542 | int slot; |
4287 | int wd = w->wd; |
4543 | int wd = w->wd; |
4288 | |
4544 | |
… | |
… | |
4295 | |
4551 | |
4296 | /* remove this watcher, if others are watching it, they will rearm */ |
4552 | /* remove this watcher, if others are watching it, they will rearm */ |
4297 | inotify_rm_watch (fs_fd, wd); |
4553 | inotify_rm_watch (fs_fd, wd); |
4298 | } |
4554 | } |
4299 | |
4555 | |
4300 | static void noinline |
4556 | ecb_noinline |
|
|
4557 | static void |
4301 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4558 | infy_wd (EV_P_ int slot, int wd, struct inotify_event *ev) |
4302 | { |
4559 | { |
4303 | if (slot < 0) |
4560 | if (slot < 0) |
4304 | /* overflow, need to check for all hash slots */ |
4561 | /* overflow, need to check for all hash slots */ |
4305 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
4562 | for (slot = 0; slot < (EV_INOTIFY_HASHSIZE); ++slot) |
… | |
… | |
4341 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4598 | infy_wd (EV_A_ ev->wd, ev->wd, ev); |
4342 | ofs += sizeof (struct inotify_event) + ev->len; |
4599 | ofs += sizeof (struct inotify_event) + ev->len; |
4343 | } |
4600 | } |
4344 | } |
4601 | } |
4345 | |
4602 | |
4346 | inline_size void ecb_cold |
4603 | inline_size ecb_cold |
|
|
4604 | void |
4347 | ev_check_2625 (EV_P) |
4605 | ev_check_2625 (EV_P) |
4348 | { |
4606 | { |
4349 | /* kernels < 2.6.25 are borked |
4607 | /* kernels < 2.6.25 are borked |
4350 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4608 | * http://www.ussg.indiana.edu/hypermail/linux/kernel/0711.3/1208.html |
4351 | */ |
4609 | */ |
… | |
… | |
4441 | #else |
4699 | #else |
4442 | # define EV_LSTAT(p,b) lstat (p, b) |
4700 | # define EV_LSTAT(p,b) lstat (p, b) |
4443 | #endif |
4701 | #endif |
4444 | |
4702 | |
4445 | void |
4703 | void |
4446 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
4704 | ev_stat_stat (EV_P_ ev_stat *w) EV_NOEXCEPT |
4447 | { |
4705 | { |
4448 | if (lstat (w->path, &w->attr) < 0) |
4706 | if (lstat (w->path, &w->attr) < 0) |
4449 | w->attr.st_nlink = 0; |
4707 | w->attr.st_nlink = 0; |
4450 | else if (!w->attr.st_nlink) |
4708 | else if (!w->attr.st_nlink) |
4451 | w->attr.st_nlink = 1; |
4709 | w->attr.st_nlink = 1; |
4452 | } |
4710 | } |
4453 | |
4711 | |
4454 | static void noinline |
4712 | ecb_noinline |
|
|
4713 | static void |
4455 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4714 | stat_timer_cb (EV_P_ ev_timer *w_, int revents) |
4456 | { |
4715 | { |
4457 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4716 | ev_stat *w = (ev_stat *)(((char *)w_) - offsetof (ev_stat, timer)); |
4458 | |
4717 | |
4459 | ev_statdata prev = w->attr; |
4718 | ev_statdata prev = w->attr; |
… | |
… | |
4490 | ev_feed_event (EV_A_ w, EV_STAT); |
4749 | ev_feed_event (EV_A_ w, EV_STAT); |
4491 | } |
4750 | } |
4492 | } |
4751 | } |
4493 | |
4752 | |
4494 | void |
4753 | void |
4495 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
4754 | ev_stat_start (EV_P_ ev_stat *w) EV_NOEXCEPT |
4496 | { |
4755 | { |
4497 | if (expect_false (ev_is_active (w))) |
4756 | if (ecb_expect_false (ev_is_active (w))) |
4498 | return; |
4757 | return; |
4499 | |
4758 | |
4500 | ev_stat_stat (EV_A_ w); |
4759 | ev_stat_stat (EV_A_ w); |
4501 | |
4760 | |
4502 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
4761 | if (w->interval < MIN_STAT_INTERVAL && w->interval) |
… | |
… | |
4521 | |
4780 | |
4522 | EV_FREQUENT_CHECK; |
4781 | EV_FREQUENT_CHECK; |
4523 | } |
4782 | } |
4524 | |
4783 | |
4525 | void |
4784 | void |
4526 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
4785 | ev_stat_stop (EV_P_ ev_stat *w) EV_NOEXCEPT |
4527 | { |
4786 | { |
4528 | clear_pending (EV_A_ (W)w); |
4787 | clear_pending (EV_A_ (W)w); |
4529 | if (expect_false (!ev_is_active (w))) |
4788 | if (ecb_expect_false (!ev_is_active (w))) |
4530 | return; |
4789 | return; |
4531 | |
4790 | |
4532 | EV_FREQUENT_CHECK; |
4791 | EV_FREQUENT_CHECK; |
4533 | |
4792 | |
4534 | #if EV_USE_INOTIFY |
4793 | #if EV_USE_INOTIFY |
… | |
… | |
4547 | } |
4806 | } |
4548 | #endif |
4807 | #endif |
4549 | |
4808 | |
4550 | #if EV_IDLE_ENABLE |
4809 | #if EV_IDLE_ENABLE |
4551 | void |
4810 | void |
4552 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
4811 | ev_idle_start (EV_P_ ev_idle *w) EV_NOEXCEPT |
4553 | { |
4812 | { |
4554 | if (expect_false (ev_is_active (w))) |
4813 | if (ecb_expect_false (ev_is_active (w))) |
4555 | return; |
4814 | return; |
4556 | |
4815 | |
4557 | pri_adjust (EV_A_ (W)w); |
4816 | pri_adjust (EV_A_ (W)w); |
4558 | |
4817 | |
4559 | EV_FREQUENT_CHECK; |
4818 | EV_FREQUENT_CHECK; |
… | |
… | |
4562 | int active = ++idlecnt [ABSPRI (w)]; |
4821 | int active = ++idlecnt [ABSPRI (w)]; |
4563 | |
4822 | |
4564 | ++idleall; |
4823 | ++idleall; |
4565 | ev_start (EV_A_ (W)w, active); |
4824 | ev_start (EV_A_ (W)w, active); |
4566 | |
4825 | |
4567 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, EMPTY2); |
4826 | array_needsize (ev_idle *, idles [ABSPRI (w)], idlemax [ABSPRI (w)], active, array_needsize_noinit); |
4568 | idles [ABSPRI (w)][active - 1] = w; |
4827 | idles [ABSPRI (w)][active - 1] = w; |
4569 | } |
4828 | } |
4570 | |
4829 | |
4571 | EV_FREQUENT_CHECK; |
4830 | EV_FREQUENT_CHECK; |
4572 | } |
4831 | } |
4573 | |
4832 | |
4574 | void |
4833 | void |
4575 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
4834 | ev_idle_stop (EV_P_ ev_idle *w) EV_NOEXCEPT |
4576 | { |
4835 | { |
4577 | clear_pending (EV_A_ (W)w); |
4836 | clear_pending (EV_A_ (W)w); |
4578 | if (expect_false (!ev_is_active (w))) |
4837 | if (ecb_expect_false (!ev_is_active (w))) |
4579 | return; |
4838 | return; |
4580 | |
4839 | |
4581 | EV_FREQUENT_CHECK; |
4840 | EV_FREQUENT_CHECK; |
4582 | |
4841 | |
4583 | { |
4842 | { |
… | |
… | |
4594 | } |
4853 | } |
4595 | #endif |
4854 | #endif |
4596 | |
4855 | |
4597 | #if EV_PREPARE_ENABLE |
4856 | #if EV_PREPARE_ENABLE |
4598 | void |
4857 | void |
4599 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
4858 | ev_prepare_start (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4600 | { |
4859 | { |
4601 | if (expect_false (ev_is_active (w))) |
4860 | if (ecb_expect_false (ev_is_active (w))) |
4602 | return; |
4861 | return; |
4603 | |
4862 | |
4604 | EV_FREQUENT_CHECK; |
4863 | EV_FREQUENT_CHECK; |
4605 | |
4864 | |
4606 | ev_start (EV_A_ (W)w, ++preparecnt); |
4865 | ev_start (EV_A_ (W)w, ++preparecnt); |
4607 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, EMPTY2); |
4866 | array_needsize (ev_prepare *, prepares, preparemax, preparecnt, array_needsize_noinit); |
4608 | prepares [preparecnt - 1] = w; |
4867 | prepares [preparecnt - 1] = w; |
4609 | |
4868 | |
4610 | EV_FREQUENT_CHECK; |
4869 | EV_FREQUENT_CHECK; |
4611 | } |
4870 | } |
4612 | |
4871 | |
4613 | void |
4872 | void |
4614 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
4873 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_NOEXCEPT |
4615 | { |
4874 | { |
4616 | clear_pending (EV_A_ (W)w); |
4875 | clear_pending (EV_A_ (W)w); |
4617 | if (expect_false (!ev_is_active (w))) |
4876 | if (ecb_expect_false (!ev_is_active (w))) |
4618 | return; |
4877 | return; |
4619 | |
4878 | |
4620 | EV_FREQUENT_CHECK; |
4879 | EV_FREQUENT_CHECK; |
4621 | |
4880 | |
4622 | { |
4881 | { |
… | |
… | |
4632 | } |
4891 | } |
4633 | #endif |
4892 | #endif |
4634 | |
4893 | |
4635 | #if EV_CHECK_ENABLE |
4894 | #if EV_CHECK_ENABLE |
4636 | void |
4895 | void |
4637 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
4896 | ev_check_start (EV_P_ ev_check *w) EV_NOEXCEPT |
4638 | { |
4897 | { |
4639 | if (expect_false (ev_is_active (w))) |
4898 | if (ecb_expect_false (ev_is_active (w))) |
4640 | return; |
4899 | return; |
4641 | |
4900 | |
4642 | EV_FREQUENT_CHECK; |
4901 | EV_FREQUENT_CHECK; |
4643 | |
4902 | |
4644 | ev_start (EV_A_ (W)w, ++checkcnt); |
4903 | ev_start (EV_A_ (W)w, ++checkcnt); |
4645 | array_needsize (ev_check *, checks, checkmax, checkcnt, EMPTY2); |
4904 | array_needsize (ev_check *, checks, checkmax, checkcnt, array_needsize_noinit); |
4646 | checks [checkcnt - 1] = w; |
4905 | checks [checkcnt - 1] = w; |
4647 | |
4906 | |
4648 | EV_FREQUENT_CHECK; |
4907 | EV_FREQUENT_CHECK; |
4649 | } |
4908 | } |
4650 | |
4909 | |
4651 | void |
4910 | void |
4652 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
4911 | ev_check_stop (EV_P_ ev_check *w) EV_NOEXCEPT |
4653 | { |
4912 | { |
4654 | clear_pending (EV_A_ (W)w); |
4913 | clear_pending (EV_A_ (W)w); |
4655 | if (expect_false (!ev_is_active (w))) |
4914 | if (ecb_expect_false (!ev_is_active (w))) |
4656 | return; |
4915 | return; |
4657 | |
4916 | |
4658 | EV_FREQUENT_CHECK; |
4917 | EV_FREQUENT_CHECK; |
4659 | |
4918 | |
4660 | { |
4919 | { |
… | |
… | |
4669 | EV_FREQUENT_CHECK; |
4928 | EV_FREQUENT_CHECK; |
4670 | } |
4929 | } |
4671 | #endif |
4930 | #endif |
4672 | |
4931 | |
4673 | #if EV_EMBED_ENABLE |
4932 | #if EV_EMBED_ENABLE |
4674 | void noinline |
4933 | ecb_noinline |
|
|
4934 | void |
4675 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
4935 | ev_embed_sweep (EV_P_ ev_embed *w) EV_NOEXCEPT |
4676 | { |
4936 | { |
4677 | ev_run (w->other, EVRUN_NOWAIT); |
4937 | ev_run (w->other, EVRUN_NOWAIT); |
4678 | } |
4938 | } |
4679 | |
4939 | |
4680 | static void |
4940 | static void |
… | |
… | |
4728 | ev_idle_stop (EV_A_ idle); |
4988 | ev_idle_stop (EV_A_ idle); |
4729 | } |
4989 | } |
4730 | #endif |
4990 | #endif |
4731 | |
4991 | |
4732 | void |
4992 | void |
4733 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4993 | ev_embed_start (EV_P_ ev_embed *w) EV_NOEXCEPT |
4734 | { |
4994 | { |
4735 | if (expect_false (ev_is_active (w))) |
4995 | if (ecb_expect_false (ev_is_active (w))) |
4736 | return; |
4996 | return; |
4737 | |
4997 | |
4738 | { |
4998 | { |
4739 | EV_P = w->other; |
4999 | EV_P = w->other; |
4740 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
5000 | assert (("libev: loop to be embedded is not embeddable", backend & ev_embeddable_backends ())); |
… | |
… | |
4759 | |
5019 | |
4760 | EV_FREQUENT_CHECK; |
5020 | EV_FREQUENT_CHECK; |
4761 | } |
5021 | } |
4762 | |
5022 | |
4763 | void |
5023 | void |
4764 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
5024 | ev_embed_stop (EV_P_ ev_embed *w) EV_NOEXCEPT |
4765 | { |
5025 | { |
4766 | clear_pending (EV_A_ (W)w); |
5026 | clear_pending (EV_A_ (W)w); |
4767 | if (expect_false (!ev_is_active (w))) |
5027 | if (ecb_expect_false (!ev_is_active (w))) |
4768 | return; |
5028 | return; |
4769 | |
5029 | |
4770 | EV_FREQUENT_CHECK; |
5030 | EV_FREQUENT_CHECK; |
4771 | |
5031 | |
4772 | ev_io_stop (EV_A_ &w->io); |
5032 | ev_io_stop (EV_A_ &w->io); |
… | |
… | |
4779 | } |
5039 | } |
4780 | #endif |
5040 | #endif |
4781 | |
5041 | |
4782 | #if EV_FORK_ENABLE |
5042 | #if EV_FORK_ENABLE |
4783 | void |
5043 | void |
4784 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
5044 | ev_fork_start (EV_P_ ev_fork *w) EV_NOEXCEPT |
4785 | { |
5045 | { |
4786 | if (expect_false (ev_is_active (w))) |
5046 | if (ecb_expect_false (ev_is_active (w))) |
4787 | return; |
5047 | return; |
4788 | |
5048 | |
4789 | EV_FREQUENT_CHECK; |
5049 | EV_FREQUENT_CHECK; |
4790 | |
5050 | |
4791 | ev_start (EV_A_ (W)w, ++forkcnt); |
5051 | ev_start (EV_A_ (W)w, ++forkcnt); |
4792 | array_needsize (ev_fork *, forks, forkmax, forkcnt, EMPTY2); |
5052 | array_needsize (ev_fork *, forks, forkmax, forkcnt, array_needsize_noinit); |
4793 | forks [forkcnt - 1] = w; |
5053 | forks [forkcnt - 1] = w; |
4794 | |
5054 | |
4795 | EV_FREQUENT_CHECK; |
5055 | EV_FREQUENT_CHECK; |
4796 | } |
5056 | } |
4797 | |
5057 | |
4798 | void |
5058 | void |
4799 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
5059 | ev_fork_stop (EV_P_ ev_fork *w) EV_NOEXCEPT |
4800 | { |
5060 | { |
4801 | clear_pending (EV_A_ (W)w); |
5061 | clear_pending (EV_A_ (W)w); |
4802 | if (expect_false (!ev_is_active (w))) |
5062 | if (ecb_expect_false (!ev_is_active (w))) |
4803 | return; |
5063 | return; |
4804 | |
5064 | |
4805 | EV_FREQUENT_CHECK; |
5065 | EV_FREQUENT_CHECK; |
4806 | |
5066 | |
4807 | { |
5067 | { |
… | |
… | |
4817 | } |
5077 | } |
4818 | #endif |
5078 | #endif |
4819 | |
5079 | |
4820 | #if EV_CLEANUP_ENABLE |
5080 | #if EV_CLEANUP_ENABLE |
4821 | void |
5081 | void |
4822 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
5082 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4823 | { |
5083 | { |
4824 | if (expect_false (ev_is_active (w))) |
5084 | if (ecb_expect_false (ev_is_active (w))) |
4825 | return; |
5085 | return; |
4826 | |
5086 | |
4827 | EV_FREQUENT_CHECK; |
5087 | EV_FREQUENT_CHECK; |
4828 | |
5088 | |
4829 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
5089 | ev_start (EV_A_ (W)w, ++cleanupcnt); |
4830 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, EMPTY2); |
5090 | array_needsize (ev_cleanup *, cleanups, cleanupmax, cleanupcnt, array_needsize_noinit); |
4831 | cleanups [cleanupcnt - 1] = w; |
5091 | cleanups [cleanupcnt - 1] = w; |
4832 | |
5092 | |
4833 | /* cleanup watchers should never keep a refcount on the loop */ |
5093 | /* cleanup watchers should never keep a refcount on the loop */ |
4834 | ev_unref (EV_A); |
5094 | ev_unref (EV_A); |
4835 | EV_FREQUENT_CHECK; |
5095 | EV_FREQUENT_CHECK; |
4836 | } |
5096 | } |
4837 | |
5097 | |
4838 | void |
5098 | void |
4839 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
5099 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_NOEXCEPT |
4840 | { |
5100 | { |
4841 | clear_pending (EV_A_ (W)w); |
5101 | clear_pending (EV_A_ (W)w); |
4842 | if (expect_false (!ev_is_active (w))) |
5102 | if (ecb_expect_false (!ev_is_active (w))) |
4843 | return; |
5103 | return; |
4844 | |
5104 | |
4845 | EV_FREQUENT_CHECK; |
5105 | EV_FREQUENT_CHECK; |
4846 | ev_ref (EV_A); |
5106 | ev_ref (EV_A); |
4847 | |
5107 | |
… | |
… | |
4858 | } |
5118 | } |
4859 | #endif |
5119 | #endif |
4860 | |
5120 | |
4861 | #if EV_ASYNC_ENABLE |
5121 | #if EV_ASYNC_ENABLE |
4862 | void |
5122 | void |
4863 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
5123 | ev_async_start (EV_P_ ev_async *w) EV_NOEXCEPT |
4864 | { |
5124 | { |
4865 | if (expect_false (ev_is_active (w))) |
5125 | if (ecb_expect_false (ev_is_active (w))) |
4866 | return; |
5126 | return; |
4867 | |
5127 | |
4868 | w->sent = 0; |
5128 | w->sent = 0; |
4869 | |
5129 | |
4870 | evpipe_init (EV_A); |
5130 | evpipe_init (EV_A); |
4871 | |
5131 | |
4872 | EV_FREQUENT_CHECK; |
5132 | EV_FREQUENT_CHECK; |
4873 | |
5133 | |
4874 | ev_start (EV_A_ (W)w, ++asynccnt); |
5134 | ev_start (EV_A_ (W)w, ++asynccnt); |
4875 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, EMPTY2); |
5135 | array_needsize (ev_async *, asyncs, asyncmax, asynccnt, array_needsize_noinit); |
4876 | asyncs [asynccnt - 1] = w; |
5136 | asyncs [asynccnt - 1] = w; |
4877 | |
5137 | |
4878 | EV_FREQUENT_CHECK; |
5138 | EV_FREQUENT_CHECK; |
4879 | } |
5139 | } |
4880 | |
5140 | |
4881 | void |
5141 | void |
4882 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
5142 | ev_async_stop (EV_P_ ev_async *w) EV_NOEXCEPT |
4883 | { |
5143 | { |
4884 | clear_pending (EV_A_ (W)w); |
5144 | clear_pending (EV_A_ (W)w); |
4885 | if (expect_false (!ev_is_active (w))) |
5145 | if (ecb_expect_false (!ev_is_active (w))) |
4886 | return; |
5146 | return; |
4887 | |
5147 | |
4888 | EV_FREQUENT_CHECK; |
5148 | EV_FREQUENT_CHECK; |
4889 | |
5149 | |
4890 | { |
5150 | { |
… | |
… | |
4898 | |
5158 | |
4899 | EV_FREQUENT_CHECK; |
5159 | EV_FREQUENT_CHECK; |
4900 | } |
5160 | } |
4901 | |
5161 | |
4902 | void |
5162 | void |
4903 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
5163 | ev_async_send (EV_P_ ev_async *w) EV_NOEXCEPT |
4904 | { |
5164 | { |
4905 | w->sent = 1; |
5165 | w->sent = 1; |
4906 | evpipe_write (EV_A_ &async_pending); |
5166 | evpipe_write (EV_A_ &async_pending); |
4907 | } |
5167 | } |
4908 | #endif |
5168 | #endif |
… | |
… | |
4945 | |
5205 | |
4946 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
5206 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4947 | } |
5207 | } |
4948 | |
5208 | |
4949 | void |
5209 | void |
4950 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
5210 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_NOEXCEPT |
4951 | { |
5211 | { |
4952 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
5212 | 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 | |
5213 | |
4960 | once->cb = cb; |
5214 | once->cb = cb; |
4961 | once->arg = arg; |
5215 | once->arg = arg; |
4962 | |
5216 | |
4963 | ev_init (&once->io, once_cb_io); |
5217 | ev_init (&once->io, once_cb_io); |
… | |
… | |
4976 | } |
5230 | } |
4977 | |
5231 | |
4978 | /*****************************************************************************/ |
5232 | /*****************************************************************************/ |
4979 | |
5233 | |
4980 | #if EV_WALK_ENABLE |
5234 | #if EV_WALK_ENABLE |
4981 | void ecb_cold |
5235 | ecb_cold |
|
|
5236 | void |
4982 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
5237 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_NOEXCEPT |
4983 | { |
5238 | { |
4984 | int i, j; |
5239 | int i, j; |
4985 | ev_watcher_list *wl, *wn; |
5240 | ev_watcher_list *wl, *wn; |
4986 | |
5241 | |
4987 | if (types & (EV_IO | EV_EMBED)) |
5242 | if (types & (EV_IO | EV_EMBED)) |