--- libecb/ecb.h 2012/05/28 08:40:25 1.88 +++ libecb/ecb.h 2012/05/29 14:30:44 1.91 @@ -56,6 +56,7 @@ typedef uint32_t uintptr_t; typedef int32_t intptr_t; #endif + typedef intptr_t ptrdiff_t; #else #include #if UINTMAX_MAX > 0xffffffffU @@ -80,6 +81,13 @@ #endif #endif +#define ECB_C (__STDC__+0) /* this assumes that __STDC__ is either empty or a number */ +#define ECB_C99 (__STDC_VERSION__ >= 199901L) +#define ECB_C11 (__STDC_VERSION__ >= 201112L) +#define ECB_CPP (__cplusplus+0) +#define ECB_CPP98 (__cplusplus >= 199711L) +#define ECB_CPP11 (__cplusplus >= 201103L) + /*****************************************************************************/ /* ECB_NO_THREADS - ecb is not used by multiple threads, ever */ @@ -94,6 +102,17 @@ #endif #ifndef ECB_MEMORY_FENCE + #if ECB_C11 && !defined __STDC_NO_ATOMICS__ + /* we assume that these memory fences work on all variables/all memory accesses, */ + /* not just C11 atomics and atomic accesses */ + #include + #define ECB_MEMORY_FENCE atomic_thread_fence (memory_order_acq_rel) + #define ECB_MEMORY_FENCE_ACQUIRE atomic_thread_fence (memory_order_acquire) + #define ECB_MEMORY_FENCE_RELEASE atomic_thread_fence (memory_order_release) + #endif +#endif + +#ifndef ECB_MEMORY_FENCE #if ECB_GCC_VERSION(2,5) || defined __INTEL_COMPILER || (__llvm__ && __GNUC__) || __SUNPRO_C >= 0x5110 || __SUNPRO_CC >= 0x5110 #if __i386 || __i386__ #define ECB_MEMORY_FENCE __asm__ __volatile__ ("lock; orb $0, -1(%%esp)" : : : "memory") @@ -176,8 +195,6 @@ /*****************************************************************************/ -#define ECB_C99 (__STDC_VERSION__ >= 199901L) - #if __cplusplus #define ecb_inline static inline #elif ECB_GCC_VERSION(2,5) @@ -225,11 +242,16 @@ #endif #define ecb_noinline ecb_attribute ((__noinline__)) -#define ecb_noreturn ecb_attribute ((__noreturn__)) #define ecb_unused ecb_attribute ((__unused__)) #define ecb_const ecb_attribute ((__const__)) #define ecb_pure ecb_attribute ((__pure__)) +#if ECB_C11 + #define ecb_noreturn _Noreturn +#else + #define ecb_noreturn ecb_attribute ((__noreturn__)) +#endif + #if ECB_GCC_VERSION(4,3) #define ecb_artificial ecb_attribute ((__artificial__)) #define ecb_hot ecb_attribute ((__hot__))