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 Marc Alexander Lehmann <libev@schmorp.de> |
4 | * Copyright (c) 2007,2008,2009,2010,2011,2012 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 | * |
… | |
… | |
59 | # endif |
59 | # endif |
60 | # ifndef EV_USE_MONOTONIC |
60 | # ifndef EV_USE_MONOTONIC |
61 | # define EV_USE_MONOTONIC 1 |
61 | # define EV_USE_MONOTONIC 1 |
62 | # endif |
62 | # endif |
63 | # endif |
63 | # endif |
64 | # elif !defined(EV_USE_CLOCK_SYSCALL) |
64 | # elif !defined EV_USE_CLOCK_SYSCALL |
65 | # define EV_USE_CLOCK_SYSCALL 0 |
65 | # define EV_USE_CLOCK_SYSCALL 0 |
66 | # endif |
66 | # endif |
67 | |
67 | |
68 | # if HAVE_CLOCK_GETTIME |
68 | # if HAVE_CLOCK_GETTIME |
69 | # ifndef EV_USE_MONOTONIC |
69 | # ifndef EV_USE_MONOTONIC |
… | |
… | |
183 | # include EV_H |
183 | # include EV_H |
184 | #else |
184 | #else |
185 | # include "ev.h" |
185 | # include "ev.h" |
186 | #endif |
186 | #endif |
187 | |
187 | |
|
|
188 | #if EV_NO_THREADS |
|
|
189 | # undef EV_NO_SMP |
|
|
190 | # define EV_NO_SMP 1 |
|
|
191 | # undef ECB_NO_THREADS |
|
|
192 | # define ECB_NO_THREADS 1 |
|
|
193 | #endif |
|
|
194 | #if EV_NO_SMP |
|
|
195 | # undef EV_NO_SMP |
|
|
196 | # define ECB_NO_SMP 1 |
|
|
197 | #endif |
|
|
198 | |
188 | #ifndef _WIN32 |
199 | #ifndef _WIN32 |
189 | # include <sys/time.h> |
200 | # include <sys/time.h> |
190 | # include <sys/wait.h> |
201 | # include <sys/wait.h> |
191 | # include <unistd.h> |
202 | # include <unistd.h> |
192 | #else |
203 | #else |
193 | # include <io.h> |
204 | # include <io.h> |
194 | # define WIN32_LEAN_AND_MEAN |
205 | # define WIN32_LEAN_AND_MEAN |
|
|
206 | # include <winsock2.h> |
195 | # include <windows.h> |
207 | # include <windows.h> |
196 | # ifndef EV_SELECT_IS_WINSOCKET |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
197 | # define EV_SELECT_IS_WINSOCKET 1 |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
198 | # endif |
210 | # endif |
199 | # undef EV_AVOID_STDIO |
211 | # undef EV_AVOID_STDIO |
… | |
… | |
208 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
209 | |
221 | |
210 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
222 | /* this block tries to deduce configuration from header-defined symbols and defaults */ |
211 | |
223 | |
212 | /* try to deduce the maximum number of signals on this platform */ |
224 | /* try to deduce the maximum number of signals on this platform */ |
213 | #if defined (EV_NSIG) |
225 | #if defined EV_NSIG |
214 | /* use what's provided */ |
226 | /* use what's provided */ |
215 | #elif defined (NSIG) |
227 | #elif defined NSIG |
216 | # define EV_NSIG (NSIG) |
228 | # define EV_NSIG (NSIG) |
217 | #elif defined(_NSIG) |
229 | #elif defined _NSIG |
218 | # define EV_NSIG (_NSIG) |
230 | # define EV_NSIG (_NSIG) |
219 | #elif defined (SIGMAX) |
231 | #elif defined SIGMAX |
220 | # define EV_NSIG (SIGMAX+1) |
232 | # define EV_NSIG (SIGMAX+1) |
221 | #elif defined (SIG_MAX) |
233 | #elif defined SIG_MAX |
222 | # define EV_NSIG (SIG_MAX+1) |
234 | # define EV_NSIG (SIG_MAX+1) |
223 | #elif defined (_SIG_MAX) |
235 | #elif defined _SIG_MAX |
224 | # define EV_NSIG (_SIG_MAX+1) |
236 | # define EV_NSIG (_SIG_MAX+1) |
225 | #elif defined (MAXSIG) |
237 | #elif defined MAXSIG |
226 | # define EV_NSIG (MAXSIG+1) |
238 | # define EV_NSIG (MAXSIG+1) |
227 | #elif defined (MAX_SIG) |
239 | #elif defined MAX_SIG |
228 | # define EV_NSIG (MAX_SIG+1) |
240 | # define EV_NSIG (MAX_SIG+1) |
229 | #elif defined (SIGARRAYSIZE) |
241 | #elif defined SIGARRAYSIZE |
230 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
231 | #elif defined (_sys_nsig) |
243 | #elif defined _sys_nsig |
232 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
233 | #else |
245 | #else |
234 | # error "unable to find value for NSIG, please report" |
246 | # error "unable to find value for NSIG, please report" |
235 | /* to make it compile regardless, just remove the above line, */ |
247 | /* to make it compile regardless, just remove the above line, */ |
236 | /* but consider reporting it, too! :) */ |
248 | /* but consider reporting it, too! :) */ |
… | |
… | |
248 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # define EV_USE_CLOCK_SYSCALL 0 |
249 | # endif |
261 | # endif |
250 | #endif |
262 | #endif |
251 | |
263 | |
252 | #ifndef EV_USE_MONOTONIC |
264 | #ifndef EV_USE_MONOTONIC |
253 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
254 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
255 | # else |
267 | # else |
256 | # define EV_USE_MONOTONIC 0 |
268 | # define EV_USE_MONOTONIC 0 |
257 | # endif |
269 | # endif |
258 | #endif |
270 | #endif |
… | |
… | |
348 | #endif |
360 | #endif |
349 | |
361 | |
350 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
362 | /* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ |
351 | /* which makes programs even slower. might work on other unices, too. */ |
363 | /* which makes programs even slower. might work on other unices, too. */ |
352 | #if EV_USE_CLOCK_SYSCALL |
364 | #if EV_USE_CLOCK_SYSCALL |
353 | # include <syscall.h> |
365 | # include <sys/syscall.h> |
354 | # ifdef SYS_clock_gettime |
366 | # ifdef SYS_clock_gettime |
355 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
356 | # undef EV_USE_MONOTONIC |
368 | # undef EV_USE_MONOTONIC |
357 | # define EV_USE_MONOTONIC 1 |
369 | # define EV_USE_MONOTONIC 1 |
358 | # else |
370 | # else |
… | |
… | |
384 | # define EV_USE_INOTIFY 0 |
396 | # define EV_USE_INOTIFY 0 |
385 | #endif |
397 | #endif |
386 | |
398 | |
387 | #if !EV_USE_NANOSLEEP |
399 | #if !EV_USE_NANOSLEEP |
388 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
400 | /* hp-ux has it in sys/time.h, which we unconditionally include above */ |
389 | # if !defined(_WIN32) && !defined(__hpux) |
401 | # if !defined _WIN32 && !defined __hpux |
390 | # include <sys/select.h> |
402 | # include <sys/select.h> |
391 | # endif |
403 | # endif |
392 | #endif |
404 | #endif |
393 | |
405 | |
394 | #if EV_USE_INOTIFY |
406 | #if EV_USE_INOTIFY |
… | |
… | |
397 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
409 | /* some very old inotify.h headers don't have IN_DONT_FOLLOW */ |
398 | # ifndef IN_DONT_FOLLOW |
410 | # ifndef IN_DONT_FOLLOW |
399 | # undef EV_USE_INOTIFY |
411 | # undef EV_USE_INOTIFY |
400 | # define EV_USE_INOTIFY 0 |
412 | # define EV_USE_INOTIFY 0 |
401 | # endif |
413 | # endif |
402 | #endif |
|
|
403 | |
|
|
404 | #if EV_SELECT_IS_WINSOCKET |
|
|
405 | # include <winsock.h> |
|
|
406 | #endif |
414 | #endif |
407 | |
415 | |
408 | #if EV_USE_EVENTFD |
416 | #if EV_USE_EVENTFD |
409 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
417 | /* our minimum requirement is glibc 2.7 which has the stub, but not the header */ |
410 | # include <stdint.h> |
418 | # include <stdint.h> |
… | |
… | |
467 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
475 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
468 | /* ECB.H BEGIN */ |
476 | /* ECB.H BEGIN */ |
469 | /* |
477 | /* |
470 | * libecb - http://software.schmorp.de/pkg/libecb |
478 | * libecb - http://software.schmorp.de/pkg/libecb |
471 | * |
479 | * |
472 | * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de> |
480 | * Copyright (©) 2009-2012 Marc Alexander Lehmann <libecb@schmorp.de> |
473 | * Copyright (©) 2011 Emanuele Giaquinta |
481 | * Copyright (©) 2011 Emanuele Giaquinta |
474 | * All rights reserved. |
482 | * All rights reserved. |
475 | * |
483 | * |
476 | * Redistribution and use in source and binary forms, with or without modifica- |
484 | * Redistribution and use in source and binary forms, with or without modifica- |
477 | * tion, are permitted provided that the following conditions are met: |
485 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
522 | * or so. |
530 | * or so. |
523 | * we try to detect these and simply assume they are not gcc - if they have |
531 | * we try to detect these and simply assume they are not gcc - if they have |
524 | * an issue with that they should have done it right in the first place. |
532 | * an issue with that they should have done it right in the first place. |
525 | */ |
533 | */ |
526 | #ifndef ECB_GCC_VERSION |
534 | #ifndef ECB_GCC_VERSION |
527 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
535 | #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__ |
528 | #define ECB_GCC_VERSION(major,minor) 0 |
536 | #define ECB_GCC_VERSION(major,minor) 0 |
529 | #else |
537 | #else |
530 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
538 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
531 | #endif |
539 | #endif |
532 | #endif |
540 | #endif |
… | |
… | |
534 | /*****************************************************************************/ |
542 | /*****************************************************************************/ |
535 | |
543 | |
536 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
544 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
537 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
545 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
538 | |
546 | |
|
|
547 | #if ECB_NO_THREADS |
|
|
548 | # define ECB_NO_SMP 1 |
|
|
549 | #endif |
|
|
550 | |
539 | #if ECB_NO_THREADS || ECB_NO_SMP |
551 | #if ECB_NO_THREADS || ECB_NO_SMP |
540 | #define ECB_MEMORY_FENCE do { } while (0) |
552 | #define ECB_MEMORY_FENCE do { } while (0) |
541 | #endif |
553 | #endif |
542 | |
554 | |
543 | #ifndef ECB_MEMORY_FENCE |
555 | #ifndef ECB_MEMORY_FENCE |
544 | #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__) |
556 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
545 | #if __i386__ |
557 | #if __i386 || __i386__ |
546 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
558 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
547 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
559 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
548 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
560 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
549 | #elif __amd64 |
561 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
550 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
551 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
563 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
552 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
564 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
553 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
565 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
554 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
566 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
555 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
567 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
556 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
568 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
557 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
569 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
558 | #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ |
570 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
559 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
571 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
560 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
572 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
|
|
573 | #elif __sparc || __sparc__ |
|
|
574 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
|
|
575 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
|
|
576 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
|
|
577 | #elif defined __s390__ || defined __s390x__ |
|
|
578 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
|
|
579 | #elif defined __mips__ |
|
|
580 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
581 | #elif defined __alpha__ |
|
|
582 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
561 | #endif |
583 | #endif |
562 | #endif |
584 | #endif |
563 | #endif |
585 | #endif |
564 | |
586 | |
565 | #ifndef ECB_MEMORY_FENCE |
587 | #ifndef ECB_MEMORY_FENCE |
566 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__) |
588 | #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
567 | #define ECB_MEMORY_FENCE __sync_synchronize () |
589 | #define ECB_MEMORY_FENCE __sync_synchronize () |
568 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
590 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
569 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
591 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
570 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
592 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
571 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
593 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
572 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
594 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
573 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
595 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
574 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
596 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
575 | #elif defined(_WIN32) |
597 | #elif defined _WIN32 |
576 | #include <WinNT.h> |
598 | #include <WinNT.h> |
577 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
599 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
|
|
600 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
601 | #include <mbarrier.h> |
|
|
602 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
|
|
603 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
|
|
604 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
605 | #elif __xlC__ |
|
|
606 | #define ECB_MEMORY_FENCE __sync () |
578 | #endif |
607 | #endif |
579 | #endif |
608 | #endif |
580 | |
609 | |
581 | #ifndef ECB_MEMORY_FENCE |
610 | #ifndef ECB_MEMORY_FENCE |
582 | #if !ECB_AVOID_PTHREADS |
611 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
594 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
623 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
595 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
624 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
596 | #endif |
625 | #endif |
597 | #endif |
626 | #endif |
598 | |
627 | |
599 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
628 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
600 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
629 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
601 | #endif |
630 | #endif |
602 | |
631 | |
603 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
632 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
604 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
633 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
605 | #endif |
634 | #endif |
606 | |
635 | |
607 | /*****************************************************************************/ |
636 | /*****************************************************************************/ |
608 | |
637 | |
… | |
… | |
757 | |
786 | |
758 | return r + ecb_ld32 (x); |
787 | return r + ecb_ld32 (x); |
759 | } |
788 | } |
760 | #endif |
789 | #endif |
761 | |
790 | |
|
|
791 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
|
|
792 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
|
|
793 | { |
|
|
794 | return ( (x * 0x0802U & 0x22110U) |
|
|
795 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
|
|
796 | } |
|
|
797 | |
|
|
798 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) ecb_const; |
|
|
799 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) |
|
|
800 | { |
|
|
801 | x = ((x >> 1) & 0x5555) | ((x & 0x5555) << 1); |
|
|
802 | x = ((x >> 2) & 0x3333) | ((x & 0x3333) << 2); |
|
|
803 | x = ((x >> 4) & 0x0f0f) | ((x & 0x0f0f) << 4); |
|
|
804 | x = ( x >> 8 ) | ( x << 8); |
|
|
805 | |
|
|
806 | return x; |
|
|
807 | } |
|
|
808 | |
|
|
809 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) ecb_const; |
|
|
810 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) |
|
|
811 | { |
|
|
812 | x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); |
|
|
813 | x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); |
|
|
814 | x = ((x >> 4) & 0x0f0f0f0f) | ((x & 0x0f0f0f0f) << 4); |
|
|
815 | x = ((x >> 8) & 0x00ff00ff) | ((x & 0x00ff00ff) << 8); |
|
|
816 | x = ( x >> 16 ) | ( x << 16); |
|
|
817 | |
|
|
818 | return x; |
|
|
819 | } |
|
|
820 | |
762 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
821 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
763 | /* so for this version we are lazy */ |
822 | /* so for this version we are lazy */ |
764 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
823 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
765 | ecb_function_ int |
824 | ecb_function_ int |
766 | ecb_popcount64 (uint64_t x) |
825 | ecb_popcount64 (uint64_t x) |
… | |
… | |
815 | |
874 | |
816 | #if ECB_GCC_VERSION(4,5) |
875 | #if ECB_GCC_VERSION(4,5) |
817 | #define ecb_unreachable() __builtin_unreachable () |
876 | #define ecb_unreachable() __builtin_unreachable () |
818 | #else |
877 | #else |
819 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
878 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
820 | ecb_function_ void ecb_unreachable (void) ecb_noreturn; |
879 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
821 | ecb_function_ void ecb_unreachable (void) { } |
880 | ecb_inline void ecb_unreachable (void) { } |
822 | #endif |
881 | #endif |
823 | |
882 | |
824 | /* try to tell the compiler that some condition is definitely true */ |
883 | /* try to tell the compiler that some condition is definitely true */ |
825 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
884 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
826 | |
885 | |
827 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
886 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
828 | ecb_function_ unsigned char |
887 | ecb_inline unsigned char |
829 | ecb_byteorder_helper (void) |
888 | ecb_byteorder_helper (void) |
830 | { |
889 | { |
831 | const uint32_t u = 0x11223344; |
890 | const uint32_t u = 0x11223344; |
832 | return *(unsigned char *)&u; |
891 | return *(unsigned char *)&u; |
833 | } |
892 | } |
834 | |
893 | |
835 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
894 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
836 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
895 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
837 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
896 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
838 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
897 | ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
839 | |
898 | |
840 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
899 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
841 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
900 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
842 | #else |
901 | #else |
843 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
902 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
… | |
… | |
876 | |
935 | |
877 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
936 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
878 | /* if your architecture doesn't need memory fences, e.g. because it is |
937 | /* if your architecture doesn't need memory fences, e.g. because it is |
879 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
938 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
880 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
939 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
881 | * libev, in which casess the memory fences become nops. |
940 | * libev, in which cases the memory fences become nops. |
882 | * alternatively, you can remove this #error and link against libpthread, |
941 | * alternatively, you can remove this #error and link against libpthread, |
883 | * which will then provide the memory fences. |
942 | * which will then provide the memory fences. |
884 | */ |
943 | */ |
885 | # error "memory fences not defined for your architecture, please report" |
944 | # error "memory fences not defined for your architecture, please report" |
886 | #endif |
945 | #endif |
… | |
… | |
1043 | { |
1102 | { |
1044 | write (STDERR_FILENO, msg, strlen (msg)); |
1103 | write (STDERR_FILENO, msg, strlen (msg)); |
1045 | } |
1104 | } |
1046 | #endif |
1105 | #endif |
1047 | |
1106 | |
1048 | static void (*syserr_cb)(const char *msg); |
1107 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1049 | |
1108 | |
1050 | void ecb_cold |
1109 | void ecb_cold |
1051 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1110 | ev_set_syserr_cb (void (*cb)(const char *msg) EV_THROW) EV_THROW |
1052 | { |
1111 | { |
1053 | syserr_cb = cb; |
1112 | syserr_cb = cb; |
1054 | } |
1113 | } |
1055 | |
1114 | |
1056 | static void noinline ecb_cold |
1115 | static void noinline ecb_cold |
… | |
… | |
1074 | abort (); |
1133 | abort (); |
1075 | } |
1134 | } |
1076 | } |
1135 | } |
1077 | |
1136 | |
1078 | static void * |
1137 | static void * |
1079 | ev_realloc_emul (void *ptr, long size) |
1138 | ev_realloc_emul (void *ptr, long size) EV_THROW |
1080 | { |
1139 | { |
1081 | #if __GLIBC__ |
1140 | #if __GLIBC__ |
1082 | return realloc (ptr, size); |
1141 | return realloc (ptr, size); |
1083 | #else |
1142 | #else |
1084 | /* some systems, notably openbsd and darwin, fail to properly |
1143 | /* some systems, notably openbsd and darwin, fail to properly |
… | |
… | |
1092 | free (ptr); |
1151 | free (ptr); |
1093 | return 0; |
1152 | return 0; |
1094 | #endif |
1153 | #endif |
1095 | } |
1154 | } |
1096 | |
1155 | |
1097 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1156 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1098 | |
1157 | |
1099 | void ecb_cold |
1158 | void ecb_cold |
1100 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1159 | ev_set_allocator (void *(*cb)(void *ptr, long size) EV_THROW) EV_THROW |
1101 | { |
1160 | { |
1102 | alloc = cb; |
1161 | alloc = cb; |
1103 | } |
1162 | } |
1104 | |
1163 | |
1105 | inline_speed void * |
1164 | inline_speed void * |
… | |
… | |
1193 | #undef VAR |
1252 | #undef VAR |
1194 | }; |
1253 | }; |
1195 | #include "ev_wrap.h" |
1254 | #include "ev_wrap.h" |
1196 | |
1255 | |
1197 | static struct ev_loop default_loop_struct; |
1256 | static struct ev_loop default_loop_struct; |
1198 | struct ev_loop *ev_default_loop_ptr; |
1257 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1199 | |
1258 | |
1200 | #else |
1259 | #else |
1201 | |
1260 | |
1202 | ev_tstamp ev_rt_now; |
1261 | EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */ |
1203 | #define VAR(name,decl) static decl; |
1262 | #define VAR(name,decl) static decl; |
1204 | #include "ev_vars.h" |
1263 | #include "ev_vars.h" |
1205 | #undef VAR |
1264 | #undef VAR |
1206 | |
1265 | |
1207 | static int ev_default_loop_ptr; |
1266 | static int ev_default_loop_ptr; |
… | |
… | |
1222 | |
1281 | |
1223 | /*****************************************************************************/ |
1282 | /*****************************************************************************/ |
1224 | |
1283 | |
1225 | #ifndef EV_HAVE_EV_TIME |
1284 | #ifndef EV_HAVE_EV_TIME |
1226 | ev_tstamp |
1285 | ev_tstamp |
1227 | ev_time (void) |
1286 | ev_time (void) EV_THROW |
1228 | { |
1287 | { |
1229 | #if EV_USE_REALTIME |
1288 | #if EV_USE_REALTIME |
1230 | if (expect_true (have_realtime)) |
1289 | if (expect_true (have_realtime)) |
1231 | { |
1290 | { |
1232 | struct timespec ts; |
1291 | struct timespec ts; |
… | |
… | |
1256 | return ev_time (); |
1315 | return ev_time (); |
1257 | } |
1316 | } |
1258 | |
1317 | |
1259 | #if EV_MULTIPLICITY |
1318 | #if EV_MULTIPLICITY |
1260 | ev_tstamp |
1319 | ev_tstamp |
1261 | ev_now (EV_P) |
1320 | ev_now (EV_P) EV_THROW |
1262 | { |
1321 | { |
1263 | return ev_rt_now; |
1322 | return ev_rt_now; |
1264 | } |
1323 | } |
1265 | #endif |
1324 | #endif |
1266 | |
1325 | |
1267 | void |
1326 | void |
1268 | ev_sleep (ev_tstamp delay) |
1327 | ev_sleep (ev_tstamp delay) EV_THROW |
1269 | { |
1328 | { |
1270 | if (delay > 0.) |
1329 | if (delay > 0.) |
1271 | { |
1330 | { |
1272 | #if EV_USE_NANOSLEEP |
1331 | #if EV_USE_NANOSLEEP |
1273 | struct timespec ts; |
1332 | struct timespec ts; |
1274 | |
1333 | |
1275 | EV_TS_SET (ts, delay); |
1334 | EV_TS_SET (ts, delay); |
1276 | nanosleep (&ts, 0); |
1335 | nanosleep (&ts, 0); |
1277 | #elif defined(_WIN32) |
1336 | #elif defined _WIN32 |
1278 | Sleep ((unsigned long)(delay * 1e3)); |
1337 | Sleep ((unsigned long)(delay * 1e3)); |
1279 | #else |
1338 | #else |
1280 | struct timeval tv; |
1339 | struct timeval tv; |
1281 | |
1340 | |
1282 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1341 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1301 | |
1360 | |
1302 | do |
1361 | do |
1303 | ncur <<= 1; |
1362 | ncur <<= 1; |
1304 | while (cnt > ncur); |
1363 | while (cnt > ncur); |
1305 | |
1364 | |
1306 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ |
1365 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accommodate malloc overhead */ |
1307 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1366 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1308 | { |
1367 | { |
1309 | ncur *= elem; |
1368 | ncur *= elem; |
1310 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1369 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1311 | ncur = ncur - sizeof (void *) * 4; |
1370 | ncur = ncur - sizeof (void *) * 4; |
… | |
… | |
1354 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1413 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1355 | { |
1414 | { |
1356 | } |
1415 | } |
1357 | |
1416 | |
1358 | void noinline |
1417 | void noinline |
1359 | ev_feed_event (EV_P_ void *w, int revents) |
1418 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1360 | { |
1419 | { |
1361 | W w_ = (W)w; |
1420 | W w_ = (W)w; |
1362 | int pri = ABSPRI (w_); |
1421 | int pri = ABSPRI (w_); |
1363 | |
1422 | |
1364 | if (expect_false (w_->pending)) |
1423 | if (expect_false (w_->pending)) |
… | |
… | |
1368 | w_->pending = ++pendingcnt [pri]; |
1427 | w_->pending = ++pendingcnt [pri]; |
1369 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1428 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1370 | pendings [pri][w_->pending - 1].w = w_; |
1429 | pendings [pri][w_->pending - 1].w = w_; |
1371 | pendings [pri][w_->pending - 1].events = revents; |
1430 | pendings [pri][w_->pending - 1].events = revents; |
1372 | } |
1431 | } |
|
|
1432 | |
|
|
1433 | pendingpri = NUMPRI - 1; |
1373 | } |
1434 | } |
1374 | |
1435 | |
1375 | inline_speed void |
1436 | inline_speed void |
1376 | feed_reverse (EV_P_ W w) |
1437 | feed_reverse (EV_P_ W w) |
1377 | { |
1438 | { |
… | |
… | |
1423 | if (expect_true (!anfd->reify)) |
1484 | if (expect_true (!anfd->reify)) |
1424 | fd_event_nocheck (EV_A_ fd, revents); |
1485 | fd_event_nocheck (EV_A_ fd, revents); |
1425 | } |
1486 | } |
1426 | |
1487 | |
1427 | void |
1488 | void |
1428 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1489 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1429 | { |
1490 | { |
1430 | if (fd >= 0 && fd < anfdmax) |
1491 | if (fd >= 0 && fd < anfdmax) |
1431 | fd_event_nocheck (EV_A_ fd, revents); |
1492 | fd_event_nocheck (EV_A_ fd, revents); |
1432 | } |
1493 | } |
1433 | |
1494 | |
… | |
… | |
1782 | } |
1843 | } |
1783 | |
1844 | |
1784 | inline_speed void |
1845 | inline_speed void |
1785 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1846 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1786 | { |
1847 | { |
|
|
1848 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1849 | |
1787 | if (expect_true (*flag)) |
1850 | if (expect_true (*flag)) |
1788 | return; |
1851 | return; |
1789 | |
1852 | |
1790 | *flag = 1; |
1853 | *flag = 1; |
1791 | |
|
|
1792 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
1854 | ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */ |
1793 | |
1855 | |
1794 | pipe_write_skipped = 1; |
1856 | pipe_write_skipped = 1; |
1795 | |
1857 | |
1796 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
1858 | ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */ |
1797 | |
1859 | |
1798 | if (pipe_write_wanted) |
1860 | if (pipe_write_wanted) |
1799 | { |
1861 | { |
1800 | int old_errno; |
1862 | int old_errno; |
1801 | |
1863 | |
1802 | pipe_write_skipped = 0; /* just an optimisation, no fence needed */ |
1864 | pipe_write_skipped = 0; |
|
|
1865 | ECB_MEMORY_FENCE_RELEASE; |
1803 | |
1866 | |
1804 | old_errno = errno; /* save errno because write will clobber it */ |
1867 | old_errno = errno; /* save errno because write will clobber it */ |
1805 | |
1868 | |
1806 | #if EV_USE_EVENTFD |
1869 | #if EV_USE_EVENTFD |
1807 | if (evfd >= 0) |
1870 | if (evfd >= 0) |
… | |
… | |
1810 | write (evfd, &counter, sizeof (uint64_t)); |
1873 | write (evfd, &counter, sizeof (uint64_t)); |
1811 | } |
1874 | } |
1812 | else |
1875 | else |
1813 | #endif |
1876 | #endif |
1814 | { |
1877 | { |
1815 | /* win32 people keep sending patches that change this write() to send() */ |
1878 | #ifdef _WIN32 |
1816 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1879 | WSABUF buf; |
1817 | /* so when you think this write should be a send instead, please find out */ |
1880 | DWORD sent; |
1818 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1881 | buf.buf = &buf; |
1819 | /* tell me. thank you. */ |
1882 | buf.len = 1; |
|
|
1883 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
|
|
1884 | #else |
1820 | write (evpipe [1], &(evpipe [1]), 1); |
1885 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1886 | #endif |
1821 | } |
1887 | } |
1822 | |
1888 | |
1823 | errno = old_errno; |
1889 | errno = old_errno; |
1824 | } |
1890 | } |
1825 | } |
1891 | } |
… | |
… | |
1840 | read (evfd, &counter, sizeof (uint64_t)); |
1906 | read (evfd, &counter, sizeof (uint64_t)); |
1841 | } |
1907 | } |
1842 | else |
1908 | else |
1843 | #endif |
1909 | #endif |
1844 | { |
1910 | { |
1845 | char dummy; |
1911 | char dummy[4]; |
1846 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1912 | #ifdef _WIN32 |
|
|
1913 | WSABUF buf; |
|
|
1914 | DWORD recvd; |
|
|
1915 | DWORD flags = 0; |
|
|
1916 | buf.buf = dummy; |
|
|
1917 | buf.len = sizeof (dummy); |
|
|
1918 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, &flags, 0, 0); |
|
|
1919 | #else |
1847 | read (evpipe [0], &dummy, 1); |
1920 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1921 | #endif |
1848 | } |
1922 | } |
1849 | } |
1923 | } |
1850 | |
1924 | |
1851 | pipe_write_skipped = 0; |
1925 | pipe_write_skipped = 0; |
|
|
1926 | |
|
|
1927 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1852 | |
1928 | |
1853 | #if EV_SIGNAL_ENABLE |
1929 | #if EV_SIGNAL_ENABLE |
1854 | if (sig_pending) |
1930 | if (sig_pending) |
1855 | { |
1931 | { |
1856 | sig_pending = 0; |
1932 | sig_pending = 0; |
|
|
1933 | |
|
|
1934 | ECB_MEMORY_FENCE; |
1857 | |
1935 | |
1858 | for (i = EV_NSIG - 1; i--; ) |
1936 | for (i = EV_NSIG - 1; i--; ) |
1859 | if (expect_false (signals [i].pending)) |
1937 | if (expect_false (signals [i].pending)) |
1860 | ev_feed_signal_event (EV_A_ i + 1); |
1938 | ev_feed_signal_event (EV_A_ i + 1); |
1861 | } |
1939 | } |
… | |
… | |
1863 | |
1941 | |
1864 | #if EV_ASYNC_ENABLE |
1942 | #if EV_ASYNC_ENABLE |
1865 | if (async_pending) |
1943 | if (async_pending) |
1866 | { |
1944 | { |
1867 | async_pending = 0; |
1945 | async_pending = 0; |
|
|
1946 | |
|
|
1947 | ECB_MEMORY_FENCE; |
1868 | |
1948 | |
1869 | for (i = asynccnt; i--; ) |
1949 | for (i = asynccnt; i--; ) |
1870 | if (asyncs [i]->sent) |
1950 | if (asyncs [i]->sent) |
1871 | { |
1951 | { |
1872 | asyncs [i]->sent = 0; |
1952 | asyncs [i]->sent = 0; |
|
|
1953 | ECB_MEMORY_FENCE_RELEASE; |
1873 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
1954 | ev_feed_event (EV_A_ asyncs [i], EV_ASYNC); |
1874 | } |
1955 | } |
1875 | } |
1956 | } |
1876 | #endif |
1957 | #endif |
1877 | } |
1958 | } |
1878 | |
1959 | |
1879 | /*****************************************************************************/ |
1960 | /*****************************************************************************/ |
1880 | |
1961 | |
1881 | void |
1962 | void |
1882 | ev_feed_signal (int signum) |
1963 | ev_feed_signal (int signum) EV_THROW |
1883 | { |
1964 | { |
1884 | #if EV_MULTIPLICITY |
1965 | #if EV_MULTIPLICITY |
1885 | EV_P = signals [signum - 1].loop; |
1966 | EV_P = signals [signum - 1].loop; |
1886 | |
1967 | |
1887 | if (!EV_A) |
1968 | if (!EV_A) |
… | |
… | |
1904 | |
1985 | |
1905 | ev_feed_signal (signum); |
1986 | ev_feed_signal (signum); |
1906 | } |
1987 | } |
1907 | |
1988 | |
1908 | void noinline |
1989 | void noinline |
1909 | ev_feed_signal_event (EV_P_ int signum) |
1990 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1910 | { |
1991 | { |
1911 | WL w; |
1992 | WL w; |
1912 | |
1993 | |
1913 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1994 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1914 | return; |
1995 | return; |
… | |
… | |
1922 | if (expect_false (signals [signum].loop != EV_A)) |
2003 | if (expect_false (signals [signum].loop != EV_A)) |
1923 | return; |
2004 | return; |
1924 | #endif |
2005 | #endif |
1925 | |
2006 | |
1926 | signals [signum].pending = 0; |
2007 | signals [signum].pending = 0; |
|
|
2008 | MEMORY_FENCE_RELEASE; |
1927 | |
2009 | |
1928 | for (w = signals [signum].head; w; w = w->next) |
2010 | for (w = signals [signum].head; w; w = w->next) |
1929 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
2011 | ev_feed_event (EV_A_ (W)w, EV_SIGNAL); |
1930 | } |
2012 | } |
1931 | |
2013 | |
… | |
… | |
2030 | #if EV_USE_SELECT |
2112 | #if EV_USE_SELECT |
2031 | # include "ev_select.c" |
2113 | # include "ev_select.c" |
2032 | #endif |
2114 | #endif |
2033 | |
2115 | |
2034 | int ecb_cold |
2116 | int ecb_cold |
2035 | ev_version_major (void) |
2117 | ev_version_major (void) EV_THROW |
2036 | { |
2118 | { |
2037 | return EV_VERSION_MAJOR; |
2119 | return EV_VERSION_MAJOR; |
2038 | } |
2120 | } |
2039 | |
2121 | |
2040 | int ecb_cold |
2122 | int ecb_cold |
2041 | ev_version_minor (void) |
2123 | ev_version_minor (void) EV_THROW |
2042 | { |
2124 | { |
2043 | return EV_VERSION_MINOR; |
2125 | return EV_VERSION_MINOR; |
2044 | } |
2126 | } |
2045 | |
2127 | |
2046 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2128 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2054 | || getgid () != getegid (); |
2136 | || getgid () != getegid (); |
2055 | #endif |
2137 | #endif |
2056 | } |
2138 | } |
2057 | |
2139 | |
2058 | unsigned int ecb_cold |
2140 | unsigned int ecb_cold |
2059 | ev_supported_backends (void) |
2141 | ev_supported_backends (void) EV_THROW |
2060 | { |
2142 | { |
2061 | unsigned int flags = 0; |
2143 | unsigned int flags = 0; |
2062 | |
2144 | |
2063 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2145 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2064 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2146 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2068 | |
2150 | |
2069 | return flags; |
2151 | return flags; |
2070 | } |
2152 | } |
2071 | |
2153 | |
2072 | unsigned int ecb_cold |
2154 | unsigned int ecb_cold |
2073 | ev_recommended_backends (void) |
2155 | ev_recommended_backends (void) EV_THROW |
2074 | { |
2156 | { |
2075 | unsigned int flags = ev_supported_backends (); |
2157 | unsigned int flags = ev_supported_backends (); |
2076 | |
2158 | |
2077 | #ifndef __NetBSD__ |
2159 | #ifndef __NetBSD__ |
2078 | /* kqueue is borked on everything but netbsd apparently */ |
2160 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2090 | |
2172 | |
2091 | return flags; |
2173 | return flags; |
2092 | } |
2174 | } |
2093 | |
2175 | |
2094 | unsigned int ecb_cold |
2176 | unsigned int ecb_cold |
2095 | ev_embeddable_backends (void) |
2177 | ev_embeddable_backends (void) EV_THROW |
2096 | { |
2178 | { |
2097 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2179 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2098 | |
2180 | |
2099 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2181 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2100 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2182 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2102 | |
2184 | |
2103 | return flags; |
2185 | return flags; |
2104 | } |
2186 | } |
2105 | |
2187 | |
2106 | unsigned int |
2188 | unsigned int |
2107 | ev_backend (EV_P) |
2189 | ev_backend (EV_P) EV_THROW |
2108 | { |
2190 | { |
2109 | return backend; |
2191 | return backend; |
2110 | } |
2192 | } |
2111 | |
2193 | |
2112 | #if EV_FEATURE_API |
2194 | #if EV_FEATURE_API |
2113 | unsigned int |
2195 | unsigned int |
2114 | ev_iteration (EV_P) |
2196 | ev_iteration (EV_P) EV_THROW |
2115 | { |
2197 | { |
2116 | return loop_count; |
2198 | return loop_count; |
2117 | } |
2199 | } |
2118 | |
2200 | |
2119 | unsigned int |
2201 | unsigned int |
2120 | ev_depth (EV_P) |
2202 | ev_depth (EV_P) EV_THROW |
2121 | { |
2203 | { |
2122 | return loop_depth; |
2204 | return loop_depth; |
2123 | } |
2205 | } |
2124 | |
2206 | |
2125 | void |
2207 | void |
2126 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2208 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2127 | { |
2209 | { |
2128 | io_blocktime = interval; |
2210 | io_blocktime = interval; |
2129 | } |
2211 | } |
2130 | |
2212 | |
2131 | void |
2213 | void |
2132 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2214 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2133 | { |
2215 | { |
2134 | timeout_blocktime = interval; |
2216 | timeout_blocktime = interval; |
2135 | } |
2217 | } |
2136 | |
2218 | |
2137 | void |
2219 | void |
2138 | ev_set_userdata (EV_P_ void *data) |
2220 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2139 | { |
2221 | { |
2140 | userdata = data; |
2222 | userdata = data; |
2141 | } |
2223 | } |
2142 | |
2224 | |
2143 | void * |
2225 | void * |
2144 | ev_userdata (EV_P) |
2226 | ev_userdata (EV_P) EV_THROW |
2145 | { |
2227 | { |
2146 | return userdata; |
2228 | return userdata; |
2147 | } |
2229 | } |
2148 | |
2230 | |
2149 | void |
2231 | void |
2150 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2232 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2151 | { |
2233 | { |
2152 | invoke_cb = invoke_pending_cb; |
2234 | invoke_cb = invoke_pending_cb; |
2153 | } |
2235 | } |
2154 | |
2236 | |
2155 | void |
2237 | void |
2156 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2238 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2157 | { |
2239 | { |
2158 | release_cb = release; |
2240 | release_cb = release; |
2159 | acquire_cb = acquire; |
2241 | acquire_cb = acquire; |
2160 | } |
2242 | } |
2161 | #endif |
2243 | #endif |
2162 | |
2244 | |
2163 | /* initialise a loop structure, must be zero-initialised */ |
2245 | /* initialise a loop structure, must be zero-initialised */ |
2164 | static void noinline ecb_cold |
2246 | static void noinline ecb_cold |
2165 | loop_init (EV_P_ unsigned int flags) |
2247 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2166 | { |
2248 | { |
2167 | if (!backend) |
2249 | if (!backend) |
2168 | { |
2250 | { |
2169 | origflags = flags; |
2251 | origflags = flags; |
2170 | |
2252 | |
… | |
… | |
2275 | EV_INVOKE_PENDING; |
2357 | EV_INVOKE_PENDING; |
2276 | } |
2358 | } |
2277 | #endif |
2359 | #endif |
2278 | |
2360 | |
2279 | #if EV_CHILD_ENABLE |
2361 | #if EV_CHILD_ENABLE |
2280 | if (ev_is_active (&childev)) |
2362 | if (ev_is_default_loop (EV_A) && ev_is_active (&childev)) |
2281 | { |
2363 | { |
2282 | ev_ref (EV_A); /* child watcher */ |
2364 | ev_ref (EV_A); /* child watcher */ |
2283 | ev_signal_stop (EV_A_ &childev); |
2365 | ev_signal_stop (EV_A_ &childev); |
2284 | } |
2366 | } |
2285 | #endif |
2367 | #endif |
… | |
… | |
2423 | } |
2505 | } |
2424 | |
2506 | |
2425 | #if EV_MULTIPLICITY |
2507 | #if EV_MULTIPLICITY |
2426 | |
2508 | |
2427 | struct ev_loop * ecb_cold |
2509 | struct ev_loop * ecb_cold |
2428 | ev_loop_new (unsigned int flags) |
2510 | ev_loop_new (unsigned int flags) EV_THROW |
2429 | { |
2511 | { |
2430 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2512 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2431 | |
2513 | |
2432 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2514 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2433 | loop_init (EV_A_ flags); |
2515 | loop_init (EV_A_ flags); |
… | |
… | |
2477 | } |
2559 | } |
2478 | #endif |
2560 | #endif |
2479 | |
2561 | |
2480 | #if EV_FEATURE_API |
2562 | #if EV_FEATURE_API |
2481 | void ecb_cold |
2563 | void ecb_cold |
2482 | ev_verify (EV_P) |
2564 | ev_verify (EV_P) EV_THROW |
2483 | { |
2565 | { |
2484 | #if EV_VERIFY |
2566 | #if EV_VERIFY |
2485 | int i; |
2567 | int i; |
2486 | WL w; |
2568 | WL w, w2; |
2487 | |
2569 | |
2488 | assert (activecnt >= -1); |
2570 | assert (activecnt >= -1); |
2489 | |
2571 | |
2490 | assert (fdchangemax >= fdchangecnt); |
2572 | assert (fdchangemax >= fdchangecnt); |
2491 | for (i = 0; i < fdchangecnt; ++i) |
2573 | for (i = 0; i < fdchangecnt; ++i) |
2492 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2574 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2493 | |
2575 | |
2494 | assert (anfdmax >= 0); |
2576 | assert (anfdmax >= 0); |
2495 | for (i = 0; i < anfdmax; ++i) |
2577 | for (i = 0; i < anfdmax; ++i) |
|
|
2578 | { |
|
|
2579 | int j = 0; |
|
|
2580 | |
2496 | for (w = anfds [i].head; w; w = w->next) |
2581 | for (w = w2 = anfds [i].head; w; w = w->next) |
2497 | { |
2582 | { |
2498 | verify_watcher (EV_A_ (W)w); |
2583 | verify_watcher (EV_A_ (W)w); |
|
|
2584 | |
|
|
2585 | if (j++ & 1) |
|
|
2586 | { |
|
|
2587 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2588 | w2 = w2->next; |
|
|
2589 | } |
|
|
2590 | |
2499 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2591 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2500 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2592 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2501 | } |
2593 | } |
|
|
2594 | } |
2502 | |
2595 | |
2503 | assert (timermax >= timercnt); |
2596 | assert (timermax >= timercnt); |
2504 | verify_heap (EV_A_ timers, timercnt); |
2597 | verify_heap (EV_A_ timers, timercnt); |
2505 | |
2598 | |
2506 | #if EV_PERIODIC_ENABLE |
2599 | #if EV_PERIODIC_ENABLE |
… | |
… | |
2556 | #if EV_MULTIPLICITY |
2649 | #if EV_MULTIPLICITY |
2557 | struct ev_loop * ecb_cold |
2650 | struct ev_loop * ecb_cold |
2558 | #else |
2651 | #else |
2559 | int |
2652 | int |
2560 | #endif |
2653 | #endif |
2561 | ev_default_loop (unsigned int flags) |
2654 | ev_default_loop (unsigned int flags) EV_THROW |
2562 | { |
2655 | { |
2563 | if (!ev_default_loop_ptr) |
2656 | if (!ev_default_loop_ptr) |
2564 | { |
2657 | { |
2565 | #if EV_MULTIPLICITY |
2658 | #if EV_MULTIPLICITY |
2566 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2659 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2585 | |
2678 | |
2586 | return ev_default_loop_ptr; |
2679 | return ev_default_loop_ptr; |
2587 | } |
2680 | } |
2588 | |
2681 | |
2589 | void |
2682 | void |
2590 | ev_loop_fork (EV_P) |
2683 | ev_loop_fork (EV_P) EV_THROW |
2591 | { |
2684 | { |
2592 | postfork = 1; /* must be in line with ev_default_fork */ |
2685 | postfork = 1; /* must be in line with ev_default_fork */ |
2593 | } |
2686 | } |
2594 | |
2687 | |
2595 | /*****************************************************************************/ |
2688 | /*****************************************************************************/ |
… | |
… | |
2599 | { |
2692 | { |
2600 | EV_CB_INVOKE ((W)w, revents); |
2693 | EV_CB_INVOKE ((W)w, revents); |
2601 | } |
2694 | } |
2602 | |
2695 | |
2603 | unsigned int |
2696 | unsigned int |
2604 | ev_pending_count (EV_P) |
2697 | ev_pending_count (EV_P) EV_THROW |
2605 | { |
2698 | { |
2606 | int pri; |
2699 | int pri; |
2607 | unsigned int count = 0; |
2700 | unsigned int count = 0; |
2608 | |
2701 | |
2609 | for (pri = NUMPRI; pri--; ) |
2702 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2613 | } |
2706 | } |
2614 | |
2707 | |
2615 | void noinline |
2708 | void noinline |
2616 | ev_invoke_pending (EV_P) |
2709 | ev_invoke_pending (EV_P) |
2617 | { |
2710 | { |
2618 | int pri; |
2711 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2619 | |
|
|
2620 | for (pri = NUMPRI; pri--; ) |
|
|
2621 | while (pendingcnt [pri]) |
2712 | while (pendingcnt [pendingpri]) |
2622 | { |
2713 | { |
2623 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2714 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2624 | |
2715 | |
2625 | p->w->pending = 0; |
2716 | p->w->pending = 0; |
2626 | EV_CB_INVOKE (p->w, p->events); |
2717 | EV_CB_INVOKE (p->w, p->events); |
2627 | EV_FREQUENT_CHECK; |
2718 | EV_FREQUENT_CHECK; |
2628 | } |
2719 | } |
… | |
… | |
2723 | { |
2814 | { |
2724 | EV_FREQUENT_CHECK; |
2815 | EV_FREQUENT_CHECK; |
2725 | |
2816 | |
2726 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2817 | while (periodiccnt && ANHE_at (periodics [HEAP0]) < ev_rt_now) |
2727 | { |
2818 | { |
2728 | int feed_count = 0; |
|
|
2729 | |
|
|
2730 | do |
2819 | do |
2731 | { |
2820 | { |
2732 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2821 | ev_periodic *w = (ev_periodic *)ANHE_w (periodics [HEAP0]); |
2733 | |
2822 | |
2734 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
2823 | /*assert (("libev: inactive timer on periodic heap detected", ev_is_active (w)));*/ |
… | |
… | |
2868 | |
2957 | |
2869 | mn_now = ev_rt_now; |
2958 | mn_now = ev_rt_now; |
2870 | } |
2959 | } |
2871 | } |
2960 | } |
2872 | |
2961 | |
2873 | void |
2962 | int |
2874 | ev_run (EV_P_ int flags) |
2963 | ev_run (EV_P_ int flags) |
2875 | { |
2964 | { |
2876 | #if EV_FEATURE_API |
2965 | #if EV_FEATURE_API |
2877 | ++loop_depth; |
2966 | ++loop_depth; |
2878 | #endif |
2967 | #endif |
… | |
… | |
2991 | #endif |
3080 | #endif |
2992 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
3081 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2993 | backend_poll (EV_A_ waittime); |
3082 | backend_poll (EV_A_ waittime); |
2994 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3083 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2995 | |
3084 | |
2996 | pipe_write_wanted = 0; /* just an optimsiation, no fence needed */ |
3085 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
2997 | |
3086 | |
2998 | if (pipe_write_skipped) |
3087 | if (pipe_write_skipped) |
2999 | { |
3088 | { |
3000 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3089 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3001 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3090 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
… | |
… | |
3035 | loop_done = EVBREAK_CANCEL; |
3124 | loop_done = EVBREAK_CANCEL; |
3036 | |
3125 | |
3037 | #if EV_FEATURE_API |
3126 | #if EV_FEATURE_API |
3038 | --loop_depth; |
3127 | --loop_depth; |
3039 | #endif |
3128 | #endif |
|
|
3129 | |
|
|
3130 | return activecnt; |
3040 | } |
3131 | } |
3041 | |
3132 | |
3042 | void |
3133 | void |
3043 | ev_break (EV_P_ int how) |
3134 | ev_break (EV_P_ int how) EV_THROW |
3044 | { |
3135 | { |
3045 | loop_done = how; |
3136 | loop_done = how; |
3046 | } |
3137 | } |
3047 | |
3138 | |
3048 | void |
3139 | void |
3049 | ev_ref (EV_P) |
3140 | ev_ref (EV_P) EV_THROW |
3050 | { |
3141 | { |
3051 | ++activecnt; |
3142 | ++activecnt; |
3052 | } |
3143 | } |
3053 | |
3144 | |
3054 | void |
3145 | void |
3055 | ev_unref (EV_P) |
3146 | ev_unref (EV_P) EV_THROW |
3056 | { |
3147 | { |
3057 | --activecnt; |
3148 | --activecnt; |
3058 | } |
3149 | } |
3059 | |
3150 | |
3060 | void |
3151 | void |
3061 | ev_now_update (EV_P) |
3152 | ev_now_update (EV_P) EV_THROW |
3062 | { |
3153 | { |
3063 | time_update (EV_A_ 1e100); |
3154 | time_update (EV_A_ 1e100); |
3064 | } |
3155 | } |
3065 | |
3156 | |
3066 | void |
3157 | void |
3067 | ev_suspend (EV_P) |
3158 | ev_suspend (EV_P) EV_THROW |
3068 | { |
3159 | { |
3069 | ev_now_update (EV_A); |
3160 | ev_now_update (EV_A); |
3070 | } |
3161 | } |
3071 | |
3162 | |
3072 | void |
3163 | void |
3073 | ev_resume (EV_P) |
3164 | ev_resume (EV_P) EV_THROW |
3074 | { |
3165 | { |
3075 | ev_tstamp mn_prev = mn_now; |
3166 | ev_tstamp mn_prev = mn_now; |
3076 | |
3167 | |
3077 | ev_now_update (EV_A); |
3168 | ev_now_update (EV_A); |
3078 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3169 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3117 | w->pending = 0; |
3208 | w->pending = 0; |
3118 | } |
3209 | } |
3119 | } |
3210 | } |
3120 | |
3211 | |
3121 | int |
3212 | int |
3122 | ev_clear_pending (EV_P_ void *w) |
3213 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3123 | { |
3214 | { |
3124 | W w_ = (W)w; |
3215 | W w_ = (W)w; |
3125 | int pending = w_->pending; |
3216 | int pending = w_->pending; |
3126 | |
3217 | |
3127 | if (expect_true (pending)) |
3218 | if (expect_true (pending)) |
… | |
… | |
3160 | } |
3251 | } |
3161 | |
3252 | |
3162 | /*****************************************************************************/ |
3253 | /*****************************************************************************/ |
3163 | |
3254 | |
3164 | void noinline |
3255 | void noinline |
3165 | ev_io_start (EV_P_ ev_io *w) |
3256 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3166 | { |
3257 | { |
3167 | int fd = w->fd; |
3258 | int fd = w->fd; |
3168 | |
3259 | |
3169 | if (expect_false (ev_is_active (w))) |
3260 | if (expect_false (ev_is_active (w))) |
3170 | return; |
3261 | return; |
… | |
… | |
3176 | |
3267 | |
3177 | ev_start (EV_A_ (W)w, 1); |
3268 | ev_start (EV_A_ (W)w, 1); |
3178 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3269 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3179 | wlist_add (&anfds[fd].head, (WL)w); |
3270 | wlist_add (&anfds[fd].head, (WL)w); |
3180 | |
3271 | |
|
|
3272 | /* common bug, apparently */ |
|
|
3273 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3274 | |
3181 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3275 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3182 | w->events &= ~EV__IOFDSET; |
3276 | w->events &= ~EV__IOFDSET; |
3183 | |
3277 | |
3184 | EV_FREQUENT_CHECK; |
3278 | EV_FREQUENT_CHECK; |
3185 | } |
3279 | } |
3186 | |
3280 | |
3187 | void noinline |
3281 | void noinline |
3188 | ev_io_stop (EV_P_ ev_io *w) |
3282 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3189 | { |
3283 | { |
3190 | clear_pending (EV_A_ (W)w); |
3284 | clear_pending (EV_A_ (W)w); |
3191 | if (expect_false (!ev_is_active (w))) |
3285 | if (expect_false (!ev_is_active (w))) |
3192 | return; |
3286 | return; |
3193 | |
3287 | |
… | |
… | |
3202 | |
3296 | |
3203 | EV_FREQUENT_CHECK; |
3297 | EV_FREQUENT_CHECK; |
3204 | } |
3298 | } |
3205 | |
3299 | |
3206 | void noinline |
3300 | void noinline |
3207 | ev_timer_start (EV_P_ ev_timer *w) |
3301 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3208 | { |
3302 | { |
3209 | if (expect_false (ev_is_active (w))) |
3303 | if (expect_false (ev_is_active (w))) |
3210 | return; |
3304 | return; |
3211 | |
3305 | |
3212 | ev_at (w) += mn_now; |
3306 | ev_at (w) += mn_now; |
… | |
… | |
3226 | |
3320 | |
3227 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3321 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3228 | } |
3322 | } |
3229 | |
3323 | |
3230 | void noinline |
3324 | void noinline |
3231 | ev_timer_stop (EV_P_ ev_timer *w) |
3325 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3232 | { |
3326 | { |
3233 | clear_pending (EV_A_ (W)w); |
3327 | clear_pending (EV_A_ (W)w); |
3234 | if (expect_false (!ev_is_active (w))) |
3328 | if (expect_false (!ev_is_active (w))) |
3235 | return; |
3329 | return; |
3236 | |
3330 | |
… | |
… | |
3256 | |
3350 | |
3257 | EV_FREQUENT_CHECK; |
3351 | EV_FREQUENT_CHECK; |
3258 | } |
3352 | } |
3259 | |
3353 | |
3260 | void noinline |
3354 | void noinline |
3261 | ev_timer_again (EV_P_ ev_timer *w) |
3355 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3262 | { |
3356 | { |
3263 | EV_FREQUENT_CHECK; |
3357 | EV_FREQUENT_CHECK; |
|
|
3358 | |
|
|
3359 | clear_pending (EV_A_ (W)w); |
3264 | |
3360 | |
3265 | if (ev_is_active (w)) |
3361 | if (ev_is_active (w)) |
3266 | { |
3362 | { |
3267 | if (w->repeat) |
3363 | if (w->repeat) |
3268 | { |
3364 | { |
… | |
… | |
3281 | |
3377 | |
3282 | EV_FREQUENT_CHECK; |
3378 | EV_FREQUENT_CHECK; |
3283 | } |
3379 | } |
3284 | |
3380 | |
3285 | ev_tstamp |
3381 | ev_tstamp |
3286 | ev_timer_remaining (EV_P_ ev_timer *w) |
3382 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3287 | { |
3383 | { |
3288 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3384 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3289 | } |
3385 | } |
3290 | |
3386 | |
3291 | #if EV_PERIODIC_ENABLE |
3387 | #if EV_PERIODIC_ENABLE |
3292 | void noinline |
3388 | void noinline |
3293 | ev_periodic_start (EV_P_ ev_periodic *w) |
3389 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3294 | { |
3390 | { |
3295 | if (expect_false (ev_is_active (w))) |
3391 | if (expect_false (ev_is_active (w))) |
3296 | return; |
3392 | return; |
3297 | |
3393 | |
3298 | if (w->reschedule_cb) |
3394 | if (w->reschedule_cb) |
… | |
… | |
3318 | |
3414 | |
3319 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3415 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3320 | } |
3416 | } |
3321 | |
3417 | |
3322 | void noinline |
3418 | void noinline |
3323 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3419 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3324 | { |
3420 | { |
3325 | clear_pending (EV_A_ (W)w); |
3421 | clear_pending (EV_A_ (W)w); |
3326 | if (expect_false (!ev_is_active (w))) |
3422 | if (expect_false (!ev_is_active (w))) |
3327 | return; |
3423 | return; |
3328 | |
3424 | |
… | |
… | |
3346 | |
3442 | |
3347 | EV_FREQUENT_CHECK; |
3443 | EV_FREQUENT_CHECK; |
3348 | } |
3444 | } |
3349 | |
3445 | |
3350 | void noinline |
3446 | void noinline |
3351 | ev_periodic_again (EV_P_ ev_periodic *w) |
3447 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3352 | { |
3448 | { |
3353 | /* TODO: use adjustheap and recalculation */ |
3449 | /* TODO: use adjustheap and recalculation */ |
3354 | ev_periodic_stop (EV_A_ w); |
3450 | ev_periodic_stop (EV_A_ w); |
3355 | ev_periodic_start (EV_A_ w); |
3451 | ev_periodic_start (EV_A_ w); |
3356 | } |
3452 | } |
… | |
… | |
3361 | #endif |
3457 | #endif |
3362 | |
3458 | |
3363 | #if EV_SIGNAL_ENABLE |
3459 | #if EV_SIGNAL_ENABLE |
3364 | |
3460 | |
3365 | void noinline |
3461 | void noinline |
3366 | ev_signal_start (EV_P_ ev_signal *w) |
3462 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3367 | { |
3463 | { |
3368 | if (expect_false (ev_is_active (w))) |
3464 | if (expect_false (ev_is_active (w))) |
3369 | return; |
3465 | return; |
3370 | |
3466 | |
3371 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3467 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3442 | |
3538 | |
3443 | EV_FREQUENT_CHECK; |
3539 | EV_FREQUENT_CHECK; |
3444 | } |
3540 | } |
3445 | |
3541 | |
3446 | void noinline |
3542 | void noinline |
3447 | ev_signal_stop (EV_P_ ev_signal *w) |
3543 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3448 | { |
3544 | { |
3449 | clear_pending (EV_A_ (W)w); |
3545 | clear_pending (EV_A_ (W)w); |
3450 | if (expect_false (!ev_is_active (w))) |
3546 | if (expect_false (!ev_is_active (w))) |
3451 | return; |
3547 | return; |
3452 | |
3548 | |
… | |
… | |
3483 | #endif |
3579 | #endif |
3484 | |
3580 | |
3485 | #if EV_CHILD_ENABLE |
3581 | #if EV_CHILD_ENABLE |
3486 | |
3582 | |
3487 | void |
3583 | void |
3488 | ev_child_start (EV_P_ ev_child *w) |
3584 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3489 | { |
3585 | { |
3490 | #if EV_MULTIPLICITY |
3586 | #if EV_MULTIPLICITY |
3491 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3587 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3492 | #endif |
3588 | #endif |
3493 | if (expect_false (ev_is_active (w))) |
3589 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3500 | |
3596 | |
3501 | EV_FREQUENT_CHECK; |
3597 | EV_FREQUENT_CHECK; |
3502 | } |
3598 | } |
3503 | |
3599 | |
3504 | void |
3600 | void |
3505 | ev_child_stop (EV_P_ ev_child *w) |
3601 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3506 | { |
3602 | { |
3507 | clear_pending (EV_A_ (W)w); |
3603 | clear_pending (EV_A_ (W)w); |
3508 | if (expect_false (!ev_is_active (w))) |
3604 | if (expect_false (!ev_is_active (w))) |
3509 | return; |
3605 | return; |
3510 | |
3606 | |
… | |
… | |
3677 | } |
3773 | } |
3678 | |
3774 | |
3679 | inline_size int |
3775 | inline_size int |
3680 | infy_newfd (void) |
3776 | infy_newfd (void) |
3681 | { |
3777 | { |
3682 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3778 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3683 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3779 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3684 | if (fd >= 0) |
3780 | if (fd >= 0) |
3685 | return fd; |
3781 | return fd; |
3686 | #endif |
3782 | #endif |
3687 | return inotify_init (); |
3783 | return inotify_init (); |
… | |
… | |
3762 | #else |
3858 | #else |
3763 | # define EV_LSTAT(p,b) lstat (p, b) |
3859 | # define EV_LSTAT(p,b) lstat (p, b) |
3764 | #endif |
3860 | #endif |
3765 | |
3861 | |
3766 | void |
3862 | void |
3767 | ev_stat_stat (EV_P_ ev_stat *w) |
3863 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3768 | { |
3864 | { |
3769 | if (lstat (w->path, &w->attr) < 0) |
3865 | if (lstat (w->path, &w->attr) < 0) |
3770 | w->attr.st_nlink = 0; |
3866 | w->attr.st_nlink = 0; |
3771 | else if (!w->attr.st_nlink) |
3867 | else if (!w->attr.st_nlink) |
3772 | w->attr.st_nlink = 1; |
3868 | w->attr.st_nlink = 1; |
… | |
… | |
3811 | ev_feed_event (EV_A_ w, EV_STAT); |
3907 | ev_feed_event (EV_A_ w, EV_STAT); |
3812 | } |
3908 | } |
3813 | } |
3909 | } |
3814 | |
3910 | |
3815 | void |
3911 | void |
3816 | ev_stat_start (EV_P_ ev_stat *w) |
3912 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3817 | { |
3913 | { |
3818 | if (expect_false (ev_is_active (w))) |
3914 | if (expect_false (ev_is_active (w))) |
3819 | return; |
3915 | return; |
3820 | |
3916 | |
3821 | ev_stat_stat (EV_A_ w); |
3917 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3842 | |
3938 | |
3843 | EV_FREQUENT_CHECK; |
3939 | EV_FREQUENT_CHECK; |
3844 | } |
3940 | } |
3845 | |
3941 | |
3846 | void |
3942 | void |
3847 | ev_stat_stop (EV_P_ ev_stat *w) |
3943 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3848 | { |
3944 | { |
3849 | clear_pending (EV_A_ (W)w); |
3945 | clear_pending (EV_A_ (W)w); |
3850 | if (expect_false (!ev_is_active (w))) |
3946 | if (expect_false (!ev_is_active (w))) |
3851 | return; |
3947 | return; |
3852 | |
3948 | |
… | |
… | |
3868 | } |
3964 | } |
3869 | #endif |
3965 | #endif |
3870 | |
3966 | |
3871 | #if EV_IDLE_ENABLE |
3967 | #if EV_IDLE_ENABLE |
3872 | void |
3968 | void |
3873 | ev_idle_start (EV_P_ ev_idle *w) |
3969 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3874 | { |
3970 | { |
3875 | if (expect_false (ev_is_active (w))) |
3971 | if (expect_false (ev_is_active (w))) |
3876 | return; |
3972 | return; |
3877 | |
3973 | |
3878 | pri_adjust (EV_A_ (W)w); |
3974 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3891 | |
3987 | |
3892 | EV_FREQUENT_CHECK; |
3988 | EV_FREQUENT_CHECK; |
3893 | } |
3989 | } |
3894 | |
3990 | |
3895 | void |
3991 | void |
3896 | ev_idle_stop (EV_P_ ev_idle *w) |
3992 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3897 | { |
3993 | { |
3898 | clear_pending (EV_A_ (W)w); |
3994 | clear_pending (EV_A_ (W)w); |
3899 | if (expect_false (!ev_is_active (w))) |
3995 | if (expect_false (!ev_is_active (w))) |
3900 | return; |
3996 | return; |
3901 | |
3997 | |
… | |
… | |
3915 | } |
4011 | } |
3916 | #endif |
4012 | #endif |
3917 | |
4013 | |
3918 | #if EV_PREPARE_ENABLE |
4014 | #if EV_PREPARE_ENABLE |
3919 | void |
4015 | void |
3920 | ev_prepare_start (EV_P_ ev_prepare *w) |
4016 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3921 | { |
4017 | { |
3922 | if (expect_false (ev_is_active (w))) |
4018 | if (expect_false (ev_is_active (w))) |
3923 | return; |
4019 | return; |
3924 | |
4020 | |
3925 | EV_FREQUENT_CHECK; |
4021 | EV_FREQUENT_CHECK; |
… | |
… | |
3930 | |
4026 | |
3931 | EV_FREQUENT_CHECK; |
4027 | EV_FREQUENT_CHECK; |
3932 | } |
4028 | } |
3933 | |
4029 | |
3934 | void |
4030 | void |
3935 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4031 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3936 | { |
4032 | { |
3937 | clear_pending (EV_A_ (W)w); |
4033 | clear_pending (EV_A_ (W)w); |
3938 | if (expect_false (!ev_is_active (w))) |
4034 | if (expect_false (!ev_is_active (w))) |
3939 | return; |
4035 | return; |
3940 | |
4036 | |
… | |
… | |
3953 | } |
4049 | } |
3954 | #endif |
4050 | #endif |
3955 | |
4051 | |
3956 | #if EV_CHECK_ENABLE |
4052 | #if EV_CHECK_ENABLE |
3957 | void |
4053 | void |
3958 | ev_check_start (EV_P_ ev_check *w) |
4054 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
3959 | { |
4055 | { |
3960 | if (expect_false (ev_is_active (w))) |
4056 | if (expect_false (ev_is_active (w))) |
3961 | return; |
4057 | return; |
3962 | |
4058 | |
3963 | EV_FREQUENT_CHECK; |
4059 | EV_FREQUENT_CHECK; |
… | |
… | |
3968 | |
4064 | |
3969 | EV_FREQUENT_CHECK; |
4065 | EV_FREQUENT_CHECK; |
3970 | } |
4066 | } |
3971 | |
4067 | |
3972 | void |
4068 | void |
3973 | ev_check_stop (EV_P_ ev_check *w) |
4069 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
3974 | { |
4070 | { |
3975 | clear_pending (EV_A_ (W)w); |
4071 | clear_pending (EV_A_ (W)w); |
3976 | if (expect_false (!ev_is_active (w))) |
4072 | if (expect_false (!ev_is_active (w))) |
3977 | return; |
4073 | return; |
3978 | |
4074 | |
… | |
… | |
3991 | } |
4087 | } |
3992 | #endif |
4088 | #endif |
3993 | |
4089 | |
3994 | #if EV_EMBED_ENABLE |
4090 | #if EV_EMBED_ENABLE |
3995 | void noinline |
4091 | void noinline |
3996 | ev_embed_sweep (EV_P_ ev_embed *w) |
4092 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
3997 | { |
4093 | { |
3998 | ev_run (w->other, EVRUN_NOWAIT); |
4094 | ev_run (w->other, EVRUN_NOWAIT); |
3999 | } |
4095 | } |
4000 | |
4096 | |
4001 | static void |
4097 | static void |
… | |
… | |
4049 | ev_idle_stop (EV_A_ idle); |
4145 | ev_idle_stop (EV_A_ idle); |
4050 | } |
4146 | } |
4051 | #endif |
4147 | #endif |
4052 | |
4148 | |
4053 | void |
4149 | void |
4054 | ev_embed_start (EV_P_ ev_embed *w) |
4150 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4055 | { |
4151 | { |
4056 | if (expect_false (ev_is_active (w))) |
4152 | if (expect_false (ev_is_active (w))) |
4057 | return; |
4153 | return; |
4058 | |
4154 | |
4059 | { |
4155 | { |
… | |
… | |
4080 | |
4176 | |
4081 | EV_FREQUENT_CHECK; |
4177 | EV_FREQUENT_CHECK; |
4082 | } |
4178 | } |
4083 | |
4179 | |
4084 | void |
4180 | void |
4085 | ev_embed_stop (EV_P_ ev_embed *w) |
4181 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4086 | { |
4182 | { |
4087 | clear_pending (EV_A_ (W)w); |
4183 | clear_pending (EV_A_ (W)w); |
4088 | if (expect_false (!ev_is_active (w))) |
4184 | if (expect_false (!ev_is_active (w))) |
4089 | return; |
4185 | return; |
4090 | |
4186 | |
… | |
… | |
4100 | } |
4196 | } |
4101 | #endif |
4197 | #endif |
4102 | |
4198 | |
4103 | #if EV_FORK_ENABLE |
4199 | #if EV_FORK_ENABLE |
4104 | void |
4200 | void |
4105 | ev_fork_start (EV_P_ ev_fork *w) |
4201 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4106 | { |
4202 | { |
4107 | if (expect_false (ev_is_active (w))) |
4203 | if (expect_false (ev_is_active (w))) |
4108 | return; |
4204 | return; |
4109 | |
4205 | |
4110 | EV_FREQUENT_CHECK; |
4206 | EV_FREQUENT_CHECK; |
… | |
… | |
4115 | |
4211 | |
4116 | EV_FREQUENT_CHECK; |
4212 | EV_FREQUENT_CHECK; |
4117 | } |
4213 | } |
4118 | |
4214 | |
4119 | void |
4215 | void |
4120 | ev_fork_stop (EV_P_ ev_fork *w) |
4216 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4121 | { |
4217 | { |
4122 | clear_pending (EV_A_ (W)w); |
4218 | clear_pending (EV_A_ (W)w); |
4123 | if (expect_false (!ev_is_active (w))) |
4219 | if (expect_false (!ev_is_active (w))) |
4124 | return; |
4220 | return; |
4125 | |
4221 | |
… | |
… | |
4138 | } |
4234 | } |
4139 | #endif |
4235 | #endif |
4140 | |
4236 | |
4141 | #if EV_CLEANUP_ENABLE |
4237 | #if EV_CLEANUP_ENABLE |
4142 | void |
4238 | void |
4143 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4239 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4144 | { |
4240 | { |
4145 | if (expect_false (ev_is_active (w))) |
4241 | if (expect_false (ev_is_active (w))) |
4146 | return; |
4242 | return; |
4147 | |
4243 | |
4148 | EV_FREQUENT_CHECK; |
4244 | EV_FREQUENT_CHECK; |
… | |
… | |
4155 | ev_unref (EV_A); |
4251 | ev_unref (EV_A); |
4156 | EV_FREQUENT_CHECK; |
4252 | EV_FREQUENT_CHECK; |
4157 | } |
4253 | } |
4158 | |
4254 | |
4159 | void |
4255 | void |
4160 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4256 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4161 | { |
4257 | { |
4162 | clear_pending (EV_A_ (W)w); |
4258 | clear_pending (EV_A_ (W)w); |
4163 | if (expect_false (!ev_is_active (w))) |
4259 | if (expect_false (!ev_is_active (w))) |
4164 | return; |
4260 | return; |
4165 | |
4261 | |
… | |
… | |
4179 | } |
4275 | } |
4180 | #endif |
4276 | #endif |
4181 | |
4277 | |
4182 | #if EV_ASYNC_ENABLE |
4278 | #if EV_ASYNC_ENABLE |
4183 | void |
4279 | void |
4184 | ev_async_start (EV_P_ ev_async *w) |
4280 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4185 | { |
4281 | { |
4186 | if (expect_false (ev_is_active (w))) |
4282 | if (expect_false (ev_is_active (w))) |
4187 | return; |
4283 | return; |
4188 | |
4284 | |
4189 | w->sent = 0; |
4285 | w->sent = 0; |
… | |
… | |
4198 | |
4294 | |
4199 | EV_FREQUENT_CHECK; |
4295 | EV_FREQUENT_CHECK; |
4200 | } |
4296 | } |
4201 | |
4297 | |
4202 | void |
4298 | void |
4203 | ev_async_stop (EV_P_ ev_async *w) |
4299 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4204 | { |
4300 | { |
4205 | clear_pending (EV_A_ (W)w); |
4301 | clear_pending (EV_A_ (W)w); |
4206 | if (expect_false (!ev_is_active (w))) |
4302 | if (expect_false (!ev_is_active (w))) |
4207 | return; |
4303 | return; |
4208 | |
4304 | |
… | |
… | |
4219 | |
4315 | |
4220 | EV_FREQUENT_CHECK; |
4316 | EV_FREQUENT_CHECK; |
4221 | } |
4317 | } |
4222 | |
4318 | |
4223 | void |
4319 | void |
4224 | ev_async_send (EV_P_ ev_async *w) |
4320 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4225 | { |
4321 | { |
4226 | w->sent = 1; |
4322 | w->sent = 1; |
4227 | evpipe_write (EV_A_ &async_pending); |
4323 | evpipe_write (EV_A_ &async_pending); |
4228 | } |
4324 | } |
4229 | #endif |
4325 | #endif |
… | |
… | |
4266 | |
4362 | |
4267 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4363 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4268 | } |
4364 | } |
4269 | |
4365 | |
4270 | void |
4366 | void |
4271 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4367 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4272 | { |
4368 | { |
4273 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4369 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4274 | |
4370 | |
4275 | if (expect_false (!once)) |
4371 | if (expect_false (!once)) |
4276 | { |
4372 | { |
… | |
… | |
4298 | |
4394 | |
4299 | /*****************************************************************************/ |
4395 | /*****************************************************************************/ |
4300 | |
4396 | |
4301 | #if EV_WALK_ENABLE |
4397 | #if EV_WALK_ENABLE |
4302 | void ecb_cold |
4398 | void ecb_cold |
4303 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4399 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4304 | { |
4400 | { |
4305 | int i, j; |
4401 | int i, j; |
4306 | ev_watcher_list *wl, *wn; |
4402 | ev_watcher_list *wl, *wn; |
4307 | |
4403 | |
4308 | if (types & (EV_IO | EV_EMBED)) |
4404 | if (types & (EV_IO | EV_EMBED)) |