Mercurial > hg > nginx-vendor-0-5
diff src/os/unix/ngx_atomic.h @ 270:6eb1e38f0f1f NGINX_0_5_5
nginx 0.5.5
*) Change: the -v switch does not show compiler information any more.
*) Feature: the -V switch.
*) Feature: the "worker_rlimit_core" directive supports size in K, M,
and G.
*) Bugfix: the nginx.pm module now could be installed by an
unprivileged user.
*) Bugfix: a segmentation fault might occur if the $r->request_body or
$r->request_body_file methods were used.
*) Bugfix: the ppc platform specific bugs.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Sun, 24 Dec 2006 00:00:00 +0300 |
parents | 6be073125f2e |
children | 3021f899881a |
line wrap: on
line diff
--- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -12,6 +12,62 @@ #include <ngx_core.h> +#if (NGX_DARWIN_ATOMIC) + +/* + * use Darwin 8 atomic(3) and barrier(3) operations + * optimized at run-time for UP and SMP + */ + +#include <libkern/OSAtomic.h> + +/* "bool" conflicts with perl's CORE/handy.h + * "true" and "false" conflict with nginx, and of course we can rename them, + * but we need to undef "bool" anyway + */ +#undef bool +#undef true +#undef false + + +#define NGX_HAVE_ATOMIC_OPS 1 + +#if (NGX_PTR_SIZE == 8) + +typedef int64_t ngx_atomic_int_t; +typedef uint64_t ngx_atomic_uint_t; +#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1 + +#define ngx_atomic_cmp_set(lock, old, new) \ + OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock) + +#define ngx_atomic_fetch_add(value, add) \ + (OSAtomicAdd64(add, (int64_t *) value) - add) + +#else + +typedef int32_t ngx_atomic_int_t; +typedef uint32_t ngx_atomic_uint_t; +#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1 + +#define ngx_atomic_cmp_set(lock, old, new) \ + OSAtomicCompareAndSwap32Barrier(old, new, (int32_t *) lock) + +#define ngx_atomic_fetch_add(value, add) \ + (OSAtomicAdd32(add, (int32_t *) value) - add) + +#endif + +#define ngx_memory_barrier() OSMemoryBarrier() + +#define ngx_cpu_pause() + +typedef volatile ngx_atomic_uint_t ngx_atomic_t; + + +#else /* !(NGX_DARWIN) */ + + #if ( __i386__ || __i386 ) typedef int32_t ngx_atomic_int_t; @@ -141,6 +197,8 @@ typedef volatile ngx_atomic_uint_t ngx_ #endif +#endif + #if !(NGX_HAVE_ATOMIC_OPS) @@ -181,6 +239,7 @@ ngx_atomic_fetch_add(ngx_atomic_t *value #endif + void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin); #define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1))