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

Comparing libev/ev.c (file contents):
Revision 1.450 by root, Mon Oct 8 15:43:35 2012 UTC vs.
Revision 1.458 by root, Sun Oct 27 16:26:07 2013 UTC

357 357
358#ifndef EV_HEAP_CACHE_AT 358#ifndef EV_HEAP_CACHE_AT
359# define EV_HEAP_CACHE_AT EV_FEATURE_DATA 359# define EV_HEAP_CACHE_AT EV_FEATURE_DATA
360#endif 360#endif
361 361
362#ifdef ANDROID
363/* supposedly, android doesn't typedef fd_mask */
364# undef EV_USE_SELECT
365# define EV_USE_SELECT 0
366/* supposedly, we need to include syscall.h, not sys/syscall.h, so just disable */
367# undef EV_USE_CLOCK_SYSCALL
368# define EV_USE_CLOCK_SYSCALL 0
369#endif
370
371/* aix's poll.h seems to cause lots of trouble */
372#ifdef _AIX
373/* AIX has a completely broken poll.h header */
374# undef EV_USE_POLL
375# define EV_USE_POLL 0
376#endif
377
362/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */ 378/* on linux, we can use a (slow) syscall to avoid a dependency on pthread, */
363/* which makes programs even slower. might work on other unices, too. */ 379/* which makes programs even slower. might work on other unices, too. */
364#if EV_USE_CLOCK_SYSCALL 380#if EV_USE_CLOCK_SYSCALL
365# include <sys/syscall.h> 381# include <sys/syscall.h>
366# ifdef SYS_clock_gettime 382# ifdef SYS_clock_gettime
372# define EV_USE_CLOCK_SYSCALL 0 388# define EV_USE_CLOCK_SYSCALL 0
373# endif 389# endif
374#endif 390#endif
375 391
376/* this block fixes any misconfiguration where we know we run into trouble otherwise */ 392/* this block fixes any misconfiguration where we know we run into trouble otherwise */
377
378#ifdef _AIX
379/* AIX has a completely broken poll.h header */
380# undef EV_USE_POLL
381# define EV_USE_POLL 0
382#endif
383 393
384#ifndef CLOCK_MONOTONIC 394#ifndef CLOCK_MONOTONIC
385# undef EV_USE_MONOTONIC 395# undef EV_USE_MONOTONIC
386# define EV_USE_MONOTONIC 0 396# define EV_USE_MONOTONIC 0
387#endif 397#endif
505 515
506#ifndef ECB_H 516#ifndef ECB_H
507#define ECB_H 517#define ECB_H
508 518
509/* 16 bits major, 16 bits minor */ 519/* 16 bits major, 16 bits minor */
510#define ECB_VERSION 0x00010002 520#define ECB_VERSION 0x00010003
511 521
512#ifdef _WIN32 522#ifdef _WIN32
513 typedef signed char int8_t; 523 typedef signed char int8_t;
514 typedef unsigned char uint8_t; 524 typedef unsigned char uint8_t;
515 typedef signed short int16_t; 525 typedef signed short int16_t;
539 #else 549 #else
540 #define ECB_PTRSIZE 4 550 #define ECB_PTRSIZE 4
541 #endif 551 #endif
542#endif 552#endif
543 553
554/* work around x32 idiocy by defining proper macros */
555#if __x86_64 || _M_AMD64
556 #if _ILP32
557 #define ECB_AMD64_X32 1
558 #else
559 #define ECB_AMD64 1
560 #endif
561#endif
562
544/* many compilers define _GNUC_ to some versions but then only implement 563/* many compilers define _GNUC_ to some versions but then only implement
545 * what their idiot authors think are the "more important" extensions, 564 * what their idiot authors think are the "more important" extensions,
546 * causing enormous grief in return for some better fake benchmark numbers. 565 * causing enormous grief in return for some better fake benchmark numbers.
547 * or so. 566 * or so.
548 * we try to detect these and simply assume they are not gcc - if they have 567 * we try to detect these and simply assume they are not gcc - if they have
608 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory") 627 #define ECB_MEMORY_FENCE_ACQUIRE __asm__ __volatile__ ("membar #LoadStore | #LoadLoad" : : : "memory")
609 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore") 628 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("membar #LoadStore | #StoreStore")
610 #elif defined __s390__ || defined __s390x__ 629 #elif defined __s390__ || defined __s390x__
611 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory") 630 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("bcr 15,0" : : : "memory")
612 #elif defined __mips__ 631 #elif defined __mips__
632 /* GNU/Linux emulates sync on mips1 architectures, so we force its use */
633 /* anybody else who still uses mips1 is supposed to send in their version, with detection code. */
613 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("sync" : : : "memory") 634 #define ECB_MEMORY_FENCE __asm__ __volatile__ (".set mips2; sync; .set mips0" : : : "memory")
614 #elif defined __alpha__ 635 #elif defined __alpha__
615 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory") 636 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mb" : : : "memory")
616 #elif defined __hppa__ 637 #elif defined __hppa__
617 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory") 638 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
618 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("") 639 #define ECB_MEMORY_FENCE_RELEASE __asm__ __volatile__ ("")
619 #elif defined __ia64__ 640 #elif defined __ia64__
620 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory") 641 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("mf" : : : "memory")
642 #elif defined __m68k__
643 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
644 #elif defined __m88k__
645 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("tb1 0,%%r0,128" : : : "memory")
646 #elif defined __sh__
647 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("" : : : "memory")
621 #endif 648 #endif
622 #endif 649 #endif
623#endif 650#endif
624 651
625#ifndef ECB_MEMORY_FENCE 652#ifndef ECB_MEMORY_FENCE
1032 || defined __s390__ || defined __s390x__ \ 1059 || defined __s390__ || defined __s390x__ \
1033 || defined __mips__ \ 1060 || defined __mips__ \
1034 || defined __alpha__ \ 1061 || defined __alpha__ \
1035 || defined __hppa__ \ 1062 || defined __hppa__ \
1036 || defined __ia64__ \ 1063 || defined __ia64__ \
1064 || defined __m68k__ \
1065 || defined __m88k__ \
1066 || defined __sh__ \
1037 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64 1067 || defined _M_IX86 || defined _M_AMD64 || defined _M_IA64
1038 #define ECB_STDFP 1 1068 #define ECB_STDFP 1
1039 #include <string.h> /* for memcpy */ 1069 #include <string.h> /* for memcpy */
1040#else 1070#else
1041 #define ECB_STDFP 0 1071 #define ECB_STDFP 0
1042 #include <math.h> /* for frexp*, ldexp* */
1043#endif 1072#endif
1044 1073
1045#ifndef ECB_NO_LIBM 1074#ifndef ECB_NO_LIBM
1075
1076 #include <math.h> /* for frexp*, ldexp*, INFINITY, NAN */
1077
1078 #ifdef NEN
1079 #define ECB_NAN NAN
1080 #else
1081 #define ECB_NAN INFINITY
1082 #endif
1083
1084 /* converts an ieee half/binary16 to a float */
1085 ecb_function_ float ecb_binary16_to_float (uint16_t x) ecb_const;
1086 ecb_function_ float
1087 ecb_binary16_to_float (uint16_t x)
1088 {
1089 int e = (x >> 10) & 0x1f;
1090 int m = x & 0x3ff;
1091 float r;
1092
1093 if (!e ) r = ldexpf (m , -24);
1094 else if (e != 31) r = ldexpf (m + 0x400, e - 25);
1095 else if (m ) r = ECB_NAN;
1096 else r = INFINITY;
1097
1098 return x & 0x8000 ? -r : r;
1099 }
1046 1100
1047 /* convert a float to ieee single/binary32 */ 1101 /* convert a float to ieee single/binary32 */
1048 ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const; 1102 ecb_function_ uint32_t ecb_float_to_binary32 (float x) ecb_const;
1049 ecb_function_ uint32_t 1103 ecb_function_ uint32_t
1050 ecb_float_to_binary32 (float x) 1104 ecb_float_to_binary32 (float x)
2085 ev_syserr ("(libev) error creating signal/async pipe"); 2139 ev_syserr ("(libev) error creating signal/async pipe");
2086 2140
2087 fd_intern (fds [0]); 2141 fd_intern (fds [0]);
2088 } 2142 }
2089 2143
2090 fd_intern (fds [1]);
2091
2092 evpipe [0] = fds [0]; 2144 evpipe [0] = fds [0];
2093 2145
2094 if (evpipe [1] < 0) 2146 if (evpipe [1] < 0)
2095 evpipe [1] = fds [1]; /* first call, set write fd */ 2147 evpipe [1] = fds [1]; /* first call, set write fd */
2096 else 2148 else
2101 /* so must not be executed on windows */ 2153 /* so must not be executed on windows */
2102 2154
2103 dup2 (fds [1], evpipe [1]); 2155 dup2 (fds [1], evpipe [1]);
2104 close (fds [1]); 2156 close (fds [1]);
2105 } 2157 }
2158
2159 fd_intern (evpipe [1]);
2106 2160
2107 ev_io_set (&pipe_w, evpipe [0] < 0 ? evpipe [1] : evpipe [0], EV_READ); 2161 ev_io_set (&pipe_w, evpipe [0] < 0 ? evpipe [1] : evpipe [0], EV_READ);
2108 ev_io_start (EV_A_ &pipe_w); 2162 ev_io_start (EV_A_ &pipe_w);
2109 ev_unref (EV_A); /* watcher should not keep loop alive */ 2163 ev_unref (EV_A); /* watcher should not keep loop alive */
2110 } 2164 }
2229 2283
2230void 2284void
2231ev_feed_signal (int signum) EV_THROW 2285ev_feed_signal (int signum) EV_THROW
2232{ 2286{
2233#if EV_MULTIPLICITY 2287#if EV_MULTIPLICITY
2288 EV_P;
2234 ECB_MEMORY_FENCE_ACQUIRE; 2289 ECB_MEMORY_FENCE_ACQUIRE;
2235 EV_P = signals [signum - 1].loop; 2290 EV_A = signals [signum - 1].loop;
2236 2291
2237 if (!EV_A) 2292 if (!EV_A)
2238 return; 2293 return;
2239#endif 2294#endif
2240 2295
3893# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX) 3948# define EV_INOTIFY_BUFSIZE (sizeof (struct inotify_event) * 2 + NAME_MAX)
3894 3949
3895static void noinline 3950static void noinline
3896infy_add (EV_P_ ev_stat *w) 3951infy_add (EV_P_ ev_stat *w)
3897{ 3952{
3898 w->wd = inotify_add_watch (fs_fd, w->path, IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY | IN_DONT_FOLLOW | IN_MASK_ADD); 3953 w->wd = inotify_add_watch (fs_fd, w->path,
3954 IN_ATTRIB | IN_DELETE_SELF | IN_MOVE_SELF | IN_MODIFY
3955 | IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO
3956 | IN_DONT_FOLLOW | IN_MASK_ADD);
3899 3957
3900 if (w->wd >= 0) 3958 if (w->wd >= 0)
3901 { 3959 {
3902 struct statfs sfs; 3960 struct statfs sfs;
3903 3961
3907 3965
3908 if (!fs_2625) 3966 if (!fs_2625)
3909 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL; 3967 w->timer.repeat = w->interval ? w->interval : DEF_STAT_INTERVAL;
3910 else if (!statfs (w->path, &sfs) 3968 else if (!statfs (w->path, &sfs)
3911 && (sfs.f_type == 0x1373 /* devfs */ 3969 && (sfs.f_type == 0x1373 /* devfs */
3970 || sfs.f_type == 0x4006 /* fat */
3971 || sfs.f_type == 0x4d44 /* msdos */
3912 || sfs.f_type == 0xEF53 /* ext2/3 */ 3972 || sfs.f_type == 0xEF53 /* ext2/3 */
3973 || sfs.f_type == 0x72b6 /* jffs2 */
3974 || sfs.f_type == 0x858458f6 /* ramfs */
3975 || sfs.f_type == 0x5346544e /* ntfs */
3913 || sfs.f_type == 0x3153464a /* jfs */ 3976 || sfs.f_type == 0x3153464a /* jfs */
3977 || sfs.f_type == 0x9123683e /* btrfs */
3914 || sfs.f_type == 0x52654973 /* reiser3 */ 3978 || sfs.f_type == 0x52654973 /* reiser3 */
3915 || sfs.f_type == 0x01021994 /* tempfs */ 3979 || sfs.f_type == 0x01021994 /* tmpfs */
3916 || sfs.f_type == 0x58465342 /* xfs */)) 3980 || sfs.f_type == 0x58465342 /* xfs */))
3917 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */ 3981 w->timer.repeat = 0.; /* filesystem is local, kernel new enough */
3918 else 3982 else
3919 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */ 3983 w->timer.repeat = w->interval ? w->interval : NFS_STAT_INTERVAL; /* remote, use reduced frequency */
3920 } 3984 }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines