comparison src/core/ngx_atomic.h @ 267:83205e0b5522

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