2004-09-28 16:34:51 +08:00
|
|
|
|
|
|
|
/*
|
2004-09-30 00:00:49 +08:00
|
|
|
* Copyright (C) Igor Sysoev
|
2004-09-28 16:34:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2003-12-19 16:15:11 +08:00
|
|
|
#ifndef _NGX_ATOMIC_H_INCLUDED_
|
|
|
|
#define _NGX_ATOMIC_H_INCLUDED_
|
|
|
|
|
|
|
|
|
|
|
|
#include <ngx_config.h>
|
|
|
|
#include <ngx_core.h>
|
|
|
|
|
|
|
|
|
2005-09-30 22:41:25 +08:00
|
|
|
#if ( __i386__ || __i386 )
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int32_t ngx_atomic_int_t;
|
|
|
|
typedef uint32_t ngx_atomic_uint_t;
|
2005-02-24 20:29:09 +08:00
|
|
|
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
|
2004-02-24 04:57:12 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#if ( __SUNPRO_C )
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_uint_t
|
2005-02-24 20:29:09 +08:00
|
|
|
ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_uint_t set);
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_int_t
|
|
|
|
ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add);
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
/* the code in src/os/unix/ngx_sunpro_x86.il */
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-19 20:33:58 +08:00
|
|
|
#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile")
|
2006-02-08 23:33:12 +08:00
|
|
|
#define ngx_cpu_pause() __asm ("pause")
|
2005-10-19 20:33:58 +08:00
|
|
|
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#else /* ( __GNUC__ || __INTEL_COMPILER ) */
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#include "ngx_gcc_atomic_x86.h"
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2004-09-23 00:18:21 +08:00
|
|
|
#endif
|
|
|
|
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#elif ( __amd64__ || __amd64 )
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int64_t ngx_atomic_int_t;
|
|
|
|
typedef uint64_t ngx_atomic_uint_t;
|
|
|
|
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#if ( __SUNPRO_C )
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_uint_t
|
2005-02-24 20:29:09 +08:00
|
|
|
ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_uint_t set);
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_int_t
|
|
|
|
ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add);
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
/* the code in src/os/unix/ngx_sunpro_amd64.il */
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-19 20:33:58 +08:00
|
|
|
#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile")
|
2006-02-08 23:33:12 +08:00
|
|
|
#define ngx_cpu_pause() __asm ("pause")
|
2005-10-19 20:33:58 +08:00
|
|
|
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#else /* ( __GNUC__ || __INTEL_COMPILER ) */
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2004-09-23 00:18:21 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#include "ngx_gcc_atomic_amd64.h"
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#endif
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#elif ( __sparc__ || __sparcv9 )
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#if (NGX_PTR_SIZE == 8)
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int64_t ngx_atomic_int_t;
|
|
|
|
typedef uint64_t ngx_atomic_uint_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#else
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int32_t ngx_atomic_int_t;
|
|
|
|
typedef uint32_t ngx_atomic_uint_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#endif
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#if ( __SUNPRO_C )
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#include "ngx_sunpro_atomic_sparc64.h"
|
2004-09-14 23:55:24 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#else /* ( __GNUC__ || __INTEL_COMPILER ) */
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#include "ngx_gcc_atomic_sparc64.h"
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#endif
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
|
2006-02-16 23:26:46 +08:00
|
|
|
#elif ( __powerpc__ || __POWERPC__ )
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
#define NGX_HAVE_ATOMIC_OPS 1
|
|
|
|
|
|
|
|
#if (NGX_PTR_SIZE == 8)
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int64_t ngx_atomic_int_t;
|
|
|
|
typedef uint64_t ngx_atomic_uint_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-9223372036854775808") - 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#else
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int32_t ngx_atomic_int_t;
|
|
|
|
typedef uint32_t ngx_atomic_uint_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#endif
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#include "ngx_gcc_atomic_ppc.h"
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#endif
|
2004-09-14 23:55:24 +08:00
|
|
|
|
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#if !(NGX_HAVE_ATOMIC_OPS)
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
#define NGX_HAVE_ATOMIC_OPS 0
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
typedef int32_t ngx_atomic_int_t;
|
|
|
|
typedef uint32_t ngx_atomic_uint_t;
|
|
|
|
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
|
|
|
|
#define NGX_ATOMIC_T_LEN sizeof("-2147483648") - 1
|
2005-02-22 22:40:13 +08:00
|
|
|
|
|
|
|
|
2005-02-24 20:29:09 +08:00
|
|
|
static ngx_inline ngx_atomic_uint_t
|
|
|
|
ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
|
2005-10-12 21:50:36 +08:00
|
|
|
ngx_atomic_uint_t set)
|
2005-02-22 22:40:13 +08:00
|
|
|
{
|
2005-10-27 23:46:13 +08:00
|
|
|
if (*lock == old) {
|
2005-10-12 21:50:36 +08:00
|
|
|
*lock = set;
|
|
|
|
return 1;
|
|
|
|
}
|
2004-09-14 23:55:24 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2005-02-22 22:40:13 +08:00
|
|
|
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
static ngx_inline ngx_atomic_int_t
|
|
|
|
ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
|
|
|
|
{
|
|
|
|
ngx_atomic_int_t old;
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
old = *value;
|
|
|
|
*value += add;
|
2004-09-23 00:18:21 +08:00
|
|
|
|
2005-10-12 21:50:36 +08:00
|
|
|
return old;
|
2004-09-23 00:18:21 +08:00
|
|
|
}
|
2004-02-24 04:57:12 +08:00
|
|
|
|
2005-10-27 23:46:13 +08:00
|
|
|
#define ngx_memory_barrier()
|
2006-02-08 23:33:12 +08:00
|
|
|
#define ngx_cpu_pause()
|
2003-12-19 16:15:11 +08:00
|
|
|
|
2005-10-27 23:46:13 +08:00
|
|
|
#endif
|
2003-12-19 16:15:11 +08:00
|
|
|
|
2006-02-08 23:33:12 +08:00
|
|
|
void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin);
|
2004-06-30 23:30:41 +08:00
|
|
|
|
2004-06-29 00:05:02 +08:00
|
|
|
#define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1))
|
|
|
|
#define ngx_unlock(lock) *(lock) = 0
|
2004-06-28 02:01:57 +08:00
|
|
|
|
|
|
|
|
2003-12-19 16:15:11 +08:00
|
|
|
#endif /* _NGX_ATOMIC_H_INCLUDED_ */
|