comparison src/os/unix/ngx_atomic.h @ 270:6eb1e38f0f1f NGINX_0_5_5

nginx 0.5.5 *) Change: the -v switch does not show compiler information any more. *) Feature: the -V switch. *) Feature: the "worker_rlimit_core" directive supports size in K, M, and G. *) Bugfix: the nginx.pm module now could be installed by an unprivileged user. *) Bugfix: a segmentation fault might occur if the $r->request_body or $r->request_body_file methods were used. *) Bugfix: the ppc platform specific bugs.
author Igor Sysoev <http://sysoev.ru>
date Sun, 24 Dec 2006 00:00:00 +0300
parents 6be073125f2e
children 95183808f549
comparison
equal deleted inserted replaced
269:aa9c0062124d 270:6eb1e38f0f1f
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_ATOMIC)
16
17 /*
18 * use Darwin 8 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