12
13
#include <ngx_core.h>
15
#if (NGX_DARWIN_ATOMIC)
16
#if (NGX_HAVE_LIBATOMIC)
18
#define AO_REQUIRE_CAS
19
#include <atomic_ops.h>
21
#define NGX_HAVE_ATOMIC_OPS 1
23
typedef long ngx_atomic_int_t;
24
typedef AO_t ngx_atomic_uint_t;
25
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
27
#if (NGX_PTR_SIZE == 8)
28
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
30
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
33
#define ngx_atomic_cmp_set(lock, old, new) \
34
AO_compare_and_swap(lock, old, new)
35
#define ngx_atomic_fetch_add(value, add) \
36
AO_fetch_and_add(value, add)
37
#define ngx_memory_barrier() AO_nop()
38
#define ngx_cpu_pause()
41
#elif (NGX_DARWIN_ATOMIC)
18
44
* use Darwin 8 atomic(3) and barrier(3) operations
22
48
#include <libkern/OSAtomic.h>
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
50
/* "bool" conflicts with perl's CORE/handy.h */
33
56
#define NGX_HAVE_ATOMIC_OPS 1
37
60
typedef int64_t ngx_atomic_int_t;
38
61
typedef uint64_t ngx_atomic_uint_t;
39
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
62
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
41
64
#define ngx_atomic_cmp_set(lock, old, new) \
42
65
OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock)
49
72
typedef int32_t ngx_atomic_int_t;
50
73
typedef uint32_t ngx_atomic_uint_t;
51
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
74
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
53
76
#define ngx_atomic_cmp_set(lock, old, new) \
54
77
OSAtomicCompareAndSwap32Barrier(old, new, (int32_t *) lock)
65
88
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
68
#else /* !(NGX_DARWIN) */
71
#if ( __i386__ || __i386 )
91
#elif (NGX_HAVE_GCC_ATOMIC)
93
/* GCC 4.1 builtin atomic operations */
95
#define NGX_HAVE_ATOMIC_OPS 1
97
typedef long ngx_atomic_int_t;
98
typedef unsigned long ngx_atomic_uint_t;
100
#if (NGX_PTR_SIZE == 8)
101
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
103
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
106
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
109
#define ngx_atomic_cmp_set(lock, old, set) \
110
__sync_bool_compare_and_swap(lock, old, set)
112
#define ngx_atomic_fetch_add(value, add) \
113
__sync_fetch_and_add(value, add)
115
#define ngx_memory_barrier() __sync_synchronize()
117
#if ( __i386__ || __i386 || __amd64__ || __amd64 )
118
#define ngx_cpu_pause() __asm__ ("pause")
120
#define ngx_cpu_pause()
124
#elif ( __i386__ || __i386 )
73
126
typedef int32_t ngx_atomic_int_t;
74
127
typedef uint32_t ngx_atomic_uint_t;
75
128
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
76
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
129
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
79
132
#if ( __SUNPRO_C )
114
167
typedef int64_t ngx_atomic_int_t;
115
168
typedef uint64_t ngx_atomic_uint_t;
116
169
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
117
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
170
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
120
173
#if ( __SUNPRO_C )
157
210
typedef int64_t ngx_atomic_int_t;
158
211
typedef uint64_t ngx_atomic_uint_t;
159
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
212
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
163
216
typedef int32_t ngx_atomic_int_t;
164
217
typedef uint32_t ngx_atomic_uint_t;
165
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
218
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
194
247
typedef int64_t ngx_atomic_int_t;
195
248
typedef uint64_t ngx_atomic_uint_t;
196
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
249
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
200
253
typedef int32_t ngx_atomic_int_t;
201
254
typedef uint32_t ngx_atomic_uint_t;
202
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
255
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
221
271
typedef int32_t ngx_atomic_int_t;
222
272
typedef uint32_t ngx_atomic_uint_t;
223
273
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
224
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
274
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
227
277
static ngx_inline ngx_atomic_uint_t