Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_atomic.h @ 4597:4be36d5e78ae
Fixed ngx_readv_chain() to honor IOV_MAX (ticket #14).
Not using full chain passed is ok as consumers are expected to check
event's ready flag to determine if another call is needed, not the
returned size.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Tue, 17 Apr 2012 09:13:58 +0000 |
parents | d620f497c50f |
children | 4c36e15651f7 |
rev | line source |
---|---|
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
435
diff
changeset
|
1 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
435
diff
changeset
|
2 /* |
444
42d11f017717
nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents:
441
diff
changeset
|
3 * Copyright (C) Igor Sysoev |
4412 | 4 * Copyright (C) Nginx, Inc. |
441
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
435
diff
changeset
|
5 */ |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
435
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
435
diff
changeset
|
7 |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
8 #ifndef _NGX_ATOMIC_H_INCLUDED_ |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
9 #define _NGX_ATOMIC_H_INCLUDED_ |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
10 |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
11 |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <ngx_config.h> |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 #include <ngx_core.h> |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
15 |
3363 | 16 #if (NGX_HAVE_LIBATOMIC) |
17 | |
3378
5d17022a1e88
fix libatomic usage on arm, cris, hppa, m68k, and sparc platforms
Igor Sysoev <igor@sysoev.ru>
parents:
3363
diff
changeset
|
18 #define AO_REQUIRE_CAS |
3363 | 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) | |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
42 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
43 /* |
940 | 44 * use Darwin 8 atomic(3) and barrier(3) operations |
45 * optimized at run-time for UP and SMP | |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
46 */ |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
47 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
48 #include <libkern/OSAtomic.h> |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
49 |
2133
c505e2712e13
fix conflicting names "true" and "false"
Igor Sysoev <igor@sysoev.ru>
parents:
1309
diff
changeset
|
50 /* "bool" conflicts with perl's CORE/handy.h */ |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
51 #undef bool |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
52 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
53 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
54 #define NGX_HAVE_ATOMIC_OPS 1 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
55 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
56 #if (NGX_PTR_SIZE == 8) |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
57 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
58 typedef int64_t ngx_atomic_int_t; |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
59 typedef uint64_t ngx_atomic_uint_t; |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
60 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
61 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
62 #define ngx_atomic_cmp_set(lock, old, new) \ |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
63 OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock) |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
64 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
65 #define ngx_atomic_fetch_add(value, add) \ |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
66 (OSAtomicAdd64(add, (int64_t *) value) - add) |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
67 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
68 #else |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
69 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
70 typedef int32_t ngx_atomic_int_t; |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
71 typedef uint32_t ngx_atomic_uint_t; |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
72 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
73 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
74 #define ngx_atomic_cmp_set(lock, old, new) \ |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
75 OSAtomicCompareAndSwap32Barrier(old, new, (int32_t *) lock) |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
76 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
77 #define ngx_atomic_fetch_add(value, add) \ |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
78 (OSAtomicAdd32(add, (int32_t *) value) - add) |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
79 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
80 #endif |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
81 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
82 #define ngx_memory_barrier() OSMemoryBarrier() |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
83 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
84 #define ngx_cpu_pause() |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
85 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
86 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
87 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
88 |
3362
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
89 #elif (NGX_HAVE_GCC_ATOMIC) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
90 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
91 /* GCC 4.1 builtin atomic operations */ |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
92 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
93 #define NGX_HAVE_ATOMIC_OPS 1 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
94 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
95 typedef long ngx_atomic_int_t; |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
96 typedef unsigned long ngx_atomic_uint_t; |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
97 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
98 #if (NGX_PTR_SIZE == 8) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
99 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
100 #else |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
101 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
102 #endif |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
103 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
104 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
105 |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
106 |
3362
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
107 #define ngx_atomic_cmp_set(lock, old, set) \ |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
108 __sync_bool_compare_and_swap(lock, old, set) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
109 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
110 #define ngx_atomic_fetch_add(value, add) \ |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
111 __sync_fetch_and_add(value, add) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
112 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
113 #define ngx_memory_barrier() __sync_synchronize() |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
114 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
115 #if ( __i386__ || __i386 || __amd64__ || __amd64 ) |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
116 #define ngx_cpu_pause() __asm__ ("pause") |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
117 #else |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
118 #define ngx_cpu_pause() |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
119 #endif |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
120 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
121 |
b57a4a704f3c
GCC 4.1 builtin atomic operations
Igor Sysoev <igor@sysoev.ru>
parents:
3165
diff
changeset
|
122 #elif ( __i386__ || __i386 ) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
123 |
561 | 124 typedef int32_t ngx_atomic_int_t; |
125 typedef uint32_t ngx_atomic_uint_t; | |
495 | 126 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
127 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
493 | 128 |
129 | |
561 | 130 #if ( __SUNPRO_C ) |
493 | 131 |
561 | 132 #define NGX_HAVE_ATOMIC_OPS 1 |
493 | 133 |
561 | 134 ngx_atomic_uint_t |
135 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
136 ngx_atomic_uint_t set); | |
493 | 137 |
561 | 138 ngx_atomic_int_t |
139 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); | |
493 | 140 |
1309 | 141 /* |
142 * Sun Studio 12 exits with segmentation fault on '__asm ("pause")', | |
143 * so ngx_cpu_pause is declared in src/os/unix/ngx_sunpro_x86.il | |
144 */ | |
145 | |
146 void | |
147 ngx_cpu_pause(void); | |
148 | |
561 | 149 /* the code in src/os/unix/ngx_sunpro_x86.il */ |
493 | 150 |
563 | 151 #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") |
152 | |
493 | 153 |
561 | 154 #else /* ( __GNUC__ || __INTEL_COMPILER ) */ |
155 | |
156 #define NGX_HAVE_ATOMIC_OPS 1 | |
493 | 157 |
561 | 158 #include "ngx_gcc_atomic_x86.h" |
493 | 159 |
561 | 160 #endif |
493 | 161 |
162 | |
547 | 163 #elif ( __amd64__ || __amd64 ) |
493 | 164 |
561 | 165 typedef int64_t ngx_atomic_int_t; |
166 typedef uint64_t ngx_atomic_uint_t; | |
495 | 167 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
168 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
169 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
170 |
561 | 171 #if ( __SUNPRO_C ) |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
172 |
561 | 173 #define NGX_HAVE_ATOMIC_OPS 1 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
174 |
561 | 175 ngx_atomic_uint_t |
176 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
177 ngx_atomic_uint_t set); | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
178 |
561 | 179 ngx_atomic_int_t |
180 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); | |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
181 |
1309 | 182 /* |
183 * Sun Studio 12 exits with segmentation fault on '__asm ("pause")', | |
184 * so ngx_cpu_pause is declared in src/os/unix/ngx_sunpro_amd64.il | |
185 */ | |
186 | |
187 void | |
188 ngx_cpu_pause(void); | |
189 | |
561 | 190 /* the code in src/os/unix/ngx_sunpro_amd64.il */ |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
191 |
563 | 192 #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") |
193 | |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
194 |
561 | 195 #else /* ( __GNUC__ || __INTEL_COMPILER ) */ |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
196 |
561 | 197 #define NGX_HAVE_ATOMIC_OPS 1 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
198 |
561 | 199 #include "ngx_gcc_atomic_amd64.h" |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
200 |
561 | 201 #endif |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
202 |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
300
diff
changeset
|
203 |
1308
63fa39cf8bd0
--with-cpu-opt=sparc32 and --with-cpu-opt=sparc64
Igor Sysoev <igor@sysoev.ru>
parents:
940
diff
changeset
|
204 #elif ( __sparc__ || __sparc || __sparcv9 ) |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
205 |
561 | 206 #if (NGX_PTR_SIZE == 8) |
207 | |
208 typedef int64_t ngx_atomic_int_t; | |
209 typedef uint64_t ngx_atomic_uint_t; | |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
210 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
211 |
493 | 212 #else |
561 | 213 |
214 typedef int32_t ngx_atomic_int_t; | |
215 typedef uint32_t ngx_atomic_uint_t; | |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
216 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
561 | 217 |
493 | 218 #endif |
219 | |
495 | 220 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
221 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
222 |
561 | 223 #if ( __SUNPRO_C ) |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
224 |
561 | 225 #define NGX_HAVE_ATOMIC_OPS 1 |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
226 |
561 | 227 #include "ngx_sunpro_atomic_sparc64.h" |
493 | 228 |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
229 |
561 | 230 #else /* ( __GNUC__ || __INTEL_COMPILER ) */ |
493 | 231 |
561 | 232 #define NGX_HAVE_ATOMIC_OPS 1 |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
233 |
561 | 234 #include "ngx_gcc_atomic_sparc64.h" |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
235 |
561 | 236 #endif |
493 | 237 |
238 | |
613 | 239 #elif ( __powerpc__ || __POWERPC__ ) |
493 | 240 |
241 #define NGX_HAVE_ATOMIC_OPS 1 | |
242 | |
243 #if (NGX_PTR_SIZE == 8) | |
561 | 244 |
245 typedef int64_t ngx_atomic_int_t; | |
246 typedef uint64_t ngx_atomic_uint_t; | |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
247 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) |
561 | 248 |
493 | 249 #else |
561 | 250 |
251 typedef int32_t ngx_atomic_int_t; | |
252 typedef uint32_t ngx_atomic_uint_t; | |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
253 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
561 | 254 |
493 | 255 #endif |
256 | |
495 | 257 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
493 | 258 |
259 | |
561 | 260 #include "ngx_gcc_atomic_ppc.h" |
493 | 261 |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
262 #endif |
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
263 |
493 | 264 |
561 | 265 #if !(NGX_HAVE_ATOMIC_OPS) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
266 |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
267 #define NGX_HAVE_ATOMIC_OPS 0 |
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
268 |
561 | 269 typedef int32_t ngx_atomic_int_t; |
270 typedef uint32_t ngx_atomic_uint_t; | |
495 | 271 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
3165
7658e9c7e814
use parents around NGX_ATOMIC_T_LEN value
Igor Sysoev <igor@sysoev.ru>
parents:
2133
diff
changeset
|
272 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
273 |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
274 |
495 | 275 static ngx_inline ngx_atomic_uint_t |
276 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
277 ngx_atomic_uint_t set) | |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
278 { |
571 | 279 if (*lock == old) { |
561 | 280 *lock = set; |
281 return 1; | |
282 } | |
283 | |
284 return 0; | |
285 } | |
286 | |
287 | |
288 static ngx_inline ngx_atomic_int_t | |
289 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) | |
290 { | |
291 ngx_atomic_int_t old; | |
292 | |
293 old = *value; | |
294 *value += add; | |
295 | |
296 return old; | |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
297 } |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
298 |
571 | 299 #define ngx_memory_barrier() |
611 | 300 #define ngx_cpu_pause() |
571 | 301 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
302 #endif |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
303 |
939
782cf4c13b8d
use MacOSX atomic(3) and barrier(3) operations
Igor Sysoev <igor@sysoev.ru>
parents:
613
diff
changeset
|
304 |
611 | 305 void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); |
373
018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
Igor Sysoev <igor@sysoev.ru>
parents:
371
diff
changeset
|
306 |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
307 #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) |
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
308 #define ngx_unlock(lock) *(lock) = 0 |
370
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
309 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
310 |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
311 #endif /* _NGX_ATOMIC_H_INCLUDED_ */ |