comparison src/os/unix/ngx_atomic.h @ 3362:b57a4a704f3c

GCC 4.1 builtin atomic operations
author Igor Sysoev <igor@sysoev.ru>
date Wed, 25 Nov 2009 17:34:35 +0000
parents 7658e9c7e814
children b4aa418af6ef
comparison
equal deleted inserted replaced
3361:79884a49e46f 3362:b57a4a704f3c
58 #define ngx_cpu_pause() 58 #define ngx_cpu_pause()
59 59
60 typedef volatile ngx_atomic_uint_t ngx_atomic_t; 60 typedef volatile ngx_atomic_uint_t ngx_atomic_t;
61 61
62 62
63 #else /* !(NGX_DARWIN) */ 63 #elif (NGX_HAVE_GCC_ATOMIC)
64 64
65 65 /* GCC 4.1 builtin atomic operations */
66 #if ( __i386__ || __i386 ) 66
67 #define NGX_HAVE_ATOMIC_OPS 1
68
69 typedef long ngx_atomic_int_t;
70 typedef unsigned long ngx_atomic_uint_t;
71
72 #if (NGX_PTR_SIZE == 8)
73 #define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
74 #else
75 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
76 #endif
77
78 typedef volatile ngx_atomic_uint_t ngx_atomic_t;
79
80
81 #define ngx_atomic_cmp_set(lock, old, set) \
82 __sync_bool_compare_and_swap(lock, old, set)
83
84 #define ngx_atomic_fetch_add(value, add) \
85 __sync_fetch_and_add(value, add)
86
87 #define ngx_memory_barrier() __sync_synchronize()
88
89 #if ( __i386__ || __i386 || __amd64__ || __amd64 )
90 #define ngx_cpu_pause() __asm__ ("pause")
91 #else
92 #define ngx_cpu_pause()
93 #endif
94
95
96 #elif ( __i386__ || __i386 )
67 97
68 typedef int32_t ngx_atomic_int_t; 98 typedef int32_t ngx_atomic_int_t;
69 typedef uint32_t ngx_atomic_uint_t; 99 typedef uint32_t ngx_atomic_uint_t;
70 typedef volatile ngx_atomic_uint_t ngx_atomic_t; 100 typedef volatile ngx_atomic_uint_t ngx_atomic_t;
71 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) 101 #define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
200 230
201 typedef volatile ngx_atomic_uint_t ngx_atomic_t; 231 typedef volatile ngx_atomic_uint_t ngx_atomic_t;
202 232
203 233
204 #include "ngx_gcc_atomic_ppc.h" 234 #include "ngx_gcc_atomic_ppc.h"
205
206
207 #endif
208 235
209 #endif 236 #endif
210 237
211 238
212 #if !(NGX_HAVE_ATOMIC_OPS) 239 #if !(NGX_HAVE_ATOMIC_OPS)