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 | EV_CPP(extern "C" {) |
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 |
189 | |
198 | |
190 | #ifndef _WIN32 |
199 | #ifndef _WIN32 |
191 | # include <sys/time.h> |
200 | # include <sys/time.h> |
192 | # include <sys/wait.h> |
201 | # include <sys/wait.h> |
193 | # include <unistd.h> |
202 | # include <unistd.h> |
194 | #else |
203 | #else |
195 | # include <io.h> |
204 | # include <io.h> |
196 | # define WIN32_LEAN_AND_MEAN |
205 | # define WIN32_LEAN_AND_MEAN |
197 | # include <windows.h> |
206 | # include <windows.h> |
|
|
207 | # include <winsock2.h> |
198 | # ifndef EV_SELECT_IS_WINSOCKET |
208 | # ifndef EV_SELECT_IS_WINSOCKET |
199 | # define EV_SELECT_IS_WINSOCKET 1 |
209 | # define EV_SELECT_IS_WINSOCKET 1 |
200 | # endif |
210 | # endif |
201 | # undef EV_AVOID_STDIO |
211 | # undef EV_AVOID_STDIO |
202 | #endif |
212 | #endif |
… | |
… | |
210 | #define _DARWIN_UNLIMITED_SELECT 1 |
220 | #define _DARWIN_UNLIMITED_SELECT 1 |
211 | |
221 | |
212 | /* 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 */ |
213 | |
223 | |
214 | /* try to deduce the maximum number of signals on this platform */ |
224 | /* try to deduce the maximum number of signals on this platform */ |
215 | #if defined (EV_NSIG) |
225 | #if defined EV_NSIG |
216 | /* use what's provided */ |
226 | /* use what's provided */ |
217 | #elif defined (NSIG) |
227 | #elif defined NSIG |
218 | # define EV_NSIG (NSIG) |
228 | # define EV_NSIG (NSIG) |
219 | #elif defined(_NSIG) |
229 | #elif defined _NSIG |
220 | # define EV_NSIG (_NSIG) |
230 | # define EV_NSIG (_NSIG) |
221 | #elif defined (SIGMAX) |
231 | #elif defined SIGMAX |
222 | # define EV_NSIG (SIGMAX+1) |
232 | # define EV_NSIG (SIGMAX+1) |
223 | #elif defined (SIG_MAX) |
233 | #elif defined SIG_MAX |
224 | # define EV_NSIG (SIG_MAX+1) |
234 | # define EV_NSIG (SIG_MAX+1) |
225 | #elif defined (_SIG_MAX) |
235 | #elif defined _SIG_MAX |
226 | # define EV_NSIG (_SIG_MAX+1) |
236 | # define EV_NSIG (_SIG_MAX+1) |
227 | #elif defined (MAXSIG) |
237 | #elif defined MAXSIG |
228 | # define EV_NSIG (MAXSIG+1) |
238 | # define EV_NSIG (MAXSIG+1) |
229 | #elif defined (MAX_SIG) |
239 | #elif defined MAX_SIG |
230 | # define EV_NSIG (MAX_SIG+1) |
240 | # define EV_NSIG (MAX_SIG+1) |
231 | #elif defined (SIGARRAYSIZE) |
241 | #elif defined SIGARRAYSIZE |
232 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
242 | # define EV_NSIG (SIGARRAYSIZE) /* Assume ary[SIGARRAYSIZE] */ |
233 | #elif defined (_sys_nsig) |
243 | #elif defined _sys_nsig |
234 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
244 | # define EV_NSIG (_sys_nsig) /* Solaris 2.5 */ |
235 | #else |
245 | #else |
236 | # error "unable to find value for NSIG, please report" |
246 | # error "unable to find value for NSIG, please report" |
237 | /* to make it compile regardless, just remove the above line, */ |
247 | /* to make it compile regardless, just remove the above line, */ |
238 | /* but consider reporting it, too! :) */ |
248 | /* but consider reporting it, too! :) */ |
… | |
… | |
250 | # define EV_USE_CLOCK_SYSCALL 0 |
260 | # define EV_USE_CLOCK_SYSCALL 0 |
251 | # endif |
261 | # endif |
252 | #endif |
262 | #endif |
253 | |
263 | |
254 | #ifndef EV_USE_MONOTONIC |
264 | #ifndef EV_USE_MONOTONIC |
255 | # if defined (_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK >= 0 |
265 | # if defined _POSIX_MONOTONIC_CLOCK && _POSIX_MONOTONIC_CLOCK >= 0 |
256 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
266 | # define EV_USE_MONOTONIC EV_FEATURE_OS |
257 | # else |
267 | # else |
258 | # define EV_USE_MONOTONIC 0 |
268 | # define EV_USE_MONOTONIC 0 |
259 | # endif |
269 | # endif |
260 | #endif |
270 | #endif |
… | |
… | |
350 | #endif |
360 | #endif |
351 | |
361 | |
352 | /* 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, */ |
353 | /* which makes programs even slower. might work on other unices, too. */ |
363 | /* which makes programs even slower. might work on other unices, too. */ |
354 | #if EV_USE_CLOCK_SYSCALL |
364 | #if EV_USE_CLOCK_SYSCALL |
355 | # include <syscall.h> |
365 | # include <sys/syscall.h> |
356 | # ifdef SYS_clock_gettime |
366 | # ifdef SYS_clock_gettime |
357 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
367 | # define clock_gettime(id, ts) syscall (SYS_clock_gettime, (id), (ts)) |
358 | # undef EV_USE_MONOTONIC |
368 | # undef EV_USE_MONOTONIC |
359 | # define EV_USE_MONOTONIC 1 |
369 | # define EV_USE_MONOTONIC 1 |
360 | # else |
370 | # else |
… | |
… | |
386 | # define EV_USE_INOTIFY 0 |
396 | # define EV_USE_INOTIFY 0 |
387 | #endif |
397 | #endif |
388 | |
398 | |
389 | #if !EV_USE_NANOSLEEP |
399 | #if !EV_USE_NANOSLEEP |
390 | /* 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 */ |
391 | # if !defined(_WIN32) && !defined(__hpux) |
401 | # if !defined _WIN32 && !defined __hpux |
392 | # include <sys/select.h> |
402 | # include <sys/select.h> |
393 | # endif |
403 | # endif |
394 | #endif |
404 | #endif |
395 | |
405 | |
396 | #if EV_USE_INOTIFY |
406 | #if EV_USE_INOTIFY |
… | |
… | |
469 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
479 | /* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */ |
470 | /* ECB.H BEGIN */ |
480 | /* ECB.H BEGIN */ |
471 | /* |
481 | /* |
472 | * libecb - http://software.schmorp.de/pkg/libecb |
482 | * libecb - http://software.schmorp.de/pkg/libecb |
473 | * |
483 | * |
474 | * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de> |
484 | * Copyright (©) 2009-2012 Marc Alexander Lehmann <libecb@schmorp.de> |
475 | * Copyright (©) 2011 Emanuele Giaquinta |
485 | * Copyright (©) 2011 Emanuele Giaquinta |
476 | * All rights reserved. |
486 | * All rights reserved. |
477 | * |
487 | * |
478 | * Redistribution and use in source and binary forms, with or without modifica- |
488 | * Redistribution and use in source and binary forms, with or without modifica- |
479 | * tion, are permitted provided that the following conditions are met: |
489 | * tion, are permitted provided that the following conditions are met: |
… | |
… | |
524 | * or so. |
534 | * or so. |
525 | * we try to detect these and simply assume they are not gcc - if they have |
535 | * we try to detect these and simply assume they are not gcc - if they have |
526 | * an issue with that they should have done it right in the first place. |
536 | * an issue with that they should have done it right in the first place. |
527 | */ |
537 | */ |
528 | #ifndef ECB_GCC_VERSION |
538 | #ifndef ECB_GCC_VERSION |
529 | #if !defined(__GNUC_MINOR__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__llvm__) || defined(__clang__) |
539 | #if !defined __GNUC_MINOR__ || defined __INTEL_COMPILER || defined __SUNPRO_C || defined __SUNPRO_CC || defined __llvm__ || defined __clang__ |
530 | #define ECB_GCC_VERSION(major,minor) 0 |
540 | #define ECB_GCC_VERSION(major,minor) 0 |
531 | #else |
541 | #else |
532 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
542 | #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) |
533 | #endif |
543 | #endif |
534 | #endif |
544 | #endif |
… | |
… | |
536 | /*****************************************************************************/ |
546 | /*****************************************************************************/ |
537 | |
547 | |
538 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
548 | /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ |
539 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
549 | /* ECB_NO_SMP - ecb might be used in multiple threads, but only on a single cpu */ |
540 | |
550 | |
|
|
551 | #if ECB_NO_THREADS |
|
|
552 | # define ECB_NO_SMP 1 |
|
|
553 | #endif |
|
|
554 | |
541 | #if ECB_NO_THREADS || ECB_NO_SMP |
555 | #if ECB_NO_THREADS || ECB_NO_SMP |
542 | #define ECB_MEMORY_FENCE do { } while (0) |
556 | #define ECB_MEMORY_FENCE do { } while (0) |
543 | #endif |
557 | #endif |
544 | |
558 | |
545 | #ifndef ECB_MEMORY_FENCE |
559 | #ifndef ECB_MEMORY_FENCE |
546 | #if ECB_GCC_VERSION(2,5) |
560 | #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
547 | #if __i386__ |
561 | #if __i386 || __i386__ |
548 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") |
549 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
563 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */ |
550 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
564 | #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */ |
551 | #elif __amd64 |
565 | #elif __amd64 || __amd64__ || __x86_64 || __x86_64__ |
552 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
566 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory") |
553 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
567 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory") |
554 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
568 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */ |
555 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
569 | #elif __powerpc__ || __ppc__ || __powerpc64__ || __ppc64__ |
556 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
570 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
557 | #elif defined(__ARM_ARCH_6__ ) || defined(__ARM_ARCH_6J__ ) \ |
571 | #elif defined __ARM_ARCH_6__ || defined __ARM_ARCH_6J__ \ |
558 | || defined(__ARM_ARCH_6K__) || defined(__ARM_ARCH_6ZK__) |
572 | || defined __ARM_ARCH_6K__ || defined __ARM_ARCH_6ZK__ |
559 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
573 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mcr p15,0,%0,c7,c10,5" : : "r" (0) : "memory") |
560 | #elif defined(__ARM_ARCH_7__ ) || defined(__ARM_ARCH_7A__ ) \ |
574 | #elif defined __ARM_ARCH_7__ || defined __ARM_ARCH_7A__ \ |
561 | || defined(__ARM_ARCH_7M__) || defined(__ARM_ARCH_7R__ ) |
575 | || defined __ARM_ARCH_7M__ || defined __ARM_ARCH_7R__ |
562 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
576 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("dmb" : : : "memory") |
|
|
577 | #elif __sparc || __sparc__ |
|
|
578 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad | #StoreStore | #StoreLoad | " : : : "memory") |
|
|
579 | #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") |
|
|
580 | #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") |
|
|
581 | #elif defined __s390__ || defined __s390x__ |
|
|
582 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") |
|
|
583 | #elif defined __mips__ |
|
|
584 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") |
|
|
585 | #elif defined __alpha__ |
|
|
586 | #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") |
563 | #endif |
587 | #endif |
564 | #endif |
588 | #endif |
565 | #endif |
589 | #endif |
566 | |
590 | |
567 | #ifndef ECB_MEMORY_FENCE |
591 | #ifndef ECB_MEMORY_FENCE |
568 | #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) |
592 | #if ECB_GCC_VERSION(4,4) || defined __INTEL_COMPILER || defined __clang__ |
569 | #define ECB_MEMORY_FENCE __sync_synchronize () |
593 | #define ECB_MEMORY_FENCE __sync_synchronize () |
570 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
594 | /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ |
571 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
595 | /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */ |
572 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
596 | #elif _MSC_VER >= 1400 /* VC++ 2005 */ |
573 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
597 | #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) |
574 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
598 | #define ECB_MEMORY_FENCE _ReadWriteBarrier () |
575 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
599 | #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */ |
576 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
600 | #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier () |
577 | #elif defined(_WIN32) |
601 | #elif defined _WIN32 |
578 | #include <WinNT.h> |
602 | #include <WinNT.h> |
579 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
603 | #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */ |
|
|
604 | #elif __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 |
|
|
605 | #include <mbarrier.h> |
|
|
606 | #define ECB_MEMORY_FENCE __machine_rw_barrier () |
|
|
607 | #define ECB_MEMORY_FENCE_ACQUIRE __machine_r_barrier () |
|
|
608 | #define ECB_MEMORY_FENCE_RELEASE __machine_w_barrier () |
|
|
609 | #elif __xlC__ |
|
|
610 | #define ECB_MEMORY_FENCE __sync () |
580 | #endif |
611 | #endif |
581 | #endif |
612 | #endif |
582 | |
613 | |
583 | #ifndef ECB_MEMORY_FENCE |
614 | #ifndef ECB_MEMORY_FENCE |
584 | #if !ECB_AVOID_PTHREADS |
615 | #if !ECB_AVOID_PTHREADS |
… | |
… | |
596 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
627 | static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER; |
597 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
628 | #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0) |
598 | #endif |
629 | #endif |
599 | #endif |
630 | #endif |
600 | |
631 | |
601 | #if !defined(ECB_MEMORY_FENCE_ACQUIRE) && defined(ECB_MEMORY_FENCE) |
632 | #if !defined ECB_MEMORY_FENCE_ACQUIRE && defined ECB_MEMORY_FENCE |
602 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
633 | #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE |
603 | #endif |
634 | #endif |
604 | |
635 | |
605 | #if !defined(ECB_MEMORY_FENCE_RELEASE) && defined(ECB_MEMORY_FENCE) |
636 | #if !defined ECB_MEMORY_FENCE_RELEASE && defined ECB_MEMORY_FENCE |
606 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
637 | #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE |
607 | #endif |
638 | #endif |
608 | |
639 | |
609 | /*****************************************************************************/ |
640 | /*****************************************************************************/ |
610 | |
641 | |
… | |
… | |
759 | |
790 | |
760 | return r + ecb_ld32 (x); |
791 | return r + ecb_ld32 (x); |
761 | } |
792 | } |
762 | #endif |
793 | #endif |
763 | |
794 | |
|
|
795 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) ecb_const; |
|
|
796 | ecb_function_ uint8_t ecb_bitrev8 (uint8_t x) |
|
|
797 | { |
|
|
798 | return ( (x * 0x0802U & 0x22110U) |
|
|
799 | | (x * 0x8020U & 0x88440U)) * 0x10101U >> 16; |
|
|
800 | } |
|
|
801 | |
|
|
802 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) ecb_const; |
|
|
803 | ecb_function_ uint16_t ecb_bitrev16 (uint16_t x) |
|
|
804 | { |
|
|
805 | x = ((x >> 1) & 0x5555) | ((x & 0x5555) << 1); |
|
|
806 | x = ((x >> 2) & 0x3333) | ((x & 0x3333) << 2); |
|
|
807 | x = ((x >> 4) & 0x0f0f) | ((x & 0x0f0f) << 4); |
|
|
808 | x = ( x >> 8 ) | ( x << 8); |
|
|
809 | |
|
|
810 | return x; |
|
|
811 | } |
|
|
812 | |
|
|
813 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) ecb_const; |
|
|
814 | ecb_function_ uint32_t ecb_bitrev32 (uint32_t x) |
|
|
815 | { |
|
|
816 | x = ((x >> 1) & 0x55555555) | ((x & 0x55555555) << 1); |
|
|
817 | x = ((x >> 2) & 0x33333333) | ((x & 0x33333333) << 2); |
|
|
818 | x = ((x >> 4) & 0x0f0f0f0f) | ((x & 0x0f0f0f0f) << 4); |
|
|
819 | x = ((x >> 8) & 0x00ff00ff) | ((x & 0x00ff00ff) << 8); |
|
|
820 | x = ( x >> 16 ) | ( x << 16); |
|
|
821 | |
|
|
822 | return x; |
|
|
823 | } |
|
|
824 | |
764 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
825 | /* popcount64 is only available on 64 bit cpus as gcc builtin */ |
765 | /* so for this version we are lazy */ |
826 | /* so for this version we are lazy */ |
766 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
827 | ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const; |
767 | ecb_function_ int |
828 | ecb_function_ int |
768 | ecb_popcount64 (uint64_t x) |
829 | ecb_popcount64 (uint64_t x) |
… | |
… | |
817 | |
878 | |
818 | #if ECB_GCC_VERSION(4,5) |
879 | #if ECB_GCC_VERSION(4,5) |
819 | #define ecb_unreachable() __builtin_unreachable () |
880 | #define ecb_unreachable() __builtin_unreachable () |
820 | #else |
881 | #else |
821 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
882 | /* this seems to work fine, but gcc always emits a warning for it :/ */ |
822 | ecb_function_ void ecb_unreachable (void) ecb_noreturn; |
883 | ecb_inline void ecb_unreachable (void) ecb_noreturn; |
823 | ecb_function_ void ecb_unreachable (void) { } |
884 | ecb_inline void ecb_unreachable (void) { } |
824 | #endif |
885 | #endif |
825 | |
886 | |
826 | /* try to tell the compiler that some condition is definitely true */ |
887 | /* try to tell the compiler that some condition is definitely true */ |
827 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
888 | #define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0) |
828 | |
889 | |
829 | ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const; |
890 | ecb_inline unsigned char ecb_byteorder_helper (void) ecb_const; |
830 | ecb_function_ unsigned char |
891 | ecb_inline unsigned char |
831 | ecb_byteorder_helper (void) |
892 | ecb_byteorder_helper (void) |
832 | { |
893 | { |
833 | const uint32_t u = 0x11223344; |
894 | const uint32_t u = 0x11223344; |
834 | return *(unsigned char *)&u; |
895 | return *(unsigned char *)&u; |
835 | } |
896 | } |
836 | |
897 | |
837 | ecb_function_ ecb_bool ecb_big_endian (void) ecb_const; |
898 | ecb_inline ecb_bool ecb_big_endian (void) ecb_const; |
838 | ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
899 | ecb_inline ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; } |
839 | ecb_function_ ecb_bool ecb_little_endian (void) ecb_const; |
900 | ecb_inline ecb_bool ecb_little_endian (void) ecb_const; |
840 | ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
901 | ecb_inline ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; } |
841 | |
902 | |
842 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
903 | #if ECB_GCC_VERSION(3,0) || ECB_C99 |
843 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
904 | #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) |
844 | #else |
905 | #else |
845 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
906 | #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) |
|
|
907 | #endif |
|
|
908 | |
|
|
909 | #if __cplusplus |
|
|
910 | template<typename T> |
|
|
911 | static inline T ecb_div_rd (T val, T div) |
|
|
912 | { |
|
|
913 | return val < 0 ? - ((-val + div - 1) / div) : (val ) / div; |
|
|
914 | } |
|
|
915 | template<typename T> |
|
|
916 | static inline T ecb_div_ru (T val, T div) |
|
|
917 | { |
|
|
918 | return val < 0 ? - ((-val ) / div) : (val + div - 1) / div; |
|
|
919 | } |
|
|
920 | #else |
|
|
921 | #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div)) |
|
|
922 | #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div)) |
846 | #endif |
923 | #endif |
847 | |
924 | |
848 | #if ecb_cplusplus_does_not_suck |
925 | #if ecb_cplusplus_does_not_suck |
849 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
926 | /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */ |
850 | template<typename T, int N> |
927 | template<typename T, int N> |
… | |
… | |
862 | |
939 | |
863 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
940 | #if ECB_MEMORY_FENCE_NEEDS_PTHREADS |
864 | /* if your architecture doesn't need memory fences, e.g. because it is |
941 | /* if your architecture doesn't need memory fences, e.g. because it is |
865 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
942 | * single-cpu/core, or if you use libev in a project that doesn't use libev |
866 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
943 | * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling |
867 | * libev, in which casess the memory fences become nops. |
944 | * libev, in which cases the memory fences become nops. |
868 | * alternatively, you can remove this #error and link against libpthread, |
945 | * alternatively, you can remove this #error and link against libpthread, |
869 | * which will then provide the memory fences. |
946 | * which will then provide the memory fences. |
870 | */ |
947 | */ |
871 | # error "memory fences not defined for your architecture, please report" |
948 | # error "memory fences not defined for your architecture, please report" |
872 | #endif |
949 | #endif |
… | |
… | |
1029 | { |
1106 | { |
1030 | write (STDERR_FILENO, msg, strlen (msg)); |
1107 | write (STDERR_FILENO, msg, strlen (msg)); |
1031 | } |
1108 | } |
1032 | #endif |
1109 | #endif |
1033 | |
1110 | |
1034 | static void (*syserr_cb)(const char *msg); |
1111 | static void (*syserr_cb)(const char *msg) EV_THROW; |
1035 | |
1112 | |
1036 | void ecb_cold |
1113 | void ecb_cold |
1037 | ev_set_syserr_cb (void (*cb)(const char *msg)) |
1114 | ev_set_syserr_cb (void (*cb)(const char *msg)) EV_THROW |
1038 | { |
1115 | { |
1039 | syserr_cb = cb; |
1116 | syserr_cb = cb; |
1040 | } |
1117 | } |
1041 | |
1118 | |
1042 | static void noinline ecb_cold |
1119 | static void noinline ecb_cold |
… | |
… | |
1078 | free (ptr); |
1155 | free (ptr); |
1079 | return 0; |
1156 | return 0; |
1080 | #endif |
1157 | #endif |
1081 | } |
1158 | } |
1082 | |
1159 | |
1083 | static void *(*alloc)(void *ptr, long size) = ev_realloc_emul; |
1160 | static void *(*alloc)(void *ptr, long size) EV_THROW = ev_realloc_emul; |
1084 | |
1161 | |
1085 | void ecb_cold |
1162 | void ecb_cold |
1086 | ev_set_allocator (void *(*cb)(void *ptr, long size)) |
1163 | ev_set_allocator (void *(*cb)(void *ptr, long size)) EV_THROW |
1087 | { |
1164 | { |
1088 | alloc = cb; |
1165 | alloc = cb; |
1089 | } |
1166 | } |
1090 | |
1167 | |
1091 | inline_speed void * |
1168 | inline_speed void * |
… | |
… | |
1179 | #undef VAR |
1256 | #undef VAR |
1180 | }; |
1257 | }; |
1181 | #include "ev_wrap.h" |
1258 | #include "ev_wrap.h" |
1182 | |
1259 | |
1183 | static struct ev_loop default_loop_struct; |
1260 | static struct ev_loop default_loop_struct; |
1184 | struct ev_loop *ev_default_loop_ptr; |
1261 | EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */ |
1185 | |
1262 | |
1186 | #else |
1263 | #else |
1187 | |
1264 | |
1188 | ev_tstamp ev_rt_now; |
1265 | EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */ |
1189 | #define VAR(name,decl) static decl; |
1266 | #define VAR(name,decl) static decl; |
1190 | #include "ev_vars.h" |
1267 | #include "ev_vars.h" |
1191 | #undef VAR |
1268 | #undef VAR |
1192 | |
1269 | |
1193 | static int ev_default_loop_ptr; |
1270 | static int ev_default_loop_ptr; |
… | |
… | |
1208 | |
1285 | |
1209 | /*****************************************************************************/ |
1286 | /*****************************************************************************/ |
1210 | |
1287 | |
1211 | #ifndef EV_HAVE_EV_TIME |
1288 | #ifndef EV_HAVE_EV_TIME |
1212 | ev_tstamp |
1289 | ev_tstamp |
1213 | ev_time (void) |
1290 | ev_time (void) EV_THROW |
1214 | { |
1291 | { |
1215 | #if EV_USE_REALTIME |
1292 | #if EV_USE_REALTIME |
1216 | if (expect_true (have_realtime)) |
1293 | if (expect_true (have_realtime)) |
1217 | { |
1294 | { |
1218 | struct timespec ts; |
1295 | struct timespec ts; |
… | |
… | |
1242 | return ev_time (); |
1319 | return ev_time (); |
1243 | } |
1320 | } |
1244 | |
1321 | |
1245 | #if EV_MULTIPLICITY |
1322 | #if EV_MULTIPLICITY |
1246 | ev_tstamp |
1323 | ev_tstamp |
1247 | ev_now (EV_P) |
1324 | ev_now (EV_P) EV_THROW |
1248 | { |
1325 | { |
1249 | return ev_rt_now; |
1326 | return ev_rt_now; |
1250 | } |
1327 | } |
1251 | #endif |
1328 | #endif |
1252 | |
1329 | |
1253 | void |
1330 | void |
1254 | ev_sleep (ev_tstamp delay) |
1331 | ev_sleep (ev_tstamp delay) EV_THROW |
1255 | { |
1332 | { |
1256 | if (delay > 0.) |
1333 | if (delay > 0.) |
1257 | { |
1334 | { |
1258 | #if EV_USE_NANOSLEEP |
1335 | #if EV_USE_NANOSLEEP |
1259 | struct timespec ts; |
1336 | struct timespec ts; |
1260 | |
1337 | |
1261 | EV_TS_SET (ts, delay); |
1338 | EV_TS_SET (ts, delay); |
1262 | nanosleep (&ts, 0); |
1339 | nanosleep (&ts, 0); |
1263 | #elif defined(_WIN32) |
1340 | #elif defined _WIN32 |
1264 | Sleep ((unsigned long)(delay * 1e3)); |
1341 | Sleep ((unsigned long)(delay * 1e3)); |
1265 | #else |
1342 | #else |
1266 | struct timeval tv; |
1343 | struct timeval tv; |
1267 | |
1344 | |
1268 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
1345 | /* here we rely on sys/time.h + sys/types.h + unistd.h providing select */ |
… | |
… | |
1287 | |
1364 | |
1288 | do |
1365 | do |
1289 | ncur <<= 1; |
1366 | ncur <<= 1; |
1290 | while (cnt > ncur); |
1367 | while (cnt > ncur); |
1291 | |
1368 | |
1292 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ |
1369 | /* if size is large, round to MALLOC_ROUND - 4 * longs to accommodate malloc overhead */ |
1293 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1370 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1294 | { |
1371 | { |
1295 | ncur *= elem; |
1372 | ncur *= elem; |
1296 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1373 | ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); |
1297 | ncur = ncur - sizeof (void *) * 4; |
1374 | ncur = ncur - sizeof (void *) * 4; |
… | |
… | |
1340 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1417 | pendingcb (EV_P_ ev_prepare *w, int revents) |
1341 | { |
1418 | { |
1342 | } |
1419 | } |
1343 | |
1420 | |
1344 | void noinline |
1421 | void noinline |
1345 | ev_feed_event (EV_P_ void *w, int revents) |
1422 | ev_feed_event (EV_P_ void *w, int revents) EV_THROW |
1346 | { |
1423 | { |
1347 | W w_ = (W)w; |
1424 | W w_ = (W)w; |
1348 | int pri = ABSPRI (w_); |
1425 | int pri = ABSPRI (w_); |
1349 | |
1426 | |
1350 | if (expect_false (w_->pending)) |
1427 | if (expect_false (w_->pending)) |
… | |
… | |
1354 | w_->pending = ++pendingcnt [pri]; |
1431 | w_->pending = ++pendingcnt [pri]; |
1355 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1432 | array_needsize (ANPENDING, pendings [pri], pendingmax [pri], w_->pending, EMPTY2); |
1356 | pendings [pri][w_->pending - 1].w = w_; |
1433 | pendings [pri][w_->pending - 1].w = w_; |
1357 | pendings [pri][w_->pending - 1].events = revents; |
1434 | pendings [pri][w_->pending - 1].events = revents; |
1358 | } |
1435 | } |
|
|
1436 | |
|
|
1437 | pendingpri = NUMPRI - 1; |
1359 | } |
1438 | } |
1360 | |
1439 | |
1361 | inline_speed void |
1440 | inline_speed void |
1362 | feed_reverse (EV_P_ W w) |
1441 | feed_reverse (EV_P_ W w) |
1363 | { |
1442 | { |
… | |
… | |
1409 | if (expect_true (!anfd->reify)) |
1488 | if (expect_true (!anfd->reify)) |
1410 | fd_event_nocheck (EV_A_ fd, revents); |
1489 | fd_event_nocheck (EV_A_ fd, revents); |
1411 | } |
1490 | } |
1412 | |
1491 | |
1413 | void |
1492 | void |
1414 | ev_feed_fd_event (EV_P_ int fd, int revents) |
1493 | ev_feed_fd_event (EV_P_ int fd, int revents) EV_THROW |
1415 | { |
1494 | { |
1416 | if (fd >= 0 && fd < anfdmax) |
1495 | if (fd >= 0 && fd < anfdmax) |
1417 | fd_event_nocheck (EV_A_ fd, revents); |
1496 | fd_event_nocheck (EV_A_ fd, revents); |
1418 | } |
1497 | } |
1419 | |
1498 | |
… | |
… | |
1768 | } |
1847 | } |
1769 | |
1848 | |
1770 | inline_speed void |
1849 | inline_speed void |
1771 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1850 | evpipe_write (EV_P_ EV_ATOMIC_T *flag) |
1772 | { |
1851 | { |
|
|
1852 | ECB_MEMORY_FENCE; /* push out the write before this function was called, acquire flag */ |
|
|
1853 | |
1773 | if (expect_true (*flag)) |
1854 | if (expect_true (*flag)) |
1774 | return; |
1855 | return; |
1775 | |
1856 | |
1776 | *flag = 1; |
1857 | *flag = 1; |
1777 | |
1858 | |
… | |
… | |
1796 | write (evfd, &counter, sizeof (uint64_t)); |
1877 | write (evfd, &counter, sizeof (uint64_t)); |
1797 | } |
1878 | } |
1798 | else |
1879 | else |
1799 | #endif |
1880 | #endif |
1800 | { |
1881 | { |
1801 | /* win32 people keep sending patches that change this write() to send() */ |
1882 | #ifdef _WIN32 |
1802 | /* and then run away. but send() is wrong, it wants a socket handle on win32 */ |
1883 | WSABUF buf; |
1803 | /* so when you think this write should be a send instead, please find out */ |
1884 | DWORD sent; |
1804 | /* where your send() is from - it's definitely not the microsoft send, and */ |
1885 | buf.buf = &buf; |
1805 | /* tell me. thank you. */ |
1886 | buf.len = 1; |
|
|
1887 | WSASend (EV_FD_TO_WIN32_HANDLE (evpipe [1]), &buf, 1, &sent, 0, 0, 0); |
|
|
1888 | #else |
1806 | write (evpipe [1], &(evpipe [1]), 1); |
1889 | write (evpipe [1], &(evpipe [1]), 1); |
|
|
1890 | #endif |
1807 | } |
1891 | } |
1808 | |
1892 | |
1809 | errno = old_errno; |
1893 | errno = old_errno; |
1810 | } |
1894 | } |
1811 | } |
1895 | } |
… | |
… | |
1826 | read (evfd, &counter, sizeof (uint64_t)); |
1910 | read (evfd, &counter, sizeof (uint64_t)); |
1827 | } |
1911 | } |
1828 | else |
1912 | else |
1829 | #endif |
1913 | #endif |
1830 | { |
1914 | { |
1831 | char dummy; |
1915 | char dummy[4]; |
1832 | /* see discussion in evpipe_write when you think this read should be recv in win32 */ |
1916 | #ifdef _WIN32 |
|
|
1917 | WSABUF buf; |
|
|
1918 | DWORD recvd; |
|
|
1919 | buf.buf = dummy; |
|
|
1920 | buf.len = sizeof (dummy); |
|
|
1921 | WSARecv (EV_FD_TO_WIN32_HANDLE (evpipe [0]), &buf, 1, &recvd, 0, 0, 0); |
|
|
1922 | #else |
1833 | read (evpipe [0], &dummy, 1); |
1923 | read (evpipe [0], &dummy, sizeof (dummy)); |
|
|
1924 | #endif |
1834 | } |
1925 | } |
1835 | } |
1926 | } |
1836 | |
1927 | |
1837 | pipe_write_skipped = 0; |
1928 | pipe_write_skipped = 0; |
|
|
1929 | |
|
|
1930 | ECB_MEMORY_FENCE; /* push out skipped, acquire flags */ |
1838 | |
1931 | |
1839 | #if EV_SIGNAL_ENABLE |
1932 | #if EV_SIGNAL_ENABLE |
1840 | if (sig_pending) |
1933 | if (sig_pending) |
1841 | { |
1934 | { |
1842 | sig_pending = 0; |
1935 | sig_pending = 0; |
|
|
1936 | |
|
|
1937 | ECB_MEMORY_FENCE_RELEASE; |
1843 | |
1938 | |
1844 | for (i = EV_NSIG - 1; i--; ) |
1939 | for (i = EV_NSIG - 1; i--; ) |
1845 | if (expect_false (signals [i].pending)) |
1940 | if (expect_false (signals [i].pending)) |
1846 | ev_feed_signal_event (EV_A_ i + 1); |
1941 | ev_feed_signal_event (EV_A_ i + 1); |
1847 | } |
1942 | } |
… | |
… | |
1849 | |
1944 | |
1850 | #if EV_ASYNC_ENABLE |
1945 | #if EV_ASYNC_ENABLE |
1851 | if (async_pending) |
1946 | if (async_pending) |
1852 | { |
1947 | { |
1853 | async_pending = 0; |
1948 | async_pending = 0; |
|
|
1949 | |
|
|
1950 | ECB_MEMORY_FENCE_RELEASE; |
1854 | |
1951 | |
1855 | for (i = asynccnt; i--; ) |
1952 | for (i = asynccnt; i--; ) |
1856 | if (asyncs [i]->sent) |
1953 | if (asyncs [i]->sent) |
1857 | { |
1954 | { |
1858 | asyncs [i]->sent = 0; |
1955 | asyncs [i]->sent = 0; |
… | |
… | |
1863 | } |
1960 | } |
1864 | |
1961 | |
1865 | /*****************************************************************************/ |
1962 | /*****************************************************************************/ |
1866 | |
1963 | |
1867 | void |
1964 | void |
1868 | ev_feed_signal (int signum) |
1965 | ev_feed_signal (int signum) EV_THROW |
1869 | { |
1966 | { |
1870 | #if EV_MULTIPLICITY |
1967 | #if EV_MULTIPLICITY |
1871 | EV_P = signals [signum - 1].loop; |
1968 | EV_P = signals [signum - 1].loop; |
1872 | |
1969 | |
1873 | if (!EV_A) |
1970 | if (!EV_A) |
… | |
… | |
1890 | |
1987 | |
1891 | ev_feed_signal (signum); |
1988 | ev_feed_signal (signum); |
1892 | } |
1989 | } |
1893 | |
1990 | |
1894 | void noinline |
1991 | void noinline |
1895 | ev_feed_signal_event (EV_P_ int signum) |
1992 | ev_feed_signal_event (EV_P_ int signum) EV_THROW |
1896 | { |
1993 | { |
1897 | WL w; |
1994 | WL w; |
1898 | |
1995 | |
1899 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1996 | if (expect_false (signum <= 0 || signum > EV_NSIG)) |
1900 | return; |
1997 | return; |
… | |
… | |
2016 | #if EV_USE_SELECT |
2113 | #if EV_USE_SELECT |
2017 | # include "ev_select.c" |
2114 | # include "ev_select.c" |
2018 | #endif |
2115 | #endif |
2019 | |
2116 | |
2020 | int ecb_cold |
2117 | int ecb_cold |
2021 | ev_version_major (void) |
2118 | ev_version_major (void) EV_THROW |
2022 | { |
2119 | { |
2023 | return EV_VERSION_MAJOR; |
2120 | return EV_VERSION_MAJOR; |
2024 | } |
2121 | } |
2025 | |
2122 | |
2026 | int ecb_cold |
2123 | int ecb_cold |
2027 | ev_version_minor (void) |
2124 | ev_version_minor (void) EV_THROW |
2028 | { |
2125 | { |
2029 | return EV_VERSION_MINOR; |
2126 | return EV_VERSION_MINOR; |
2030 | } |
2127 | } |
2031 | |
2128 | |
2032 | /* return true if we are running with elevated privileges and should ignore env variables */ |
2129 | /* return true if we are running with elevated privileges and should ignore env variables */ |
… | |
… | |
2040 | || getgid () != getegid (); |
2137 | || getgid () != getegid (); |
2041 | #endif |
2138 | #endif |
2042 | } |
2139 | } |
2043 | |
2140 | |
2044 | unsigned int ecb_cold |
2141 | unsigned int ecb_cold |
2045 | ev_supported_backends (void) |
2142 | ev_supported_backends (void) EV_THROW |
2046 | { |
2143 | { |
2047 | unsigned int flags = 0; |
2144 | unsigned int flags = 0; |
2048 | |
2145 | |
2049 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2146 | if (EV_USE_PORT ) flags |= EVBACKEND_PORT; |
2050 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
2147 | if (EV_USE_KQUEUE) flags |= EVBACKEND_KQUEUE; |
… | |
… | |
2054 | |
2151 | |
2055 | return flags; |
2152 | return flags; |
2056 | } |
2153 | } |
2057 | |
2154 | |
2058 | unsigned int ecb_cold |
2155 | unsigned int ecb_cold |
2059 | ev_recommended_backends (void) |
2156 | ev_recommended_backends (void) EV_THROW |
2060 | { |
2157 | { |
2061 | unsigned int flags = ev_supported_backends (); |
2158 | unsigned int flags = ev_supported_backends (); |
2062 | |
2159 | |
2063 | #ifndef __NetBSD__ |
2160 | #ifndef __NetBSD__ |
2064 | /* kqueue is borked on everything but netbsd apparently */ |
2161 | /* kqueue is borked on everything but netbsd apparently */ |
… | |
… | |
2076 | |
2173 | |
2077 | return flags; |
2174 | return flags; |
2078 | } |
2175 | } |
2079 | |
2176 | |
2080 | unsigned int ecb_cold |
2177 | unsigned int ecb_cold |
2081 | ev_embeddable_backends (void) |
2178 | ev_embeddable_backends (void) EV_THROW |
2082 | { |
2179 | { |
2083 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2180 | int flags = EVBACKEND_EPOLL | EVBACKEND_KQUEUE | EVBACKEND_PORT; |
2084 | |
2181 | |
2085 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2182 | /* epoll embeddability broken on all linux versions up to at least 2.6.23 */ |
2086 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
2183 | if (ev_linux_version () < 0x020620) /* disable it on linux < 2.6.32 */ |
… | |
… | |
2088 | |
2185 | |
2089 | return flags; |
2186 | return flags; |
2090 | } |
2187 | } |
2091 | |
2188 | |
2092 | unsigned int |
2189 | unsigned int |
2093 | ev_backend (EV_P) |
2190 | ev_backend (EV_P) EV_THROW |
2094 | { |
2191 | { |
2095 | return backend; |
2192 | return backend; |
2096 | } |
2193 | } |
2097 | |
2194 | |
2098 | #if EV_FEATURE_API |
2195 | #if EV_FEATURE_API |
2099 | unsigned int |
2196 | unsigned int |
2100 | ev_iteration (EV_P) |
2197 | ev_iteration (EV_P) EV_THROW |
2101 | { |
2198 | { |
2102 | return loop_count; |
2199 | return loop_count; |
2103 | } |
2200 | } |
2104 | |
2201 | |
2105 | unsigned int |
2202 | unsigned int |
2106 | ev_depth (EV_P) |
2203 | ev_depth (EV_P) EV_THROW |
2107 | { |
2204 | { |
2108 | return loop_depth; |
2205 | return loop_depth; |
2109 | } |
2206 | } |
2110 | |
2207 | |
2111 | void |
2208 | void |
2112 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) |
2209 | ev_set_io_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2113 | { |
2210 | { |
2114 | io_blocktime = interval; |
2211 | io_blocktime = interval; |
2115 | } |
2212 | } |
2116 | |
2213 | |
2117 | void |
2214 | void |
2118 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) |
2215 | ev_set_timeout_collect_interval (EV_P_ ev_tstamp interval) EV_THROW |
2119 | { |
2216 | { |
2120 | timeout_blocktime = interval; |
2217 | timeout_blocktime = interval; |
2121 | } |
2218 | } |
2122 | |
2219 | |
2123 | void |
2220 | void |
2124 | ev_set_userdata (EV_P_ void *data) |
2221 | ev_set_userdata (EV_P_ void *data) EV_THROW |
2125 | { |
2222 | { |
2126 | userdata = data; |
2223 | userdata = data; |
2127 | } |
2224 | } |
2128 | |
2225 | |
2129 | void * |
2226 | void * |
2130 | ev_userdata (EV_P) |
2227 | ev_userdata (EV_P) EV_THROW |
2131 | { |
2228 | { |
2132 | return userdata; |
2229 | return userdata; |
2133 | } |
2230 | } |
2134 | |
2231 | |
2135 | void |
2232 | void |
2136 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) |
2233 | ev_set_invoke_pending_cb (EV_P_ void (*invoke_pending_cb)(EV_P)) EV_THROW |
2137 | { |
2234 | { |
2138 | invoke_cb = invoke_pending_cb; |
2235 | invoke_cb = invoke_pending_cb; |
2139 | } |
2236 | } |
2140 | |
2237 | |
2141 | void |
2238 | void |
2142 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P), void (*acquire)(EV_P)) |
2239 | ev_set_loop_release_cb (EV_P_ void (*release)(EV_P) EV_THROW, void (*acquire)(EV_P) EV_THROW) EV_THROW |
2143 | { |
2240 | { |
2144 | release_cb = release; |
2241 | release_cb = release; |
2145 | acquire_cb = acquire; |
2242 | acquire_cb = acquire; |
2146 | } |
2243 | } |
2147 | #endif |
2244 | #endif |
2148 | |
2245 | |
2149 | /* initialise a loop structure, must be zero-initialised */ |
2246 | /* initialise a loop structure, must be zero-initialised */ |
2150 | static void noinline ecb_cold |
2247 | static void noinline ecb_cold |
2151 | loop_init (EV_P_ unsigned int flags) |
2248 | loop_init (EV_P_ unsigned int flags) EV_THROW |
2152 | { |
2249 | { |
2153 | if (!backend) |
2250 | if (!backend) |
2154 | { |
2251 | { |
2155 | origflags = flags; |
2252 | origflags = flags; |
2156 | |
2253 | |
… | |
… | |
2409 | } |
2506 | } |
2410 | |
2507 | |
2411 | #if EV_MULTIPLICITY |
2508 | #if EV_MULTIPLICITY |
2412 | |
2509 | |
2413 | struct ev_loop * ecb_cold |
2510 | struct ev_loop * ecb_cold |
2414 | ev_loop_new (unsigned int flags) |
2511 | ev_loop_new (unsigned int flags) EV_THROW |
2415 | { |
2512 | { |
2416 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2513 | EV_P = (struct ev_loop *)ev_malloc (sizeof (struct ev_loop)); |
2417 | |
2514 | |
2418 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2515 | memset (EV_A, 0, sizeof (struct ev_loop)); |
2419 | loop_init (EV_A_ flags); |
2516 | loop_init (EV_A_ flags); |
… | |
… | |
2463 | } |
2560 | } |
2464 | #endif |
2561 | #endif |
2465 | |
2562 | |
2466 | #if EV_FEATURE_API |
2563 | #if EV_FEATURE_API |
2467 | void ecb_cold |
2564 | void ecb_cold |
2468 | ev_verify (EV_P) |
2565 | ev_verify (EV_P) EV_THROW |
2469 | { |
2566 | { |
2470 | #if EV_VERIFY |
2567 | #if EV_VERIFY |
2471 | int i; |
2568 | int i, j; |
2472 | WL w; |
2569 | WL w, w2; |
2473 | |
2570 | |
2474 | assert (activecnt >= -1); |
2571 | assert (activecnt >= -1); |
2475 | |
2572 | |
2476 | assert (fdchangemax >= fdchangecnt); |
2573 | assert (fdchangemax >= fdchangecnt); |
2477 | for (i = 0; i < fdchangecnt; ++i) |
2574 | for (i = 0; i < fdchangecnt; ++i) |
2478 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2575 | assert (("libev: negative fd in fdchanges", fdchanges [i] >= 0)); |
2479 | |
2576 | |
2480 | assert (anfdmax >= 0); |
2577 | assert (anfdmax >= 0); |
2481 | for (i = 0; i < anfdmax; ++i) |
2578 | for (i = j = 0; i < anfdmax; ++i) |
2482 | for (w = anfds [i].head; w; w = w->next) |
2579 | for (w = w2 = anfds [i].head; w; w = w->next) |
2483 | { |
2580 | { |
2484 | verify_watcher (EV_A_ (W)w); |
2581 | verify_watcher (EV_A_ (W)w); |
|
|
2582 | |
|
|
2583 | if (j++ & 1) |
|
|
2584 | { |
|
|
2585 | assert (("libev: io watcher list contains a loop", w != w2)); |
|
|
2586 | w2 = w2->next; |
|
|
2587 | } |
|
|
2588 | |
2485 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2589 | assert (("libev: inactive fd watcher on anfd list", ev_active (w) == 1)); |
2486 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2590 | assert (("libev: fd mismatch between watcher and anfd", ((ev_io *)w)->fd == i)); |
2487 | } |
2591 | } |
2488 | |
2592 | |
2489 | assert (timermax >= timercnt); |
2593 | assert (timermax >= timercnt); |
… | |
… | |
2542 | #if EV_MULTIPLICITY |
2646 | #if EV_MULTIPLICITY |
2543 | struct ev_loop * ecb_cold |
2647 | struct ev_loop * ecb_cold |
2544 | #else |
2648 | #else |
2545 | int |
2649 | int |
2546 | #endif |
2650 | #endif |
2547 | ev_default_loop (unsigned int flags) |
2651 | ev_default_loop (unsigned int flags) EV_THROW |
2548 | { |
2652 | { |
2549 | if (!ev_default_loop_ptr) |
2653 | if (!ev_default_loop_ptr) |
2550 | { |
2654 | { |
2551 | #if EV_MULTIPLICITY |
2655 | #if EV_MULTIPLICITY |
2552 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
2656 | EV_P = ev_default_loop_ptr = &default_loop_struct; |
… | |
… | |
2571 | |
2675 | |
2572 | return ev_default_loop_ptr; |
2676 | return ev_default_loop_ptr; |
2573 | } |
2677 | } |
2574 | |
2678 | |
2575 | void |
2679 | void |
2576 | ev_loop_fork (EV_P) |
2680 | ev_loop_fork (EV_P) EV_THROW |
2577 | { |
2681 | { |
2578 | postfork = 1; /* must be in line with ev_default_fork */ |
2682 | postfork = 1; /* must be in line with ev_default_fork */ |
2579 | } |
2683 | } |
2580 | |
2684 | |
2581 | /*****************************************************************************/ |
2685 | /*****************************************************************************/ |
… | |
… | |
2585 | { |
2689 | { |
2586 | EV_CB_INVOKE ((W)w, revents); |
2690 | EV_CB_INVOKE ((W)w, revents); |
2587 | } |
2691 | } |
2588 | |
2692 | |
2589 | unsigned int |
2693 | unsigned int |
2590 | ev_pending_count (EV_P) |
2694 | ev_pending_count (EV_P) EV_THROW |
2591 | { |
2695 | { |
2592 | int pri; |
2696 | int pri; |
2593 | unsigned int count = 0; |
2697 | unsigned int count = 0; |
2594 | |
2698 | |
2595 | for (pri = NUMPRI; pri--; ) |
2699 | for (pri = NUMPRI; pri--; ) |
… | |
… | |
2599 | } |
2703 | } |
2600 | |
2704 | |
2601 | void noinline |
2705 | void noinline |
2602 | ev_invoke_pending (EV_P) |
2706 | ev_invoke_pending (EV_P) |
2603 | { |
2707 | { |
2604 | int pri; |
2708 | for (pendingpri = NUMPRI; pendingpri--; ) /* pendingpri is modified during the loop */ |
2605 | |
|
|
2606 | for (pri = NUMPRI; pri--; ) |
|
|
2607 | while (pendingcnt [pri]) |
2709 | while (pendingcnt [pendingpri]) |
2608 | { |
2710 | { |
2609 | ANPENDING *p = pendings [pri] + --pendingcnt [pri]; |
2711 | ANPENDING *p = pendings [pendingpri] + --pendingcnt [pendingpri]; |
2610 | |
2712 | |
2611 | p->w->pending = 0; |
2713 | p->w->pending = 0; |
2612 | EV_CB_INVOKE (p->w, p->events); |
2714 | EV_CB_INVOKE (p->w, p->events); |
2613 | EV_FREQUENT_CHECK; |
2715 | EV_FREQUENT_CHECK; |
2614 | } |
2716 | } |
… | |
… | |
2854 | |
2956 | |
2855 | mn_now = ev_rt_now; |
2957 | mn_now = ev_rt_now; |
2856 | } |
2958 | } |
2857 | } |
2959 | } |
2858 | |
2960 | |
2859 | void |
2961 | int |
2860 | ev_run (EV_P_ int flags) |
2962 | ev_run (EV_P_ int flags) |
2861 | { |
2963 | { |
2862 | #if EV_FEATURE_API |
2964 | #if EV_FEATURE_API |
2863 | ++loop_depth; |
2965 | ++loop_depth; |
2864 | #endif |
2966 | #endif |
… | |
… | |
2977 | #endif |
3079 | #endif |
2978 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
3080 | assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ |
2979 | backend_poll (EV_A_ waittime); |
3081 | backend_poll (EV_A_ waittime); |
2980 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
3082 | assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ |
2981 | |
3083 | |
2982 | pipe_write_wanted = 0; /* just an optimsiation, no fence needed */ |
3084 | pipe_write_wanted = 0; /* just an optimisation, no fence needed */ |
2983 | |
3085 | |
2984 | if (pipe_write_skipped) |
3086 | if (pipe_write_skipped) |
2985 | { |
3087 | { |
2986 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
3088 | assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); |
2987 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
3089 | ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); |
… | |
… | |
3021 | loop_done = EVBREAK_CANCEL; |
3123 | loop_done = EVBREAK_CANCEL; |
3022 | |
3124 | |
3023 | #if EV_FEATURE_API |
3125 | #if EV_FEATURE_API |
3024 | --loop_depth; |
3126 | --loop_depth; |
3025 | #endif |
3127 | #endif |
|
|
3128 | |
|
|
3129 | return activecnt; |
3026 | } |
3130 | } |
3027 | |
3131 | |
3028 | void |
3132 | void |
3029 | ev_break (EV_P_ int how) |
3133 | ev_break (EV_P_ int how) EV_THROW |
3030 | { |
3134 | { |
3031 | loop_done = how; |
3135 | loop_done = how; |
3032 | } |
3136 | } |
3033 | |
3137 | |
3034 | void |
3138 | void |
3035 | ev_ref (EV_P) |
3139 | ev_ref (EV_P) EV_THROW |
3036 | { |
3140 | { |
3037 | ++activecnt; |
3141 | ++activecnt; |
3038 | } |
3142 | } |
3039 | |
3143 | |
3040 | void |
3144 | void |
3041 | ev_unref (EV_P) |
3145 | ev_unref (EV_P) EV_THROW |
3042 | { |
3146 | { |
3043 | --activecnt; |
3147 | --activecnt; |
3044 | } |
3148 | } |
3045 | |
3149 | |
3046 | void |
3150 | void |
3047 | ev_now_update (EV_P) |
3151 | ev_now_update (EV_P) EV_THROW |
3048 | { |
3152 | { |
3049 | time_update (EV_A_ 1e100); |
3153 | time_update (EV_A_ 1e100); |
3050 | } |
3154 | } |
3051 | |
3155 | |
3052 | void |
3156 | void |
3053 | ev_suspend (EV_P) |
3157 | ev_suspend (EV_P) EV_THROW |
3054 | { |
3158 | { |
3055 | ev_now_update (EV_A); |
3159 | ev_now_update (EV_A); |
3056 | } |
3160 | } |
3057 | |
3161 | |
3058 | void |
3162 | void |
3059 | ev_resume (EV_P) |
3163 | ev_resume (EV_P) EV_THROW |
3060 | { |
3164 | { |
3061 | ev_tstamp mn_prev = mn_now; |
3165 | ev_tstamp mn_prev = mn_now; |
3062 | |
3166 | |
3063 | ev_now_update (EV_A); |
3167 | ev_now_update (EV_A); |
3064 | timers_reschedule (EV_A_ mn_now - mn_prev); |
3168 | timers_reschedule (EV_A_ mn_now - mn_prev); |
… | |
… | |
3103 | w->pending = 0; |
3207 | w->pending = 0; |
3104 | } |
3208 | } |
3105 | } |
3209 | } |
3106 | |
3210 | |
3107 | int |
3211 | int |
3108 | ev_clear_pending (EV_P_ void *w) |
3212 | ev_clear_pending (EV_P_ void *w) EV_THROW |
3109 | { |
3213 | { |
3110 | W w_ = (W)w; |
3214 | W w_ = (W)w; |
3111 | int pending = w_->pending; |
3215 | int pending = w_->pending; |
3112 | |
3216 | |
3113 | if (expect_true (pending)) |
3217 | if (expect_true (pending)) |
… | |
… | |
3146 | } |
3250 | } |
3147 | |
3251 | |
3148 | /*****************************************************************************/ |
3252 | /*****************************************************************************/ |
3149 | |
3253 | |
3150 | void noinline |
3254 | void noinline |
3151 | ev_io_start (EV_P_ ev_io *w) |
3255 | ev_io_start (EV_P_ ev_io *w) EV_THROW |
3152 | { |
3256 | { |
3153 | int fd = w->fd; |
3257 | int fd = w->fd; |
3154 | |
3258 | |
3155 | if (expect_false (ev_is_active (w))) |
3259 | if (expect_false (ev_is_active (w))) |
3156 | return; |
3260 | return; |
… | |
… | |
3162 | |
3266 | |
3163 | ev_start (EV_A_ (W)w, 1); |
3267 | ev_start (EV_A_ (W)w, 1); |
3164 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3268 | array_needsize (ANFD, anfds, anfdmax, fd + 1, array_init_zero); |
3165 | wlist_add (&anfds[fd].head, (WL)w); |
3269 | wlist_add (&anfds[fd].head, (WL)w); |
3166 | |
3270 | |
|
|
3271 | /* common bug, apparently */ |
|
|
3272 | assert (("libev: ev_io_start called with corrupted watcher", ((WL)w)->next != (WL)w)); |
|
|
3273 | |
3167 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3274 | fd_change (EV_A_ fd, w->events & EV__IOFDSET | EV_ANFD_REIFY); |
3168 | w->events &= ~EV__IOFDSET; |
3275 | w->events &= ~EV__IOFDSET; |
3169 | |
3276 | |
3170 | EV_FREQUENT_CHECK; |
3277 | EV_FREQUENT_CHECK; |
3171 | } |
3278 | } |
3172 | |
3279 | |
3173 | void noinline |
3280 | void noinline |
3174 | ev_io_stop (EV_P_ ev_io *w) |
3281 | ev_io_stop (EV_P_ ev_io *w) EV_THROW |
3175 | { |
3282 | { |
3176 | clear_pending (EV_A_ (W)w); |
3283 | clear_pending (EV_A_ (W)w); |
3177 | if (expect_false (!ev_is_active (w))) |
3284 | if (expect_false (!ev_is_active (w))) |
3178 | return; |
3285 | return; |
3179 | |
3286 | |
… | |
… | |
3188 | |
3295 | |
3189 | EV_FREQUENT_CHECK; |
3296 | EV_FREQUENT_CHECK; |
3190 | } |
3297 | } |
3191 | |
3298 | |
3192 | void noinline |
3299 | void noinline |
3193 | ev_timer_start (EV_P_ ev_timer *w) |
3300 | ev_timer_start (EV_P_ ev_timer *w) EV_THROW |
3194 | { |
3301 | { |
3195 | if (expect_false (ev_is_active (w))) |
3302 | if (expect_false (ev_is_active (w))) |
3196 | return; |
3303 | return; |
3197 | |
3304 | |
3198 | ev_at (w) += mn_now; |
3305 | ev_at (w) += mn_now; |
… | |
… | |
3212 | |
3319 | |
3213 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3320 | /*assert (("libev: internal timer heap corruption", timers [ev_active (w)] == (WT)w));*/ |
3214 | } |
3321 | } |
3215 | |
3322 | |
3216 | void noinline |
3323 | void noinline |
3217 | ev_timer_stop (EV_P_ ev_timer *w) |
3324 | ev_timer_stop (EV_P_ ev_timer *w) EV_THROW |
3218 | { |
3325 | { |
3219 | clear_pending (EV_A_ (W)w); |
3326 | clear_pending (EV_A_ (W)w); |
3220 | if (expect_false (!ev_is_active (w))) |
3327 | if (expect_false (!ev_is_active (w))) |
3221 | return; |
3328 | return; |
3222 | |
3329 | |
… | |
… | |
3242 | |
3349 | |
3243 | EV_FREQUENT_CHECK; |
3350 | EV_FREQUENT_CHECK; |
3244 | } |
3351 | } |
3245 | |
3352 | |
3246 | void noinline |
3353 | void noinline |
3247 | ev_timer_again (EV_P_ ev_timer *w) |
3354 | ev_timer_again (EV_P_ ev_timer *w) EV_THROW |
3248 | { |
3355 | { |
3249 | EV_FREQUENT_CHECK; |
3356 | EV_FREQUENT_CHECK; |
|
|
3357 | |
|
|
3358 | clear_pending (EV_A_ (W)w); |
3250 | |
3359 | |
3251 | if (ev_is_active (w)) |
3360 | if (ev_is_active (w)) |
3252 | { |
3361 | { |
3253 | if (w->repeat) |
3362 | if (w->repeat) |
3254 | { |
3363 | { |
… | |
… | |
3267 | |
3376 | |
3268 | EV_FREQUENT_CHECK; |
3377 | EV_FREQUENT_CHECK; |
3269 | } |
3378 | } |
3270 | |
3379 | |
3271 | ev_tstamp |
3380 | ev_tstamp |
3272 | ev_timer_remaining (EV_P_ ev_timer *w) |
3381 | ev_timer_remaining (EV_P_ ev_timer *w) EV_THROW |
3273 | { |
3382 | { |
3274 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3383 | return ev_at (w) - (ev_is_active (w) ? mn_now : 0.); |
3275 | } |
3384 | } |
3276 | |
3385 | |
3277 | #if EV_PERIODIC_ENABLE |
3386 | #if EV_PERIODIC_ENABLE |
3278 | void noinline |
3387 | void noinline |
3279 | ev_periodic_start (EV_P_ ev_periodic *w) |
3388 | ev_periodic_start (EV_P_ ev_periodic *w) EV_THROW |
3280 | { |
3389 | { |
3281 | if (expect_false (ev_is_active (w))) |
3390 | if (expect_false (ev_is_active (w))) |
3282 | return; |
3391 | return; |
3283 | |
3392 | |
3284 | if (w->reschedule_cb) |
3393 | if (w->reschedule_cb) |
… | |
… | |
3304 | |
3413 | |
3305 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3414 | /*assert (("libev: internal periodic heap corruption", ANHE_w (periodics [ev_active (w)]) == (WT)w));*/ |
3306 | } |
3415 | } |
3307 | |
3416 | |
3308 | void noinline |
3417 | void noinline |
3309 | ev_periodic_stop (EV_P_ ev_periodic *w) |
3418 | ev_periodic_stop (EV_P_ ev_periodic *w) EV_THROW |
3310 | { |
3419 | { |
3311 | clear_pending (EV_A_ (W)w); |
3420 | clear_pending (EV_A_ (W)w); |
3312 | if (expect_false (!ev_is_active (w))) |
3421 | if (expect_false (!ev_is_active (w))) |
3313 | return; |
3422 | return; |
3314 | |
3423 | |
… | |
… | |
3332 | |
3441 | |
3333 | EV_FREQUENT_CHECK; |
3442 | EV_FREQUENT_CHECK; |
3334 | } |
3443 | } |
3335 | |
3444 | |
3336 | void noinline |
3445 | void noinline |
3337 | ev_periodic_again (EV_P_ ev_periodic *w) |
3446 | ev_periodic_again (EV_P_ ev_periodic *w) EV_THROW |
3338 | { |
3447 | { |
3339 | /* TODO: use adjustheap and recalculation */ |
3448 | /* TODO: use adjustheap and recalculation */ |
3340 | ev_periodic_stop (EV_A_ w); |
3449 | ev_periodic_stop (EV_A_ w); |
3341 | ev_periodic_start (EV_A_ w); |
3450 | ev_periodic_start (EV_A_ w); |
3342 | } |
3451 | } |
… | |
… | |
3347 | #endif |
3456 | #endif |
3348 | |
3457 | |
3349 | #if EV_SIGNAL_ENABLE |
3458 | #if EV_SIGNAL_ENABLE |
3350 | |
3459 | |
3351 | void noinline |
3460 | void noinline |
3352 | ev_signal_start (EV_P_ ev_signal *w) |
3461 | ev_signal_start (EV_P_ ev_signal *w) EV_THROW |
3353 | { |
3462 | { |
3354 | if (expect_false (ev_is_active (w))) |
3463 | if (expect_false (ev_is_active (w))) |
3355 | return; |
3464 | return; |
3356 | |
3465 | |
3357 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
3466 | assert (("libev: ev_signal_start called with illegal signal number", w->signum > 0 && w->signum < EV_NSIG)); |
… | |
… | |
3428 | |
3537 | |
3429 | EV_FREQUENT_CHECK; |
3538 | EV_FREQUENT_CHECK; |
3430 | } |
3539 | } |
3431 | |
3540 | |
3432 | void noinline |
3541 | void noinline |
3433 | ev_signal_stop (EV_P_ ev_signal *w) |
3542 | ev_signal_stop (EV_P_ ev_signal *w) EV_THROW |
3434 | { |
3543 | { |
3435 | clear_pending (EV_A_ (W)w); |
3544 | clear_pending (EV_A_ (W)w); |
3436 | if (expect_false (!ev_is_active (w))) |
3545 | if (expect_false (!ev_is_active (w))) |
3437 | return; |
3546 | return; |
3438 | |
3547 | |
… | |
… | |
3469 | #endif |
3578 | #endif |
3470 | |
3579 | |
3471 | #if EV_CHILD_ENABLE |
3580 | #if EV_CHILD_ENABLE |
3472 | |
3581 | |
3473 | void |
3582 | void |
3474 | ev_child_start (EV_P_ ev_child *w) |
3583 | ev_child_start (EV_P_ ev_child *w) EV_THROW |
3475 | { |
3584 | { |
3476 | #if EV_MULTIPLICITY |
3585 | #if EV_MULTIPLICITY |
3477 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3586 | assert (("libev: child watchers are only supported in the default loop", loop == ev_default_loop_ptr)); |
3478 | #endif |
3587 | #endif |
3479 | if (expect_false (ev_is_active (w))) |
3588 | if (expect_false (ev_is_active (w))) |
… | |
… | |
3486 | |
3595 | |
3487 | EV_FREQUENT_CHECK; |
3596 | EV_FREQUENT_CHECK; |
3488 | } |
3597 | } |
3489 | |
3598 | |
3490 | void |
3599 | void |
3491 | ev_child_stop (EV_P_ ev_child *w) |
3600 | ev_child_stop (EV_P_ ev_child *w) EV_THROW |
3492 | { |
3601 | { |
3493 | clear_pending (EV_A_ (W)w); |
3602 | clear_pending (EV_A_ (W)w); |
3494 | if (expect_false (!ev_is_active (w))) |
3603 | if (expect_false (!ev_is_active (w))) |
3495 | return; |
3604 | return; |
3496 | |
3605 | |
… | |
… | |
3663 | } |
3772 | } |
3664 | |
3773 | |
3665 | inline_size int |
3774 | inline_size int |
3666 | infy_newfd (void) |
3775 | infy_newfd (void) |
3667 | { |
3776 | { |
3668 | #if defined (IN_CLOEXEC) && defined (IN_NONBLOCK) |
3777 | #if defined IN_CLOEXEC && defined IN_NONBLOCK |
3669 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3778 | int fd = inotify_init1 (IN_CLOEXEC | IN_NONBLOCK); |
3670 | if (fd >= 0) |
3779 | if (fd >= 0) |
3671 | return fd; |
3780 | return fd; |
3672 | #endif |
3781 | #endif |
3673 | return inotify_init (); |
3782 | return inotify_init (); |
… | |
… | |
3748 | #else |
3857 | #else |
3749 | # define EV_LSTAT(p,b) lstat (p, b) |
3858 | # define EV_LSTAT(p,b) lstat (p, b) |
3750 | #endif |
3859 | #endif |
3751 | |
3860 | |
3752 | void |
3861 | void |
3753 | ev_stat_stat (EV_P_ ev_stat *w) |
3862 | ev_stat_stat (EV_P_ ev_stat *w) EV_THROW |
3754 | { |
3863 | { |
3755 | if (lstat (w->path, &w->attr) < 0) |
3864 | if (lstat (w->path, &w->attr) < 0) |
3756 | w->attr.st_nlink = 0; |
3865 | w->attr.st_nlink = 0; |
3757 | else if (!w->attr.st_nlink) |
3866 | else if (!w->attr.st_nlink) |
3758 | w->attr.st_nlink = 1; |
3867 | w->attr.st_nlink = 1; |
… | |
… | |
3797 | ev_feed_event (EV_A_ w, EV_STAT); |
3906 | ev_feed_event (EV_A_ w, EV_STAT); |
3798 | } |
3907 | } |
3799 | } |
3908 | } |
3800 | |
3909 | |
3801 | void |
3910 | void |
3802 | ev_stat_start (EV_P_ ev_stat *w) |
3911 | ev_stat_start (EV_P_ ev_stat *w) EV_THROW |
3803 | { |
3912 | { |
3804 | if (expect_false (ev_is_active (w))) |
3913 | if (expect_false (ev_is_active (w))) |
3805 | return; |
3914 | return; |
3806 | |
3915 | |
3807 | ev_stat_stat (EV_A_ w); |
3916 | ev_stat_stat (EV_A_ w); |
… | |
… | |
3828 | |
3937 | |
3829 | EV_FREQUENT_CHECK; |
3938 | EV_FREQUENT_CHECK; |
3830 | } |
3939 | } |
3831 | |
3940 | |
3832 | void |
3941 | void |
3833 | ev_stat_stop (EV_P_ ev_stat *w) |
3942 | ev_stat_stop (EV_P_ ev_stat *w) EV_THROW |
3834 | { |
3943 | { |
3835 | clear_pending (EV_A_ (W)w); |
3944 | clear_pending (EV_A_ (W)w); |
3836 | if (expect_false (!ev_is_active (w))) |
3945 | if (expect_false (!ev_is_active (w))) |
3837 | return; |
3946 | return; |
3838 | |
3947 | |
… | |
… | |
3854 | } |
3963 | } |
3855 | #endif |
3964 | #endif |
3856 | |
3965 | |
3857 | #if EV_IDLE_ENABLE |
3966 | #if EV_IDLE_ENABLE |
3858 | void |
3967 | void |
3859 | ev_idle_start (EV_P_ ev_idle *w) |
3968 | ev_idle_start (EV_P_ ev_idle *w) EV_THROW |
3860 | { |
3969 | { |
3861 | if (expect_false (ev_is_active (w))) |
3970 | if (expect_false (ev_is_active (w))) |
3862 | return; |
3971 | return; |
3863 | |
3972 | |
3864 | pri_adjust (EV_A_ (W)w); |
3973 | pri_adjust (EV_A_ (W)w); |
… | |
… | |
3877 | |
3986 | |
3878 | EV_FREQUENT_CHECK; |
3987 | EV_FREQUENT_CHECK; |
3879 | } |
3988 | } |
3880 | |
3989 | |
3881 | void |
3990 | void |
3882 | ev_idle_stop (EV_P_ ev_idle *w) |
3991 | ev_idle_stop (EV_P_ ev_idle *w) EV_THROW |
3883 | { |
3992 | { |
3884 | clear_pending (EV_A_ (W)w); |
3993 | clear_pending (EV_A_ (W)w); |
3885 | if (expect_false (!ev_is_active (w))) |
3994 | if (expect_false (!ev_is_active (w))) |
3886 | return; |
3995 | return; |
3887 | |
3996 | |
… | |
… | |
3901 | } |
4010 | } |
3902 | #endif |
4011 | #endif |
3903 | |
4012 | |
3904 | #if EV_PREPARE_ENABLE |
4013 | #if EV_PREPARE_ENABLE |
3905 | void |
4014 | void |
3906 | ev_prepare_start (EV_P_ ev_prepare *w) |
4015 | ev_prepare_start (EV_P_ ev_prepare *w) EV_THROW |
3907 | { |
4016 | { |
3908 | if (expect_false (ev_is_active (w))) |
4017 | if (expect_false (ev_is_active (w))) |
3909 | return; |
4018 | return; |
3910 | |
4019 | |
3911 | EV_FREQUENT_CHECK; |
4020 | EV_FREQUENT_CHECK; |
… | |
… | |
3916 | |
4025 | |
3917 | EV_FREQUENT_CHECK; |
4026 | EV_FREQUENT_CHECK; |
3918 | } |
4027 | } |
3919 | |
4028 | |
3920 | void |
4029 | void |
3921 | ev_prepare_stop (EV_P_ ev_prepare *w) |
4030 | ev_prepare_stop (EV_P_ ev_prepare *w) EV_THROW |
3922 | { |
4031 | { |
3923 | clear_pending (EV_A_ (W)w); |
4032 | clear_pending (EV_A_ (W)w); |
3924 | if (expect_false (!ev_is_active (w))) |
4033 | if (expect_false (!ev_is_active (w))) |
3925 | return; |
4034 | return; |
3926 | |
4035 | |
… | |
… | |
3939 | } |
4048 | } |
3940 | #endif |
4049 | #endif |
3941 | |
4050 | |
3942 | #if EV_CHECK_ENABLE |
4051 | #if EV_CHECK_ENABLE |
3943 | void |
4052 | void |
3944 | ev_check_start (EV_P_ ev_check *w) |
4053 | ev_check_start (EV_P_ ev_check *w) EV_THROW |
3945 | { |
4054 | { |
3946 | if (expect_false (ev_is_active (w))) |
4055 | if (expect_false (ev_is_active (w))) |
3947 | return; |
4056 | return; |
3948 | |
4057 | |
3949 | EV_FREQUENT_CHECK; |
4058 | EV_FREQUENT_CHECK; |
… | |
… | |
3954 | |
4063 | |
3955 | EV_FREQUENT_CHECK; |
4064 | EV_FREQUENT_CHECK; |
3956 | } |
4065 | } |
3957 | |
4066 | |
3958 | void |
4067 | void |
3959 | ev_check_stop (EV_P_ ev_check *w) |
4068 | ev_check_stop (EV_P_ ev_check *w) EV_THROW |
3960 | { |
4069 | { |
3961 | clear_pending (EV_A_ (W)w); |
4070 | clear_pending (EV_A_ (W)w); |
3962 | if (expect_false (!ev_is_active (w))) |
4071 | if (expect_false (!ev_is_active (w))) |
3963 | return; |
4072 | return; |
3964 | |
4073 | |
… | |
… | |
3977 | } |
4086 | } |
3978 | #endif |
4087 | #endif |
3979 | |
4088 | |
3980 | #if EV_EMBED_ENABLE |
4089 | #if EV_EMBED_ENABLE |
3981 | void noinline |
4090 | void noinline |
3982 | ev_embed_sweep (EV_P_ ev_embed *w) |
4091 | ev_embed_sweep (EV_P_ ev_embed *w) EV_THROW |
3983 | { |
4092 | { |
3984 | ev_run (w->other, EVRUN_NOWAIT); |
4093 | ev_run (w->other, EVRUN_NOWAIT); |
3985 | } |
4094 | } |
3986 | |
4095 | |
3987 | static void |
4096 | static void |
… | |
… | |
4035 | ev_idle_stop (EV_A_ idle); |
4144 | ev_idle_stop (EV_A_ idle); |
4036 | } |
4145 | } |
4037 | #endif |
4146 | #endif |
4038 | |
4147 | |
4039 | void |
4148 | void |
4040 | ev_embed_start (EV_P_ ev_embed *w) |
4149 | ev_embed_start (EV_P_ ev_embed *w) EV_THROW |
4041 | { |
4150 | { |
4042 | if (expect_false (ev_is_active (w))) |
4151 | if (expect_false (ev_is_active (w))) |
4043 | return; |
4152 | return; |
4044 | |
4153 | |
4045 | { |
4154 | { |
… | |
… | |
4066 | |
4175 | |
4067 | EV_FREQUENT_CHECK; |
4176 | EV_FREQUENT_CHECK; |
4068 | } |
4177 | } |
4069 | |
4178 | |
4070 | void |
4179 | void |
4071 | ev_embed_stop (EV_P_ ev_embed *w) |
4180 | ev_embed_stop (EV_P_ ev_embed *w) EV_THROW |
4072 | { |
4181 | { |
4073 | clear_pending (EV_A_ (W)w); |
4182 | clear_pending (EV_A_ (W)w); |
4074 | if (expect_false (!ev_is_active (w))) |
4183 | if (expect_false (!ev_is_active (w))) |
4075 | return; |
4184 | return; |
4076 | |
4185 | |
… | |
… | |
4086 | } |
4195 | } |
4087 | #endif |
4196 | #endif |
4088 | |
4197 | |
4089 | #if EV_FORK_ENABLE |
4198 | #if EV_FORK_ENABLE |
4090 | void |
4199 | void |
4091 | ev_fork_start (EV_P_ ev_fork *w) |
4200 | ev_fork_start (EV_P_ ev_fork *w) EV_THROW |
4092 | { |
4201 | { |
4093 | if (expect_false (ev_is_active (w))) |
4202 | if (expect_false (ev_is_active (w))) |
4094 | return; |
4203 | return; |
4095 | |
4204 | |
4096 | EV_FREQUENT_CHECK; |
4205 | EV_FREQUENT_CHECK; |
… | |
… | |
4101 | |
4210 | |
4102 | EV_FREQUENT_CHECK; |
4211 | EV_FREQUENT_CHECK; |
4103 | } |
4212 | } |
4104 | |
4213 | |
4105 | void |
4214 | void |
4106 | ev_fork_stop (EV_P_ ev_fork *w) |
4215 | ev_fork_stop (EV_P_ ev_fork *w) EV_THROW |
4107 | { |
4216 | { |
4108 | clear_pending (EV_A_ (W)w); |
4217 | clear_pending (EV_A_ (W)w); |
4109 | if (expect_false (!ev_is_active (w))) |
4218 | if (expect_false (!ev_is_active (w))) |
4110 | return; |
4219 | return; |
4111 | |
4220 | |
… | |
… | |
4124 | } |
4233 | } |
4125 | #endif |
4234 | #endif |
4126 | |
4235 | |
4127 | #if EV_CLEANUP_ENABLE |
4236 | #if EV_CLEANUP_ENABLE |
4128 | void |
4237 | void |
4129 | ev_cleanup_start (EV_P_ ev_cleanup *w) |
4238 | ev_cleanup_start (EV_P_ ev_cleanup *w) EV_THROW |
4130 | { |
4239 | { |
4131 | if (expect_false (ev_is_active (w))) |
4240 | if (expect_false (ev_is_active (w))) |
4132 | return; |
4241 | return; |
4133 | |
4242 | |
4134 | EV_FREQUENT_CHECK; |
4243 | EV_FREQUENT_CHECK; |
… | |
… | |
4141 | ev_unref (EV_A); |
4250 | ev_unref (EV_A); |
4142 | EV_FREQUENT_CHECK; |
4251 | EV_FREQUENT_CHECK; |
4143 | } |
4252 | } |
4144 | |
4253 | |
4145 | void |
4254 | void |
4146 | ev_cleanup_stop (EV_P_ ev_cleanup *w) |
4255 | ev_cleanup_stop (EV_P_ ev_cleanup *w) EV_THROW |
4147 | { |
4256 | { |
4148 | clear_pending (EV_A_ (W)w); |
4257 | clear_pending (EV_A_ (W)w); |
4149 | if (expect_false (!ev_is_active (w))) |
4258 | if (expect_false (!ev_is_active (w))) |
4150 | return; |
4259 | return; |
4151 | |
4260 | |
… | |
… | |
4165 | } |
4274 | } |
4166 | #endif |
4275 | #endif |
4167 | |
4276 | |
4168 | #if EV_ASYNC_ENABLE |
4277 | #if EV_ASYNC_ENABLE |
4169 | void |
4278 | void |
4170 | ev_async_start (EV_P_ ev_async *w) |
4279 | ev_async_start (EV_P_ ev_async *w) EV_THROW |
4171 | { |
4280 | { |
4172 | if (expect_false (ev_is_active (w))) |
4281 | if (expect_false (ev_is_active (w))) |
4173 | return; |
4282 | return; |
4174 | |
4283 | |
4175 | w->sent = 0; |
4284 | w->sent = 0; |
… | |
… | |
4184 | |
4293 | |
4185 | EV_FREQUENT_CHECK; |
4294 | EV_FREQUENT_CHECK; |
4186 | } |
4295 | } |
4187 | |
4296 | |
4188 | void |
4297 | void |
4189 | ev_async_stop (EV_P_ ev_async *w) |
4298 | ev_async_stop (EV_P_ ev_async *w) EV_THROW |
4190 | { |
4299 | { |
4191 | clear_pending (EV_A_ (W)w); |
4300 | clear_pending (EV_A_ (W)w); |
4192 | if (expect_false (!ev_is_active (w))) |
4301 | if (expect_false (!ev_is_active (w))) |
4193 | return; |
4302 | return; |
4194 | |
4303 | |
… | |
… | |
4205 | |
4314 | |
4206 | EV_FREQUENT_CHECK; |
4315 | EV_FREQUENT_CHECK; |
4207 | } |
4316 | } |
4208 | |
4317 | |
4209 | void |
4318 | void |
4210 | ev_async_send (EV_P_ ev_async *w) |
4319 | ev_async_send (EV_P_ ev_async *w) EV_THROW |
4211 | { |
4320 | { |
4212 | w->sent = 1; |
4321 | w->sent = 1; |
4213 | evpipe_write (EV_A_ &async_pending); |
4322 | evpipe_write (EV_A_ &async_pending); |
4214 | } |
4323 | } |
4215 | #endif |
4324 | #endif |
… | |
… | |
4252 | |
4361 | |
4253 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4362 | once_cb (EV_A_ once, revents | ev_clear_pending (EV_A_ &once->io)); |
4254 | } |
4363 | } |
4255 | |
4364 | |
4256 | void |
4365 | void |
4257 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) |
4366 | ev_once (EV_P_ int fd, int events, ev_tstamp timeout, void (*cb)(int revents, void *arg), void *arg) EV_THROW |
4258 | { |
4367 | { |
4259 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4368 | struct ev_once *once = (struct ev_once *)ev_malloc (sizeof (struct ev_once)); |
4260 | |
4369 | |
4261 | if (expect_false (!once)) |
4370 | if (expect_false (!once)) |
4262 | { |
4371 | { |
… | |
… | |
4284 | |
4393 | |
4285 | /*****************************************************************************/ |
4394 | /*****************************************************************************/ |
4286 | |
4395 | |
4287 | #if EV_WALK_ENABLE |
4396 | #if EV_WALK_ENABLE |
4288 | void ecb_cold |
4397 | void ecb_cold |
4289 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) |
4398 | ev_walk (EV_P_ int types, void (*cb)(EV_P_ int type, void *w)) EV_THROW |
4290 | { |
4399 | { |
4291 | int i, j; |
4400 | int i, j; |
4292 | ev_watcher_list *wl, *wn; |
4401 | ev_watcher_list *wl, *wn; |
4293 | |
4402 | |
4294 | if (types & (EV_IO | EV_EMBED)) |
4403 | if (types & (EV_IO | EV_EMBED)) |
… | |
… | |
4400 | |
4509 | |
4401 | #if EV_MULTIPLICITY |
4510 | #if EV_MULTIPLICITY |
4402 | #include "ev_wrap.h" |
4511 | #include "ev_wrap.h" |
4403 | #endif |
4512 | #endif |
4404 | |
4513 | |
4405 | EV_CPP(}) |
|
|
4406 | |
|
|