Mercurial > hg > nginx
comparison src/os/unix/ngx_atomic.h @ 939:782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 21 Dec 2006 16:33:31 +0000 |
parents | c73c5c58c619 |
children | ca9fe5ae412b |
comparison
equal
deleted
inserted
replaced
938:c4f120548171 | 939:782cf4c13b8d |
---|---|
10 | 10 |
11 #include <ngx_config.h> | 11 #include <ngx_config.h> |
12 #include <ngx_core.h> | 12 #include <ngx_core.h> |
13 | 13 |
14 | 14 |
15 #if (NGX_DARWIN) | |
16 | |
17 /* | |
18 * use MacOSX atomic(3) and barrier(3) operations | |
19 * optimized at run time for UP and SMP | |
20 */ | |
21 | |
22 #include <libkern/OSAtomic.h> | |
23 | |
24 /* "bool" conflicts with perl's CORE/handy.h | |
25 * "true" and "false" conflict with nginx, and of course we can rename them, | |
26 * but we need to undef "bool" anyway | |
27 */ | |
28 #undef bool | |
29 #undef true | |
30 #undef false | |
31 | |
32 | |
33 #define NGX_HAVE_ATOMIC_OPS 1 | |
34 | |
35 #if (NGX_PTR_SIZE == 8) | |
36 | |
37 typedef int64_t ngx_atomic_int_t; | |
38 typedef uint64_t ngx_atomic_uint_t; | |
39 #define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1 | |
40 | |
41 #define ngx_atomic_cmp_set(lock, old, new) \ | |
42 OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock) | |
43 | |
44 #define ngx_atomic_fetch_add(value, add) \ | |
45 (OSAtomicAdd64(add, (int64_t *) value) - add) | |
46 | |
47 #else | |
48 | |
49 typedef int32_t ngx_atomic_int_t; | |
50 typedef uint32_t ngx_atomic_uint_t; | |
51 #define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1 | |
52 | |
53 #define ngx_atomic_cmp_set(lock, old, new) \ | |
54 OSAtomicCompareAndSwap32Barrier(old, new, (int32_t *) lock) | |
55 | |
56 #define ngx_atomic_fetch_add(value, add) \ | |
57 (OSAtomicAdd32(add, (int32_t *) value) - add) | |
58 | |
59 #endif | |
60 | |
61 #define ngx_memory_barrier() OSMemoryBarrier() | |
62 | |
63 #define ngx_cpu_pause() | |
64 | |
65 typedef volatile ngx_atomic_uint_t ngx_atomic_t; | |
66 | |
67 | |
68 #else /* !(NGX_DARWIN) */ | |
69 | |
70 | |
15 #if ( __i386__ || __i386 ) | 71 #if ( __i386__ || __i386 ) |
16 | 72 |
17 typedef int32_t ngx_atomic_int_t; | 73 typedef int32_t ngx_atomic_int_t; |
18 typedef uint32_t ngx_atomic_uint_t; | 74 typedef uint32_t ngx_atomic_uint_t; |
19 typedef volatile ngx_atomic_uint_t ngx_atomic_t; | 75 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
136 typedef volatile ngx_atomic_uint_t ngx_atomic_t; | 192 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
137 | 193 |
138 | 194 |
139 #include "ngx_gcc_atomic_ppc.h" | 195 #include "ngx_gcc_atomic_ppc.h" |
140 | 196 |
197 | |
198 #endif | |
141 | 199 |
142 #endif | 200 #endif |
143 | 201 |
144 | 202 |
145 #if !(NGX_HAVE_ATOMIC_OPS) | 203 #if !(NGX_HAVE_ATOMIC_OPS) |
179 #define ngx_memory_barrier() | 237 #define ngx_memory_barrier() |
180 #define ngx_cpu_pause() | 238 #define ngx_cpu_pause() |
181 | 239 |
182 #endif | 240 #endif |
183 | 241 |
242 | |
184 void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); | 243 void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); |
185 | 244 |
186 #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) | 245 #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) |
187 #define ngx_unlock(lock) *(lock) = 0 | 246 #define ngx_unlock(lock) *(lock) = 0 |
188 | 247 |