… | |
… | |
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" {) |
|
|
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 | { |
… | |
… | |
1287 | |
1301 | |
1288 | do |
1302 | do |
1289 | ncur <<= 1; |
1303 | ncur <<= 1; |
1290 | while (cnt > ncur); |
1304 | while (cnt > ncur); |
1291 | |
1305 | |
1292 | /* 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 */ |
1293 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1307 | if (elem * ncur > MALLOC_ROUND - sizeof (void *) * 4) |
1294 | { |
1308 | { |
1295 | ncur *= elem; |
1309 | ncur *= elem; |
1296 | 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); |
1297 | ncur = ncur - sizeof (void *) * 4; |
1311 | ncur = ncur - sizeof (void *) * 4; |
… | |
… | |
4400 | |
4414 | |
4401 | #if EV_MULTIPLICITY |
4415 | #if EV_MULTIPLICITY |
4402 | #include "ev_wrap.h" |
4416 | #include "ev_wrap.h" |
4403 | #endif |
4417 | #endif |
4404 | |
4418 | |
4405 | EV_CPP(}) |
|
|
4406 | |
|
|