ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libev/ev.c
(Generate patch)

Comparing libev/ev.c (file contents):
Revision 1.380 by root, Mon Jun 27 19:20:01 2011 UTC vs.
Revision 1.391 by root, Thu Aug 4 13:57:16 2011 UTC

464#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */ 464#define MAX_BLOCKTIME 59.743 /* never wait longer than this time (to detect time jumps) */
465 465
466#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0) 466#define EV_TV_SET(tv,t) do { tv.tv_sec = (long)t; tv.tv_usec = (long)((t - tv.tv_sec) * 1e6); } while (0)
467#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0) 467#define EV_TS_SET(ts,t) do { ts.tv_sec = (long)t; ts.tv_nsec = (long)((t - ts.tv_sec) * 1e9); } while (0)
468 468
469/* the following are taken from libecb */ 469/* the following is ecb.h embedded into libev - use update_ev_c to update from an external copy */
470/* ecb.h start */ 470/* ECB.H BEGIN */
471/*
472 * libecb - http://software.schmorp.de/pkg/libecb
473 *
474 * Copyright (©) 2009-2011 Marc Alexander Lehmann <libecb@schmorp.de>
475 * Copyright (©) 2011 Emanuele Giaquinta
476 * All rights reserved.
477 *
478 * Redistribution and use in source and binary forms, with or without modifica-
479 * tion, are permitted provided that the following conditions are met:
480 *
481 * 1. Redistributions of source code must retain the above copyright notice,
482 * this list of conditions and the following disclaimer.
483 *
484 * 2. Redistributions in binary form must reproduce the above copyright
485 * notice, this list of conditions and the following disclaimer in the
486 * documentation and/or other materials provided with the distribution.
487 *
488 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
489 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MER-
490 * CHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
491 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPE-
492 * CIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
493 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
494 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
495 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTH-
496 * ERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
497 * OF THE POSSIBILITY OF SUCH DAMAGE.
498 */
499
500#ifndef ECB_H
501#define ECB_H
502
503#ifdef _WIN32
504 typedef signed char int8_t;
505 typedef unsigned char uint8_t;
506 typedef signed short int16_t;
507 typedef unsigned short uint16_t;
508 typedef signed int int32_t;
509 typedef unsigned int uint32_t;
510 #if __GNUC__
511 typedef signed long long int64_t;
512 typedef unsigned long long uint64_t;
513 #else /* _MSC_VER || __BORLANDC__ */
514 typedef signed __int64 int64_t;
515 typedef unsigned __int64 uint64_t;
516 #endif
517#else
518 #include <inttypes.h>
519#endif
471 520
472/* many compilers define _GNUC_ to some versions but then only implement 521/* many compilers define _GNUC_ to some versions but then only implement
473 * what their idiot authors think are the "more important" extensions, 522 * what their idiot authors think are the "more important" extensions,
474 * causing enourmous grief in return for some better fake benchmark numbers. 523 * causing enormous grief in return for some better fake benchmark numbers.
475 * or so. 524 * or so.
476 * we try to detect these and simply assume they are not gcc - if they have 525 * we try to detect these and simply assume they are not gcc - if they have
477 * an issue with that they should have done it right in the first place. 526 * an issue with that they should have done it right in the first place.
478 */ 527 */
479#ifndef ECB_GCC_VERSION 528#ifndef ECB_GCC_VERSION
482 #else 531 #else
483 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor))) 532 #define ECB_GCC_VERSION(major,minor) (__GNUC__ > (major) || (__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)))
484 #endif 533 #endif
485#endif 534#endif
486 535
536/*****************************************************************************/
537
538/* 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 */
540
541#if ECB_NO_THREADS || ECB_NO_SMP
542 #define ECB_MEMORY_FENCE do { } while (0)
543 #define ECB_MEMORY_FENCE_ACQUIRE do { } while (0)
544 #define ECB_MEMORY_FENCE_RELEASE do { } while (0)
545#endif
546
547#ifndef ECB_MEMORY_FENCE
548 #if ECB_GCC_VERSION(2,5)
549 #if __x86
550 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory")
551 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE /* non-lock xchg might be enough */
552 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
553 #elif __amd64
554 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mfence" : : : "memory")
555 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("lfence" : : : "memory")
556 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("sfence") /* play safe - not needed in any current cpu */
557 #endif
558 #endif
559#endif
560
561#ifndef ECB_MEMORY_FENCE
562 #if ECB_GCC_VERSION(4,4)
563 #define ECB_MEMORY_FENCE __sync_synchronize ()
564 #define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); })
565 #define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); })
566 #elif _MSC_VER >= 1400 /* VC++ 2005 */
567 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
568 #define ECB_MEMORY_FENCE _ReadWriteBarrier ()
569 #define ECB_MEMORY_FENCE_ACQUIRE _ReadWriteBarrier () /* according to msdn, _ReadBarrier is not a load fence */
570 #define ECB_MEMORY_FENCE_RELEASE _WriteBarrier ()
571 #elif defined(_WIN32)
572 #include <WinNT.h>
573 #define ECB_MEMORY_FENCE MemoryBarrier () /* actually just xchg on x86... scary */
574 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
575 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
576 #endif
577#endif
578
579#ifndef ECB_MEMORY_FENCE
580 /*
581 * if you get undefined symbol references to pthread_mutex_lock,
582 * or failure to find pthread.h, then you should implement
583 * the ECB_MEMORY_FENCE operations for your cpu/compiler
584 * OR provide pthread.h and link against the posix thread library
585 * of your system.
586 */
587 #include <pthread.h>
588 #define ECB_NEEDS_PTHREADS 1
589 #define ECB_MEMORY_FENCE_NEEDS_PTHREADS 1
590
591 static pthread_mutex_t ecb_mf_lock = PTHREAD_MUTEX_INITIALIZER;
592 #define ECB_MEMORY_FENCE do { pthread_mutex_lock (&ecb_mf_lock); pthread_mutex_unlock (&ecb_mf_lock); } while (0)
593 #define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
594 #define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
595#endif
596
597/*****************************************************************************/
598
599#define ECB_C99 (__STDC_VERSION__ >= 199901L)
600
487#if __cplusplus 601#if __cplusplus
488 #define ecb_inline static inline 602 #define ecb_inline static inline
489#elif ECB_GCC_VERSION(2,5) 603#elif ECB_GCC_VERSION(2,5)
490 #define ecb_inline static __inline__ 604 #define ecb_inline static __inline__
491#elif ECB_C99 605#elif ECB_C99
492 #define ecb_inline static inline 606 #define ecb_inline static inline
493#else 607#else
494 #define ecb_inline static 608 #define ecb_inline static
495#endif 609#endif
610
611#if ECB_GCC_VERSION(3,3)
612 #define ecb_restrict __restrict__
613#elif ECB_C99
614 #define ecb_restrict restrict
615#else
616 #define ecb_restrict
617#endif
618
619typedef int ecb_bool;
620
621#define ECB_CONCAT_(a, b) a ## b
622#define ECB_CONCAT(a, b) ECB_CONCAT_(a, b)
623#define ECB_STRINGIFY_(a) # a
624#define ECB_STRINGIFY(a) ECB_STRINGIFY_(a)
625
626#define ecb_function_ ecb_inline
496 627
497#if ECB_GCC_VERSION(3,1) 628#if ECB_GCC_VERSION(3,1)
498 #define ecb_attribute(attrlist) __attribute__(attrlist) 629 #define ecb_attribute(attrlist) __attribute__(attrlist)
499 #define ecb_is_constant(expr) __builtin_constant_p (expr) 630 #define ecb_is_constant(expr) __builtin_constant_p (expr)
500 #define ecb_expect(expr,value) __builtin_expect ((expr),(value)) 631 #define ecb_expect(expr,value) __builtin_expect ((expr),(value))
504 #define ecb_is_constant(expr) 0 635 #define ecb_is_constant(expr) 0
505 #define ecb_expect(expr,value) (expr) 636 #define ecb_expect(expr,value) (expr)
506 #define ecb_prefetch(addr,rw,locality) 637 #define ecb_prefetch(addr,rw,locality)
507#endif 638#endif
508 639
640/* no emulation for ecb_decltype */
641#if ECB_GCC_VERSION(4,5)
642 #define ecb_decltype(x) __decltype(x)
643#elif ECB_GCC_VERSION(3,0)
644 #define ecb_decltype(x) __typeof(x)
645#endif
646
509#define ecb_noinline ecb_attribute ((__noinline__)) 647#define ecb_noinline ecb_attribute ((__noinline__))
510#define ecb_noreturn ecb_attribute ((__noreturn__)) 648#define ecb_noreturn ecb_attribute ((__noreturn__))
511#define ecb_unused ecb_attribute ((__unused__)) 649#define ecb_unused ecb_attribute ((__unused__))
512#define ecb_const ecb_attribute ((__const__)) 650#define ecb_const ecb_attribute ((__const__))
513#define ecb_pure ecb_attribute ((__pure__)) 651#define ecb_pure ecb_attribute ((__pure__))
525/* put around conditional expressions if you are very sure that the */ 663/* put around conditional expressions if you are very sure that the */
526/* expression is mostly true or mostly false. note that these return */ 664/* expression is mostly true or mostly false. note that these return */
527/* booleans, not the expression. */ 665/* booleans, not the expression. */
528#define ecb_expect_false(expr) ecb_expect (!!(expr), 0) 666#define ecb_expect_false(expr) ecb_expect (!!(expr), 0)
529#define ecb_expect_true(expr) ecb_expect (!!(expr), 1) 667#define ecb_expect_true(expr) ecb_expect (!!(expr), 1)
530/* ecb.h end */ 668/* for compatibility to the rest of the world */
669#define ecb_likely(expr) ecb_expect_true (expr)
670#define ecb_unlikely(expr) ecb_expect_false (expr)
671
672/* count trailing zero bits and count # of one bits */
673#if ECB_GCC_VERSION(3,4)
674 /* we assume int == 32 bit, long == 32 or 64 bit and long long == 64 bit */
675 #define ecb_ld32(x) (__builtin_clz (x) ^ 31)
676 #define ecb_ld64(x) (__builtin_clzll (x) ^ 63)
677 #define ecb_ctz32(x) __builtin_ctz (x)
678 #define ecb_ctz64(x) __builtin_ctzll (x)
679 #define ecb_popcount32(x) __builtin_popcount (x)
680 /* no popcountll */
681#else
682 ecb_function_ int ecb_ctz32 (uint32_t x) ecb_const;
683 ecb_function_ int
684 ecb_ctz32 (uint32_t x)
685 {
686 int r = 0;
687
688 x &= ~x + 1; /* this isolates the lowest bit */
689
690#if ECB_branchless_on_i386
691 r += !!(x & 0xaaaaaaaa) << 0;
692 r += !!(x & 0xcccccccc) << 1;
693 r += !!(x & 0xf0f0f0f0) << 2;
694 r += !!(x & 0xff00ff00) << 3;
695 r += !!(x & 0xffff0000) << 4;
696#else
697 if (x & 0xaaaaaaaa) r += 1;
698 if (x & 0xcccccccc) r += 2;
699 if (x & 0xf0f0f0f0) r += 4;
700 if (x & 0xff00ff00) r += 8;
701 if (x & 0xffff0000) r += 16;
702#endif
703
704 return r;
705 }
706
707 ecb_function_ int ecb_ctz64 (uint64_t x) ecb_const;
708 ecb_function_ int
709 ecb_ctz64 (uint64_t x)
710 {
711 int shift = x & 0xffffffffU ? 0 : 32;
712 return ecb_ctz32 (x >> shift) + shift;
713 }
714
715 ecb_function_ int ecb_popcount32 (uint32_t x) ecb_const;
716 ecb_function_ int
717 ecb_popcount32 (uint32_t x)
718 {
719 x -= (x >> 1) & 0x55555555;
720 x = ((x >> 2) & 0x33333333) + (x & 0x33333333);
721 x = ((x >> 4) + x) & 0x0f0f0f0f;
722 x *= 0x01010101;
723
724 return x >> 24;
725 }
726
727 ecb_function_ int ecb_ld32 (uint32_t x) ecb_const;
728 ecb_function_ int ecb_ld32 (uint32_t x)
729 {
730 int r = 0;
731
732 if (x >> 16) { x >>= 16; r += 16; }
733 if (x >> 8) { x >>= 8; r += 8; }
734 if (x >> 4) { x >>= 4; r += 4; }
735 if (x >> 2) { x >>= 2; r += 2; }
736 if (x >> 1) { r += 1; }
737
738 return r;
739 }
740
741 ecb_function_ int ecb_ld64 (uint64_t x) ecb_const;
742 ecb_function_ int ecb_ld64 (uint64_t x)
743 {
744 int r = 0;
745
746 if (x >> 32) { x >>= 32; r += 32; }
747
748 return r + ecb_ld32 (x);
749 }
750#endif
751
752/* popcount64 is only available on 64 bit cpus as gcc builtin */
753/* so for this version we are lazy */
754ecb_function_ int ecb_popcount64 (uint64_t x) ecb_const;
755ecb_function_ int
756ecb_popcount64 (uint64_t x)
757{
758 return ecb_popcount32 (x) + ecb_popcount32 (x >> 32);
759}
760
761ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count) ecb_const;
762ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count) ecb_const;
763ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count) ecb_const;
764ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count) ecb_const;
765ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) ecb_const;
766ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) ecb_const;
767ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) ecb_const;
768ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) ecb_const;
769
770ecb_inline uint8_t ecb_rotl8 (uint8_t x, unsigned int count) { return (x >> ( 8 - count)) | (x << count); }
771ecb_inline uint8_t ecb_rotr8 (uint8_t x, unsigned int count) { return (x << ( 8 - count)) | (x >> count); }
772ecb_inline uint16_t ecb_rotl16 (uint16_t x, unsigned int count) { return (x >> (16 - count)) | (x << count); }
773ecb_inline uint16_t ecb_rotr16 (uint16_t x, unsigned int count) { return (x << (16 - count)) | (x >> count); }
774ecb_inline uint32_t ecb_rotl32 (uint32_t x, unsigned int count) { return (x >> (32 - count)) | (x << count); }
775ecb_inline uint32_t ecb_rotr32 (uint32_t x, unsigned int count) { return (x << (32 - count)) | (x >> count); }
776ecb_inline uint64_t ecb_rotl64 (uint64_t x, unsigned int count) { return (x >> (64 - count)) | (x << count); }
777ecb_inline uint64_t ecb_rotr64 (uint64_t x, unsigned int count) { return (x << (64 - count)) | (x >> count); }
778
779#if ECB_GCC_VERSION(4,3)
780 #define ecb_bswap16(x) (__builtin_bswap32 (x) >> 16)
781 #define ecb_bswap32(x) __builtin_bswap32 (x)
782 #define ecb_bswap64(x) __builtin_bswap64 (x)
783#else
784 ecb_function_ uint16_t ecb_bswap16 (uint16_t x) ecb_const;
785 ecb_function_ uint16_t
786 ecb_bswap16 (uint16_t x)
787 {
788 return ecb_rotl16 (x, 8);
789 }
790
791 ecb_function_ uint32_t ecb_bswap32 (uint32_t x) ecb_const;
792 ecb_function_ uint32_t
793 ecb_bswap32 (uint32_t x)
794 {
795 return (((uint32_t)ecb_bswap16 (x)) << 16) | ecb_bswap16 (x >> 16);
796 }
797
798 ecb_function_ uint64_t ecb_bswap64 (uint64_t x) ecb_const;
799 ecb_function_ uint64_t
800 ecb_bswap64 (uint64_t x)
801 {
802 return (((uint64_t)ecb_bswap32 (x)) << 32) | ecb_bswap32 (x >> 32);
803 }
804#endif
805
806#if ECB_GCC_VERSION(4,5)
807 #define ecb_unreachable() __builtin_unreachable ()
808#else
809 /* this seems to work fine, but gcc always emits a warning for it :/ */
810 ecb_function_ void ecb_unreachable (void) ecb_noreturn;
811 ecb_function_ void ecb_unreachable (void) { }
812#endif
813
814/* try to tell the compiler that some condition is definitely true */
815#define ecb_assume(cond) do { if (!(cond)) ecb_unreachable (); } while (0)
816
817ecb_function_ unsigned char ecb_byteorder_helper (void) ecb_const;
818ecb_function_ unsigned char
819ecb_byteorder_helper (void)
820{
821 const uint32_t u = 0x11223344;
822 return *(unsigned char *)&u;
823}
824
825ecb_function_ ecb_bool ecb_big_endian (void) ecb_const;
826ecb_function_ ecb_bool ecb_big_endian (void) { return ecb_byteorder_helper () == 0x11; }
827ecb_function_ ecb_bool ecb_little_endian (void) ecb_const;
828ecb_function_ ecb_bool ecb_little_endian (void) { return ecb_byteorder_helper () == 0x44; }
829
830#if ECB_GCC_VERSION(3,0) || ECB_C99
831 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
832#else
833 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))
834#endif
835
836#if ecb_cplusplus_does_not_suck
837 /* does not work for local types (http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2657.htm) */
838 template<typename T, int N>
839 static inline int ecb_array_length (const T (&arr)[N])
840 {
841 return N;
842 }
843#else
844 #define ecb_array_length(name) (sizeof (name) / sizeof (name [0]))
845#endif
846
847#endif
848
849/* ECB.H END */
531 850
532#define expect_false(cond) ecb_expect_false (cond) 851#define expect_false(cond) ecb_expect_false (cond)
533#define expect_true(cond) ecb_expect_true (cond) 852#define expect_true(cond) ecb_expect_true (cond)
534#define noinline ecb_noinline 853#define noinline ecb_noinline
535 854
964 memset ((void *)(base), 0, sizeof (*(base)) * (count)) 1283 memset ((void *)(base), 0, sizeof (*(base)) * (count))
965 1284
966#define array_needsize(type,base,cur,cnt,init) \ 1285#define array_needsize(type,base,cur,cnt,init) \
967 if (expect_false ((cnt) > (cur))) \ 1286 if (expect_false ((cnt) > (cur))) \
968 { \ 1287 { \
969 int ocur_ = (cur); \ 1288 int ecb_unused ocur_ = (cur); \
970 (base) = (type *)array_realloc \ 1289 (base) = (type *)array_realloc \
971 (sizeof (type), (base), &(cur), (cnt)); \ 1290 (sizeof (type), (base), &(cur), (cnt)); \
972 init ((base) + (ocur_), (cur) - ocur_); \ 1291 init ((base) + (ocur_), (cur) - ocur_); \
973 } 1292 }
974 1293
1420} 1739}
1421 1740
1422inline_speed void 1741inline_speed void
1423evpipe_write (EV_P_ EV_ATOMIC_T *flag) 1742evpipe_write (EV_P_ EV_ATOMIC_T *flag)
1424{ 1743{
1425 if (!*flag) 1744 if (expect_true (*flag))
1426 { 1745 return;
1746
1427 *flag = 1; 1747 *flag = 1;
1428 1748
1749 ECB_MEMORY_FENCE_RELEASE; /* make sure flag is visible before the wakeup */
1750
1429 pipe_write_skipped = 1; 1751 pipe_write_skipped = 1;
1430 1752
1753 ECB_MEMORY_FENCE; /* make sure pipe_write_skipped is visible before we check pipe_write_wanted */
1754
1431 if (pipe_write_wanted) 1755 if (pipe_write_wanted)
1756 {
1757 int old_errno;
1758
1759 pipe_write_skipped = 0; /* just an optimsiation, no fence needed */
1760
1761 old_errno = errno; /* save errno because write will clobber it */
1762
1763#if EV_USE_EVENTFD
1764 if (evfd >= 0)
1432 { 1765 {
1433 int old_errno;
1434
1435 pipe_write_skipped = 0;
1436
1437 old_errno = errno; /* save errno because write will clobber it */
1438
1439#if EV_USE_EVENTFD
1440 if (evfd >= 0)
1441 {
1442 uint64_t counter = 1; 1766 uint64_t counter = 1;
1443 write (evfd, &counter, sizeof (uint64_t)); 1767 write (evfd, &counter, sizeof (uint64_t));
1444 }
1445 else
1446#endif
1447 {
1448 /* win32 people keep sending patches that change this write() to send() */
1449 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1450 /* so when you think this write should be a send instead, please find out */
1451 /* where your send() is from - it's definitely not the microsoft send, and */
1452 /* tell me. thank you. */
1453 write (evpipe [1], &(evpipe [1]), 1);
1454 }
1455
1456 errno = old_errno;
1457 } 1768 }
1769 else
1770#endif
1771 {
1772 /* win32 people keep sending patches that change this write() to send() */
1773 /* and then run away. but send() is wrong, it wants a socket handle on win32 */
1774 /* so when you think this write should be a send instead, please find out */
1775 /* where your send() is from - it's definitely not the microsoft send, and */
1776 /* tell me. thank you. */
1777 write (evpipe [1], &(evpipe [1]), 1);
1778 }
1779
1780 errno = old_errno;
1458 } 1781 }
1459} 1782}
1460 1783
1461/* called whenever the libev signal pipe */ 1784/* called whenever the libev signal pipe */
1462/* got some events (signal, async) */ 1785/* got some events (signal, async) */
1520 1843
1521 if (!EV_A) 1844 if (!EV_A)
1522 return; 1845 return;
1523#endif 1846#endif
1524 1847
1525 evpipe_init (EV_A); 1848 if (!ev_active (&pipe_w))
1849 return;
1526 1850
1527 signals [signum - 1].pending = 1; 1851 signals [signum - 1].pending = 1;
1528 evpipe_write (EV_A_ &sig_pending); 1852 evpipe_write (EV_A_ &sig_pending);
1529} 1853}
1530 1854
2572 time_update (EV_A_ 1e100); 2896 time_update (EV_A_ 1e100);
2573 2897
2574 /* from now on, we want a pipe-wake-up */ 2898 /* from now on, we want a pipe-wake-up */
2575 pipe_write_wanted = 1; 2899 pipe_write_wanted = 1;
2576 2900
2901 ECB_MEMORY_FENCE; /* make sure pipe_write_wanted is visible before we check for potential skips */
2902
2577 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped))) 2903 if (expect_true (!(flags & EVRUN_NOWAIT || idleall || !activecnt || pipe_write_skipped)))
2578 { 2904 {
2579 waittime = MAX_BLOCKTIME; 2905 waittime = MAX_BLOCKTIME;
2580 2906
2581 if (timercnt) 2907 if (timercnt)
2622#endif 2948#endif
2623 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ 2949 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2624 backend_poll (EV_A_ waittime); 2950 backend_poll (EV_A_ waittime);
2625 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 2951 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2626 2952
2627 pipe_write_wanted = 0; 2953 pipe_write_wanted = 0; /* just an optimsiation, no fence needed */
2628 2954
2629 if (pipe_write_skipped) 2955 if (pipe_write_skipped)
2630 { 2956 {
2631 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 2957 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
2632 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 2958 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
3982 cb (EV_A_ EV_PERIODIC, ANHE_w (periodics [i])); 4308 cb (EV_A_ EV_PERIODIC, ANHE_w (periodics [i]));
3983#endif 4309#endif
3984 4310
3985#if EV_IDLE_ENABLE 4311#if EV_IDLE_ENABLE
3986 if (types & EV_IDLE) 4312 if (types & EV_IDLE)
3987 for (j = NUMPRI; i--; ) 4313 for (j = NUMPRI; j--; )
3988 for (i = idlecnt [j]; i--; ) 4314 for (i = idlecnt [j]; i--; )
3989 cb (EV_A_ EV_IDLE, idles [j][i]); 4315 cb (EV_A_ EV_IDLE, idles [j][i]);
3990#endif 4316#endif
3991 4317
3992#if EV_FORK_ENABLE 4318#if EV_FORK_ENABLE

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines