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

Comparing libev/ev.c (file contents):
Revision 1.395 by root, Wed Aug 24 16:08:17 2011 UTC vs.
Revision 1.402 by sf-exg, Tue Dec 20 10:34:10 2011 UTC

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
188EV_CPP(extern "C" {)
189
190#ifndef _WIN32 188#ifndef _WIN32
191# include <sys/time.h> 189# include <sys/time.h>
192# include <sys/wait.h> 190# include <sys/wait.h>
193# include <unistd.h> 191# include <unistd.h>
194#else 192#else
541#if ECB_NO_THREADS || ECB_NO_SMP 539#if ECB_NO_THREADS || ECB_NO_SMP
542 #define ECB_MEMORY_FENCE do { } while (0) 540 #define ECB_MEMORY_FENCE do { } while (0)
543#endif 541#endif
544 542
545#ifndef ECB_MEMORY_FENCE 543#ifndef ECB_MEMORY_FENCE
546 #if ECB_GCC_VERSION(2,5) 544 #if ECB_GCC_VERSION(2,5) || defined(__INTEL_COMPILER) || defined(__clang__)
547 #if __i386__ 545 #if __i386__
548 #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") 546 #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 */ 547 #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 */ 548 #define ECB_MEMORY_FENCE_RELEASE do { } while (0) /* unlikely to change in future cpus */
551 #elif __amd64 549 #elif __amd64
563 #endif 561 #endif
564 #endif 562 #endif
565#endif 563#endif
566 564
567#ifndef ECB_MEMORY_FENCE 565#ifndef ECB_MEMORY_FENCE
568 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) 566 #if ECB_GCC_VERSION(4,4) || defined(__INTEL_COMPILER) || defined(__clang__)
569 #define ECB_MEMORY_FENCE __sync_synchronize () 567 #define ECB_MEMORY_FENCE __sync_synchronize ()
570 /*#define ECB_MEMORY_FENCE_ACQUIRE ({ char dummy = 0; __sync_lock_test_and_set (&dummy, 1); }) */ 568 /*#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 ); }) */ 569 /*#define ECB_MEMORY_FENCE_RELEASE ({ char dummy = 1; __sync_lock_release (&dummy ); }) */
572 #elif _MSC_VER >= 1400 /* VC++ 2005 */ 570 #elif _MSC_VER >= 1400 /* VC++ 2005 */
573 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier) 571 #pragma intrinsic(_ReadBarrier,_WriteBarrier,_ReadWriteBarrier)
843 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0)) 841 #define ecb_mod(m,n) ((m) % (n) + ((m) % (n) < 0 ? (n) : 0))
844#else 842#else
845 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n))) 843 #define ecb_mod(m,n) ((m) < 0 ? ((n) - 1 - ((-1 - (m)) % (n))) : ((m) % (n)))
846#endif 844#endif
847 845
846#if __cplusplus
847 template<typename T>
848 static inline T ecb_div_rd (T val, T div)
849 {
850 return val < 0 ? - ((-val + div - 1) / div) : (val ) / div;
851 }
852 template<typename T>
853 static inline T ecb_div_ru (T val, T div)
854 {
855 return val < 0 ? - ((-val ) / div) : (val + div - 1) / div;
856 }
857#else
858 #define ecb_div_rd(val,div) ((val) < 0 ? - ((-(val) + (div) - 1) / (div)) : ((val) ) / (div))
859 #define ecb_div_ru(val,div) ((val) < 0 ? - ((-(val) ) / (div)) : ((val) + (div) - 1) / (div))
860#endif
861
848#if ecb_cplusplus_does_not_suck 862#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) */ 863 /* 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> 864 template<typename T, int N>
851 static inline int ecb_array_length (const T (&arr)[N]) 865 static inline int ecb_array_length (const T (&arr)[N])
852 { 866 {
859#endif 873#endif
860 874
861/* ECB.H END */ 875/* ECB.H END */
862 876
863#if ECB_MEMORY_FENCE_NEEDS_PTHREADS 877#if ECB_MEMORY_FENCE_NEEDS_PTHREADS
878/* if your architecture doesn't need memory fences, e.g. because it is
879 * single-cpu/core, or if you use libev in a project that doesn't use libev
880 * from multiple threads, then you can define ECB_AVOID_PTHREADS when compiling
881 * libev, in which cases the memory fences become nops.
882 * alternatively, you can remove this #error and link against libpthread,
883 * which will then provide the memory fences.
884 */
885# error "memory fences not defined for your architecture, please report"
886#endif
887
864# undef ECB_MEMORY_FENCE 888#ifndef ECB_MEMORY_FENCE
865# undef ECB_MEMORY_FENCE_ACQUIRE 889# define ECB_MEMORY_FENCE do { } while (0)
866# undef ECB_MEMORY_FENCE_RELEASE 890# define ECB_MEMORY_FENCE_ACQUIRE ECB_MEMORY_FENCE
891# define ECB_MEMORY_FENCE_RELEASE ECB_MEMORY_FENCE
867#endif 892#endif
868 893
869#define expect_false(cond) ecb_expect_false (cond) 894#define expect_false(cond) ecb_expect_false (cond)
870#define expect_true(cond) ecb_expect_true (cond) 895#define expect_true(cond) ecb_expect_true (cond)
871#define noinline ecb_noinline 896#define noinline ecb_noinline
1168 #undef VAR 1193 #undef VAR
1169 }; 1194 };
1170 #include "ev_wrap.h" 1195 #include "ev_wrap.h"
1171 1196
1172 static struct ev_loop default_loop_struct; 1197 static struct ev_loop default_loop_struct;
1173 struct ev_loop *ev_default_loop_ptr; 1198 EV_API_DECL struct ev_loop *ev_default_loop_ptr = 0; /* needs to be initialised to make it a definition despite extern */
1174 1199
1175#else 1200#else
1176 1201
1177 ev_tstamp ev_rt_now; 1202 EV_API_DECL ev_tstamp ev_rt_now = 0; /* needs to be initialised to make it a definition despite extern */
1178 #define VAR(name,decl) static decl; 1203 #define VAR(name,decl) static decl;
1179 #include "ev_vars.h" 1204 #include "ev_vars.h"
1180 #undef VAR 1205 #undef VAR
1181 1206
1182 static int ev_default_loop_ptr; 1207 static int ev_default_loop_ptr;
1276 1301
1277 do 1302 do
1278 ncur <<= 1; 1303 ncur <<= 1;
1279 while (cnt > ncur); 1304 while (cnt > ncur);
1280 1305
1281 /* if size is large, round to MALLOC_ROUND - 4 * longs to accomodate malloc overhead */ 1306 /* if size is large, round to MALLOC_ROUND - 4 * longs to accommodate malloc overhead */
1282 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) 1307 if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4)
1283 { 1308 {
1284 ncur *= elem; 1309 ncur *= elem;
1285 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1); 1310 ncur = (ncur + elem + (MALLOC_ROUND - 1) + sizeof (void *) * 4) & ~(MALLOC_ROUND - 1);
1286 ncur = ncur - sizeof (void *) * 4; 1311 ncur = ncur - sizeof (void *) * 4;
2966#endif 2991#endif
2967 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */ 2992 assert ((loop_done = EVBREAK_RECURSE, 1)); /* assert for side effect */
2968 backend_poll (EV_A_ waittime); 2993 backend_poll (EV_A_ waittime);
2969 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */ 2994 assert ((loop_done = EVBREAK_CANCEL, 1)); /* assert for side effect */
2970 2995
2971 pipe_write_wanted = 0; /* just an optimsiation, no fence needed */ 2996 pipe_write_wanted = 0; /* just an optimisation, no fence needed */
2972 2997
2973 if (pipe_write_skipped) 2998 if (pipe_write_skipped)
2974 { 2999 {
2975 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w))); 3000 assert (("libev: pipe_w not active, but pipe not written", ev_is_active (&pipe_w)));
2976 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM); 3001 ev_feed_event (EV_A_ &pipe_w, EV_CUSTOM);
4389 4414
4390#if EV_MULTIPLICITY 4415#if EV_MULTIPLICITY
4391 #include "ev_wrap.h" 4416 #include "ev_wrap.h"
4392#endif 4417#endif
4393 4418
4394EV_CPP(})
4395

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines