~ubuntu-branches/ubuntu/trusty/nginx/trusty-proposed

« back to all changes in this revision

Viewing changes to src/os/unix/ngx_atomic.h

  • Committer: Package Import Robot
  • Author(s): Kartik Mistry
  • Date: 2013-04-25 12:51:45 UTC
  • mfrom: (1.3.28)
  • mto: (1.3.29) (15.1.2 experimental)
  • mto: This revision was merged to the branch mainline in revision 64.
  • Revision ID: package-import@ubuntu.com-20130425125145-ugl0wor6bq0u5eae
Tags: upstream-1.4.0
ImportĀ upstreamĀ versionĀ 1.4.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
 
2
2
/*
3
3
 * Copyright (C) Igor Sysoev
 
4
 * Copyright (C) Nginx, Inc.
4
5
 */
5
6
 
6
7
 
12
13
#include <ngx_core.h>
13
14
 
14
15
 
15
 
#if (NGX_DARWIN_ATOMIC)
 
16
#if (NGX_HAVE_LIBATOMIC)
 
17
 
 
18
#define AO_REQUIRE_CAS
 
19
#include <atomic_ops.h>
 
20
 
 
21
#define NGX_HAVE_ATOMIC_OPS  1
 
22
 
 
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;
 
26
 
 
27
#if (NGX_PTR_SIZE == 8)
 
28
#define NGX_ATOMIC_T_LEN            (sizeof("-9223372036854775808") - 1)
 
29
#else
 
30
#define NGX_ATOMIC_T_LEN            (sizeof("-2147483648") - 1)
 
31
#endif
 
32
 
 
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()
 
39
 
 
40
 
 
41
#elif (NGX_DARWIN_ATOMIC)
16
42
 
17
43
/*
18
44
 * use Darwin 8 atomic(3) and barrier(3) operations
21
47
 
22
48
#include <libkern/OSAtomic.h>
23
49
 
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
 
 */
 
50
/* "bool" conflicts with perl's CORE/handy.h */
 
51
#if 0
28
52
#undef bool
29
 
#undef true
30
 
#undef false
 
53
#endif
31
54
 
32
55
 
33
56
#define NGX_HAVE_ATOMIC_OPS  1
36
59
 
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)
40
63
 
41
64
#define ngx_atomic_cmp_set(lock, old, new)                                    \
42
65
    OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock)
48
71
 
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)
52
75
 
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;
66
89
 
67
90
 
68
 
#else /* !(NGX_DARWIN) */
69
 
 
70
 
 
71
 
#if ( __i386__ || __i386 )
 
91
#elif (NGX_HAVE_GCC_ATOMIC)
 
92
 
 
93
/* GCC 4.1 builtin atomic operations */
 
94
 
 
95
#define NGX_HAVE_ATOMIC_OPS  1
 
96
 
 
97
typedef long                        ngx_atomic_int_t;
 
98
typedef unsigned long               ngx_atomic_uint_t;
 
99
 
 
100
#if (NGX_PTR_SIZE == 8)
 
101
#define NGX_ATOMIC_T_LEN            (sizeof("-9223372036854775808") - 1)
 
102
#else
 
103
#define NGX_ATOMIC_T_LEN            (sizeof("-2147483648") - 1)
 
104
#endif
 
105
 
 
106
typedef volatile ngx_atomic_uint_t  ngx_atomic_t;
 
107
 
 
108
 
 
109
#define ngx_atomic_cmp_set(lock, old, set)                                    \
 
110
    __sync_bool_compare_and_swap(lock, old, set)
 
111
 
 
112
#define ngx_atomic_fetch_add(value, add)                                      \
 
113
    __sync_fetch_and_add(value, add)
 
114
 
 
115
#define ngx_memory_barrier()        __sync_synchronize()
 
116
 
 
117
#if ( __i386__ || __i386 || __amd64__ || __amd64 )
 
118
#define ngx_cpu_pause()             __asm__ ("pause")
 
119
#else
 
120
#define ngx_cpu_pause()
 
121
#endif
 
122
 
 
123
 
 
124
#elif ( __i386__ || __i386 )
72
125
 
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)
77
130
 
78
131
 
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)
118
171
 
119
172
 
120
173
#if ( __SUNPRO_C )
156
209
 
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)
160
213
 
161
214
#else
162
215
 
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)
166
219
 
167
220
#endif
168
221
 
193
246
 
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)
197
250
 
198
251
#else
199
252
 
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)
203
256
 
204
257
#endif
205
258
 
208
261
 
209
262
#include "ngx_gcc_atomic_ppc.h"
210
263
 
211
 
 
212
 
#endif
213
 
 
214
264
#endif
215
265
 
216
266
 
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)
225
275
 
226
276
 
227
277
static ngx_inline ngx_atomic_uint_t