Mercurial > hg > nginx-quic
annotate src/os/unix/ngx_atomic.h @ 809:da9c1521319d
AUTH PLAIN LOGIN CRAM-MD5
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 24 Oct 2006 18:38:31 +0000 |
parents | c73c5c58c619 |
children | 782cf4c13b8d |
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 |
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
|
4 */ |
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 |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 |
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 #include <ngx_config.h> |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 #include <ngx_core.h> |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 |
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
14 |
547 | 15 #if ( __i386__ || __i386 ) |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
16 |
561 | 17 typedef int32_t ngx_atomic_int_t; |
18 typedef uint32_t ngx_atomic_uint_t; | |
495 | 19 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
561 | 20 #define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1 |
493 | 21 |
22 | |
561 | 23 #if ( __SUNPRO_C ) |
493 | 24 |
561 | 25 #define NGX_HAVE_ATOMIC_OPS 1 |
493 | 26 |
561 | 27 ngx_atomic_uint_t |
28 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
29 ngx_atomic_uint_t set); | |
493 | 30 |
561 | 31 ngx_atomic_int_t |
32 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add); | |
493 | 33 |
561 | 34 /* the code in src/os/unix/ngx_sunpro_x86.il */ |
493 | 35 |
563 | 36 #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") |
611 | 37 #define ngx_cpu_pause() __asm ("pause") |
563 | 38 |
493 | 39 |
561 | 40 #else /* ( __GNUC__ || __INTEL_COMPILER ) */ |
41 | |
42 #define NGX_HAVE_ATOMIC_OPS 1 | |
493 | 43 |
561 | 44 #include "ngx_gcc_atomic_x86.h" |
493 | 45 |
561 | 46 #endif |
493 | 47 |
48 | |
547 | 49 #elif ( __amd64__ || __amd64 ) |
493 | 50 |
561 | 51 typedef int64_t ngx_atomic_int_t; |
52 typedef uint64_t ngx_atomic_uint_t; | |
495 | 53 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
561 | 54 #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
|
55 |
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
56 |
561 | 57 #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
|
58 |
561 | 59 #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
|
60 |
561 | 61 ngx_atomic_uint_t |
62 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
63 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
|
64 |
561 | 65 ngx_atomic_int_t |
66 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
|
67 |
561 | 68 /* 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
|
69 |
563 | 70 #define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile") |
611 | 71 #define ngx_cpu_pause() __asm ("pause") |
563 | 72 |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
73 |
561 | 74 #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
|
75 |
561 | 76 #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
|
77 |
561 | 78 #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
|
79 |
561 | 80 #endif |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
81 |
301
744965ec6275
nginx-0.0.3-2004-03-31-19:26:46 import
Igor Sysoev <igor@sysoev.ru>
parents:
300
diff
changeset
|
82 |
547 | 83 #elif ( __sparc__ || __sparcv9 ) |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
84 |
561 | 85 #if (NGX_PTR_SIZE == 8) |
86 | |
87 typedef int64_t ngx_atomic_int_t; | |
88 typedef uint64_t ngx_atomic_uint_t; | |
89 #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
|
90 |
493 | 91 #else |
561 | 92 |
93 typedef int32_t ngx_atomic_int_t; | |
94 typedef uint32_t ngx_atomic_uint_t; | |
95 #define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1 | |
96 | |
493 | 97 #endif |
98 | |
495 | 99 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
|
100 |
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
101 |
561 | 102 #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
|
103 |
561 | 104 #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
|
105 |
561 | 106 #include "ngx_sunpro_atomic_sparc64.h" |
493 | 107 |
425
bd39260a1383
nginx-0.0.10-2004-09-14-19:55:24 import
Igor Sysoev <igor@sysoev.ru>
parents:
373
diff
changeset
|
108 |
561 | 109 #else /* ( __GNUC__ || __INTEL_COMPILER ) */ |
493 | 110 |
561 | 111 #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
|
112 |
561 | 113 #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
|
114 |
561 | 115 #endif |
493 | 116 |
117 | |
613 | 118 #elif ( __powerpc__ || __POWERPC__ ) |
493 | 119 |
120 #define NGX_HAVE_ATOMIC_OPS 1 | |
121 | |
122 #if (NGX_PTR_SIZE == 8) | |
561 | 123 |
124 typedef int64_t ngx_atomic_int_t; | |
125 typedef uint64_t ngx_atomic_uint_t; | |
126 #define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1 | |
127 | |
493 | 128 #else |
561 | 129 |
130 typedef int32_t ngx_atomic_int_t; | |
131 typedef uint32_t ngx_atomic_uint_t; | |
132 #define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1 | |
133 | |
493 | 134 #endif |
135 | |
495 | 136 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
493 | 137 |
138 | |
561 | 139 #include "ngx_gcc_atomic_ppc.h" |
493 | 140 |
141 | |
561 | 142 #endif |
493 | 143 |
144 | |
561 | 145 #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
|
146 |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
147 #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
|
148 |
561 | 149 typedef int32_t ngx_atomic_int_t; |
150 typedef uint32_t ngx_atomic_uint_t; | |
495 | 151 typedef volatile ngx_atomic_uint_t ngx_atomic_t; |
561 | 152 #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
|
153 |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
154 |
495 | 155 static ngx_inline ngx_atomic_uint_t |
156 ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old, | |
157 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
|
158 { |
571 | 159 if (*lock == old) { |
561 | 160 *lock = set; |
161 return 1; | |
162 } | |
163 | |
164 return 0; | |
165 } | |
166 | |
167 | |
168 static ngx_inline ngx_atomic_int_t | |
169 ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add) | |
170 { | |
171 ngx_atomic_int_t old; | |
172 | |
173 old = *value; | |
174 *value += add; | |
175 | |
176 return old; | |
435
5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
Igor Sysoev <igor@sysoev.ru>
parents:
433
diff
changeset
|
177 } |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
178 |
571 | 179 #define ngx_memory_barrier() |
611 | 180 #define ngx_cpu_pause() |
571 | 181 |
266
5238e93961a1
nginx-0.0.2-2004-02-23-23:57:12 import
Igor Sysoev <igor@sysoev.ru>
parents:
213
diff
changeset
|
182 #endif |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
183 |
611 | 184 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
|
185 |
371
780e93985b93
nginx-0.0.7-2004-06-28-20:05:02 import
Igor Sysoev <igor@sysoev.ru>
parents:
370
diff
changeset
|
186 #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
|
187 #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
|
188 |
54f76b0b8dca
nginx-0.0.7-2004-06-27-22:01:57 import
Igor Sysoev <igor@sysoev.ru>
parents:
302
diff
changeset
|
189 |
212
679f60139863
nginx-0.0.1-2003-12-19-11:15:11 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
190 #endif /* _NGX_ATOMIC_H_INCLUDED_ */ |