Mercurial > hg > nginx
comparison src/os/unix/ngx_atomic.h @ 373:018569a8f09c
nginx-0.0.7-2004-06-30-19:30:41 import
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 30 Jun 2004 15:30:41 +0000 |
parents | src/core/ngx_atomic.h@780e93985b93 |
children | bd39260a1383 |
comparison
equal
deleted
inserted
replaced
372:c9fdfccebc49 | 373:018569a8f09c |
---|---|
1 #ifndef _NGX_ATOMIC_H_INCLUDED_ | |
2 #define _NGX_ATOMIC_H_INCLUDED_ | |
3 | |
4 | |
5 #include <ngx_config.h> | |
6 #include <ngx_core.h> | |
7 | |
8 | |
9 #if ( __i386__ || __amd64__ ) | |
10 | |
11 typedef volatile 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 NGX_SMP_LOCK | |
27 " xaddl %0, %2; " | |
28 " incl %0; " | |
29 | |
30 : "=q" (old) : "0" (1), "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 NGX_SMP_LOCK | |
43 " xaddl %0, %1; " | |
44 " decl %0; " | |
45 | |
46 : "=q" (old) : "0" (-1), "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 " setz %%al; " | |
63 " movzbl %%al, %0; " | |
64 | |
65 : "=a" (res) : "m" (*lock), "a" (old), "q" (set)); | |
66 | |
67 return res; | |
68 } | |
69 | |
70 | |
71 #else | |
72 | |
73 typedef volatile uint32_t ngx_atomic_t; | |
74 | |
75 /* STUB */ | |
76 #define ngx_atomic_inc(x) (*(x))++; | |
77 #define ngx_atomic_dec(x) (*(x))--; | |
78 #define ngx_atomic_cmp_set(lock, old, set) 1 | |
79 /**/ | |
80 | |
81 #endif | |
82 | |
83 | |
84 void ngx_spinlock(ngx_atomic_t *lock, ngx_uint_t spin); | |
85 | |
86 #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1)) | |
87 #define ngx_unlock(lock) *(lock) = 0 | |
88 | |
89 | |
90 #endif /* _NGX_ATOMIC_H_INCLUDED_ */ |