comparison src/core/ngx_atomic.h @ 266:5238e93961a1

nginx-0.0.2-2004-02-23-23:57:12 import
author Igor Sysoev <igor@sysoev.ru>
date Mon, 23 Feb 2004 20:57:12 +0000
parents f536f91e8e99
children 83205e0b5522
comparison
equal deleted inserted replaced
265:6468241715e6 266:5238e93961a1
4 4
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 #ifdef __i386__
10
11 typedef uint32_t ngx_atomic_t;
12
13 #if (NGX_SMP)
14 #define NGX_SMP_LOCK "lock"
15 #else
16 #define NGX_SMP_LOCK
17 #endif
18
19
20 static ngx_inline uint32_t ngx_atomic_inc(ngx_atomic_t *value)
21 {
22 uint32_t old;
23
24 __asm__ __volatile ("
25
26 movl $1, %0
27 " NGX_SMP_LOCK
28 " xaddl %0, %1
29
30 ": "=a" (old) : "m" (*value));
31
32 return old;
33 }
34
35
36 static ngx_inline uint32_t ngx_atomic_dec(ngx_atomic_t *value)
37 {
38 uint32_t old;
39
40 __asm__ __volatile ("
41
42 movl $-1, %0
43 " NGX_SMP_LOCK
44 " xaddl %0, %1
45
46 ": "=a" (old) : "m" (*value));
47
48 return old;
49 }
50
51
52 static ngx_inline uint32_t ngx_atomic_cmp_set(ngx_atomic_t *lock,
53 ngx_atomic_t old,
54 ngx_atomic_t set)
55 {
56 uint32_t res;
57
58 __asm__ __volatile ("
59
60 " NGX_SMP_LOCK
61 " cmpxchgl %3, %1
62 setzb %%al
63 movzbl %%al, %0
64
65 ": "=a" (res) : "m" (*lock), "a" (old), "q" (set));
66
67 return res;
68 }
69
70 #else
71
72 typedef uint32_t ngx_atomic_t;
73
9 /* STUB */ 74 /* STUB */
10 #define ngx_atomic_inc(x) x++; 75 #define ngx_atomic_inc(x) x++;
11 #define ngx_atomic_dec(x) x--; 76 #define ngx_atomic_dec(x) x--;
77 #define ngx_atomic_cmp_set(lock, old, set) 1;
78 /**/
79
80 #endif
12 81
13 82
14 #endif /* _NGX_ATOMIC_H_INCLUDED_ */ 83 #endif /* _NGX_ATOMIC_H_INCLUDED_ */