root/trunk/sol_compat.h

Revision 2, 4.1 kB (checked in by wez, 8 years ago)

Initial revision

  • Property svn:eol-style set to native
Line 
1 /*
2  * Copyright (c) 2006 OmniTI, Inc. All rights reserved
3  * This header file distributed under the terms of the CDDL.
4  * Portions Copyright 2004 Sun Microsystems, Inc. All Rights reserved.
5  */
6 #ifndef _EC_UMEM_SOL_COMPAT_H_
7 #define _EC_UMEM_SOL_COMPAT_H_
8
9 #if defined(__MACH__) || defined(_WIN32)
10 #define NO_WEAK_SYMBOLS
11 #define _umem_cache_alloc(a,b) umem_cache_alloc(a,b)
12 #define _umem_cache_free(a,b) umem_cache_free(a,b)
13 #define _umem_zalloc(a,b) umem_zalloc(a,b)
14 #define _umem_alloc(a,b) umem_alloc(a,b)
15 #define _umem_alloc_align(a,b,c) umem_alloc_align(a,b,c)
16 #define _umem_free(a,b) umem_free(a,b)
17 #define _umem_free_align(a,b) umem_free_align(a,b)
18 #endif
19
20 #ifdef _WIN32
21 #define bcopy(s, d, n)          memcpy(d, s, n)
22 #define bzero(m, s)                     memset(m, 0, s)
23 #endif
24
25 typedef pthread_t thread_t;
26 typedef pthread_mutex_t mutex_t;
27 typedef pthread_cond_t cond_t;
28 typedef u_int64_t hrtime_t;
29 typedef uint32_t uint_t;
30 typedef unsigned long ulong_t;
31 typedef struct timespec timestruc_t;
32 typedef long long longlong_t;
33 typedef struct timespec timespec_t;
34 static INLINE hrtime_t gethrtime(void) {
35   struct timeval tv;
36   gettimeofday(&tv, NULL);
37   return (((u_int64_t)tv.tv_sec) << 32) | tv.tv_usec;
38 }
39 # define thr_self()                pthread_self()
40 static INLINE thread_t _thr_self(void) {
41   return thr_self();
42 }
43 #if defined(_MACH_PORT_T)
44 #define CPUHINT() (pthread_mach_thread_np(pthread_self()))
45 #endif
46 # define thr_sigsetmask            pthread_sigmask
47
48 #define THR_BOUND     1
49 #define THR_DETACHED  2
50 #define THR_DAEMON    4
51
52 static INLINE int thr_create(void *stack_base,
53   size_t stack_size, THR_RETURN (THR_API *start_func)(void*),
54   void *arg, long flags, thread_t *new_thread_ID)
55 {
56   int ret;
57   pthread_attr_t attr;
58
59   pthread_attr_init(&attr);
60
61   if (flags & THR_DETACHED) {
62     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
63   }
64   ret = pthread_create(new_thread_ID, &attr, start_func, arg);
65   pthread_attr_destroy(&attr);
66   return ret;
67 }
68
69
70 # define mutex_init(mp, type, arg) pthread_mutex_init(mp, NULL)
71 # define mutex_lock(mp)            pthread_mutex_lock(mp)
72 # define mutex_unlock(mp)          pthread_mutex_unlock(mp)
73 # define mutex_destroy(mp)         pthread_mutex_destroy(mp)
74 # define mutex_trylock(mp)         pthread_mutex_trylock(mp)
75 # define DEFAULTMUTEX              PTHREAD_MUTEX_INITIALIZER
76 # define DEFAULTCV                                 PTHREAD_COND_INITIALIZER
77 # define MUTEX_HELD(mp)            1 /* not really, but only used in an assert */
78
79 # define cond_init(c, type, arg)   pthread_cond_init(c, NULL)
80 # define cond_wait(c, m)           pthread_cond_wait(c, m)
81 # define _cond_wait(c, m)          pthread_cond_wait(c, m)
82 # define cond_signal(c)            pthread_cond_signal(c)
83 # define cond_broadcast(c)         pthread_cond_broadcast(c)
84 # define cond_destroy(c)           pthread_cond_destroy(c)
85 # define cond_timedwait            pthread_cond_timedwait
86 # define _cond_timedwait           pthread_cond_timedwait
87
88 #ifndef RTLD_FIRST
89 # define RTLD_FIRST 0
90 #endif
91
92 #include "ec_atomic.h"
93
94 #define P2PHASE(x, align)    ((x) & ((align) - 1))
95 #define P2ALIGN(x, align)    ((x) & -(align))
96 #define P2NPHASE(x, align)    (-(x) & ((align) - 1))
97 #define P2ROUNDUP(x, align)   (-(-(x) & -(align)))
98 #define P2END(x, align)     (-(~(x) & -(align)))
99 #define P2PHASEUP(x, align, phase)  ((phase) - (((phase) - (x)) & -(align)))
100 #define P2CROSS(x, y, align)    (((x) ^ (y)) > (align) - 1)
101 #define P2SAMEHIGHBIT(x, y)    (((x) ^ (y)) < ((x) & (y)))
102 #define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
103 #define ISP2(x)    (((x) & ((x) - 1)) == 0)
104
105 /* beware! umem only uses these atomic adds for incrementing by 1 */
106 #define atomic_add_64(lvalptr, delta) ec_atomic_inc64(lvalptr)
107 #define atomic_add_32_nv(a, b)            ec_atomic_inc(a)
108
109 #ifndef NANOSEC
110 #define NANOSEC 1000000000
111 #endif
112
113 #ifdef _WIN32
114 #define issetugid()               0
115 #else
116 #define issetugid()       (geteuid() == 0)
117 #endif
118
119 #define _sysconf(a) sysconf(a)
120 #define __NORETURN  __attribute__ ((noreturn))
121
122 #define EC_UMEM_DUMMY_PCSTACK 1
123 static INLINE int __nthreads(void)
124 {
125   /* or more; just to force multi-threaded mode */
126   return 2;
127 }
128
129 #if (SIZEOF_VOID_P == 8)
130 # define _LP64 1
131 #endif
132
133 #endif
Note: See TracBrowser for help on using the browser.