6 #ifndef _EC_UMEM_SOL_COMPAT_H_ 7 #define _EC_UMEM_SOL_COMPAT_H_ 14 #ifdef HAVE_SYS_TIME_H 19 # define THR_RETURN DWORD 20 # define THR_API WINAPI 21 # define INLINE __inline 23 # define THR_RETURN void * 25 # define INLINE inline 28 #if defined(__MACH__) || defined(_WIN32) 29 #define NO_WEAK_SYMBOLS 30 #define _umem_cache_alloc(a,b) umem_cache_alloc(a,b) 31 #define _umem_cache_free(a,b) umem_cache_free(a,b) 32 #define _umem_zalloc(a,b) umem_zalloc(a,b) 33 #define _umem_alloc(a,b) umem_alloc(a,b) 34 #define _umem_alloc_align(a,b,c) umem_alloc_align(a,b,c) 35 #define _umem_free(a,b) umem_free(a,b) 36 #define _umem_free_align(a,b) umem_free_align(a,b) 40 #define bcopy(s, d, n) memcpy(d, s, n) 41 #define bzero(m, s) memset(m, 0, s) 55 gettimeofday(&tv, NULL);
56 return (((u_int64_t)tv.tv_sec) << 32) | tv.tv_usec;
58 # define thr_self() pthread_self() 62 #if defined(_MACH_PORT_T) 63 #define CPUHINT() (pthread_mach_thread_np(pthread_self())) 65 # define thr_sigsetmask pthread_sigmask 68 #define THR_DETACHED 2 71 static INLINE int thr_create(
void *stack_base,
73 void *arg,
long flags,
thread_t *new_thread_ID)
78 pthread_attr_init(&attr);
81 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
83 ret = pthread_create(new_thread_ID, &attr, start_func, arg);
84 pthread_attr_destroy(&attr);
89 # define mutex_init(mp, type, arg) pthread_mutex_init(mp, NULL) 90 # define mutex_lock(mp) pthread_mutex_lock(mp) 91 # define mutex_unlock(mp) pthread_mutex_unlock(mp) 92 # define mutex_destroy(mp) pthread_mutex_destroy(mp) 93 # define mutex_trylock(mp) pthread_mutex_trylock(mp) 94 # define DEFAULTMUTEX PTHREAD_MUTEX_INITIALIZER 95 # define DEFAULTCV PTHREAD_COND_INITIALIZER 96 # define MUTEX_HELD(mp) 1 98 # define cond_init(c, type, arg) pthread_cond_init(c, NULL) 99 # define cond_wait(c, m) pthread_cond_wait(c, m) 100 # define _cond_wait(c, m) pthread_cond_wait(c, m) 101 # define cond_signal(c) pthread_cond_signal(c) 102 # define cond_broadcast(c) pthread_cond_broadcast(c) 103 # define cond_destroy(c) pthread_cond_destroy(c) 104 # define cond_timedwait pthread_cond_timedwait 105 # define _cond_timedwait pthread_cond_timedwait 108 # define RTLD_FIRST 0 112 # include "ec_atomic.h" 115 # define ec_atomic_inc(a) InterlockedIncrement(a) 116 # define ec_atomic_inc64(a) InterlockedIncrement64(a) 117 # elif (defined(__i386__) || defined(__x86_64__)) && defined(__GNUC__) 121 asm volatile (
"lock; cmpxchgl %1, %2" 123 :
"r" (with),
"m" (*(mem)),
"0" (cmp)
129 # ifndef ec_atomic_inc 135 }
while (ec_atomic_cas(mem, last+1, last) != last);
139 # ifndef ec_atomic_inc64 142 # define ec_atomic_inc64(a) (*a)++ 147 #define P2PHASE(x, align) ((x) & ((align) - 1)) 148 #define P2ALIGN(x, align) ((x) & -(align)) 149 #define P2NPHASE(x, align) (-(x) & ((align) - 1)) 150 #define P2ROUNDUP(x, align) (-(-(x) & -(align))) 151 #define P2END(x, align) (-(~(x) & -(align))) 152 #define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align))) 153 #define P2CROSS(x, y, align) (((x) ^ (y)) > (align) - 1) 154 #define P2SAMEHIGHBIT(x, y) (((x) ^ (y)) < ((x) & (y))) 155 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) 156 #define ISP2(x) (((x) & ((x) - 1)) == 0) 159 #define atomic_add_64(lvalptr, delta) ec_atomic_inc64(lvalptr) 160 #define atomic_add_32_nv(a, b) ec_atomic_inc(a) 163 #define NANOSEC 1000000000 167 #define issetugid() 0 168 #elif !HAVE_ISSETUGID 169 #define issetugid() (geteuid() == 0) 172 #define _sysconf(a) sysconf(a) 173 #define __NORETURN __attribute__ ((noreturn)) 175 #define EC_UMEM_DUMMY_PCSTACK 1 176 static INLINE int __nthreads(
void)
182 #if (SIZEOF_VOID_P == 8) 187 # define MIN(a,b) ((a) < (b) ? (a) : (b)) 190 # define MAX(a,b) ((a) > (b) ? (a) : (b)) long long longlong_t
Definition: sol_compat.h:51
struct timespec timespec_t
Definition: sol_compat.h:52
#define THR_RETURN
Definition: sol_compat.h:23
#define THR_API
Definition: sol_compat.h:24
pthread_cond_t cond_t
Definition: sol_compat.h:46
pthread_mutex_t mutex_t
Definition: sol_compat.h:45
#define thr_self()
Definition: sol_compat.h:58
#define THR_DETACHED
Definition: sol_compat.h:68
u_int64_t hrtime_t
Definition: sol_compat.h:47
pthread_t thread_t
Definition: sol_compat.h:44
#define INLINE
Definition: sol_compat.h:25
unsigned long ulong_t
Definition: sol_compat.h:49
struct timespec timestruc_t
Definition: sol_compat.h:50
uint32_t uint_t
Definition: sol_compat.h:48