mirror of
https://github.com/nginx/nginx.git
synced 2025-06-07 09:42:39 +08:00
use MacOSX atomic(3) and barrier(3) operations
This commit is contained in:
parent
d8d4f1b1fd
commit
28abaf70ff
@ -12,6 +12,62 @@
|
||||
#include <ngx_core.h>
|
||||
|
||||
|
||||
#if (NGX_DARWIN)
|
||||
|
||||
/*
|
||||
* use MacOSX 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;
|
||||
@ -139,6 +195,8 @@ typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
||||
#include "ngx_gcc_atomic_ppc.h"
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -181,6 +239,7 @@ ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
|
||||
|
||||
#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))
|
||||
|
Loading…
Reference in New Issue
Block a user