Mercurial > hg > nginx
comparison src/os/unix/ngx_atomic.h @ 435:5cdc4838d4e8
nginx-0.0.11-2004-09-22-20:18:21 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 22 Sep 2004 16:18:21 +0000 |
parents | 9a97dcdd2421 |
children | da8c5707af39 |
comparison
equal
deleted
inserted
replaced
434:8998b09f89e9 | 435:5cdc4838d4e8 |
---|---|
5 #include <ngx_config.h> | 5 #include <ngx_config.h> |
6 #include <ngx_core.h> | 6 #include <ngx_core.h> |
7 | 7 |
8 | 8 |
9 #if ( __i386__ || __amd64__ ) | 9 #if ( __i386__ || __amd64__ ) |
10 | |
11 #define NGX_HAVE_ATOMIC_OPS 1 | |
10 | 12 |
11 typedef volatile uint32_t ngx_atomic_t; | 13 typedef volatile uint32_t ngx_atomic_t; |
12 | 14 |
13 #if (NGX_SMP) | 15 #if (NGX_SMP) |
14 #define NGX_SMP_LOCK "lock;" | 16 #define NGX_SMP_LOCK "lock;" |
31 | 33 |
32 return old; | 34 return old; |
33 } | 35 } |
34 | 36 |
35 | 37 |
38 #if 0 | |
39 | |
36 static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value) | 40 static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value) |
37 { | 41 { |
38 uint32_t old; | 42 uint32_t old; |
39 | 43 |
40 __asm__ volatile ( | 44 __asm__ volatile ( |
45 | 49 |
46 : "=q" (old) : "0" (-1), "m" (*value)); | 50 : "=q" (old) : "0" (-1), "m" (*value)); |
47 | 51 |
48 return old; | 52 return old; |
49 } | 53 } |
54 | |
55 #endif | |
50 | 56 |
51 | 57 |
52 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, | 58 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, |
53 ngx_atomic_t old, | 59 ngx_atomic_t old, |
54 ngx_atomic_t set) | 60 ngx_atomic_t set) |
67 return res; | 73 return res; |
68 } | 74 } |
69 | 75 |
70 | 76 |
71 #elif ( __sparc__ ) | 77 #elif ( __sparc__ ) |
78 | |
79 #define NGX_HAVE_ATOMIC_OPS 1 | |
72 | 80 |
73 typedef volatile uint32_t ngx_atomic_t; | 81 typedef volatile uint32_t ngx_atomic_t; |
74 | 82 |
75 | 83 |
76 static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value) | 84 static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value) |
97 old = res; | 105 old = res; |
98 } | 106 } |
99 } | 107 } |
100 | 108 |
101 | 109 |
102 /* STUB */ | |
103 #define ngx_atomic_dec(x) (*(x))--; | |
104 /**/ | |
105 | |
106 | |
107 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, | 110 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, |
108 ngx_atomic_t old, | 111 ngx_atomic_t old, |
109 ngx_atomic_t set) | 112 ngx_atomic_t set) |
110 { | 113 { |
111 uint32_t res = (uint32_t) set; | 114 uint32_t res = (uint32_t) set; |
119 return (res == old); | 122 return (res == old); |
120 } | 123 } |
121 | 124 |
122 #else | 125 #else |
123 | 126 |
127 #define NGX_HAVE_ATOMIC_OPS 0 | |
128 | |
124 typedef volatile uint32_t ngx_atomic_t; | 129 typedef volatile uint32_t ngx_atomic_t; |
125 | 130 |
126 /* STUB */ | 131 #define ngx_atomic_inc(x) ++(*(x)); |
127 #define ngx_atomic_inc(x) ++(*(x)); | 132 |
128 #define ngx_atomic_dec(x) --(*(x)); | 133 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock, |
129 #define ngx_atomic_cmp_set(lock, old, set) 1 | 134 ngx_atomic_t old, |
130 /**/ | 135 ngx_atomic_t set) |
136 { | |
137 return 1; | |
138 } | |
131 | 139 |
132 #endif | 140 #endif |
133 | 141 |
134 | 142 |
135 void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); | 143 void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); |