Mercurial > hg > nginx
diff 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 |
line wrap: on
line diff
--- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -60,10 +60,40 @@ typedef uint32_t ngx_ typedef volatile ngx_atomic_uint_t ngx_atomic_t; -#else /* !(NGX_DARWIN) */ +#elif (NGX_HAVE_GCC_ATOMIC) + +/* GCC 4.1 builtin atomic operations */ + +#define NGX_HAVE_ATOMIC_OPS 1 + +typedef long ngx_atomic_int_t; +typedef unsigned long ngx_atomic_uint_t; + +#if (NGX_PTR_SIZE == 8) +#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1) +#else +#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1) +#endif + +typedef volatile ngx_atomic_uint_t ngx_atomic_t; -#if ( __i386__ || __i386 ) +#define ngx_atomic_cmp_set(lock, old, set) \ + __sync_bool_compare_and_swap(lock, old, set) + +#define ngx_atomic_fetch_add(value, add) \ + __sync_fetch_and_add(value, add) + +#define ngx_memory_barrier() __sync_synchronize() + +#if ( __i386__ || __i386 || __amd64__ || __amd64 ) +#define ngx_cpu_pause() __asm__ ("pause") +#else +#define ngx_cpu_pause() +#endif + + +#elif ( __i386__ || __i386 ) typedef int32_t ngx_atomic_int_t; typedef uint32_t ngx_atomic_uint_t; @@ -203,9 +233,6 @@ typedef volatile ngx_atomic_uint_t ngx_ #include "ngx_gcc_atomic_ppc.h" - -#endif - #endif