libatomic_ops support

This commit is contained in:
Igor Sysoev 2009-11-25 17:55:25 +00:00
parent 89d635fa5d
commit 213cad8e81
6 changed files with 93 additions and 1 deletions

View File

@ -70,6 +70,11 @@ fi
if [ $HTTP_GEOIP = YES ]; then
. auto/lib/geoip/conf
fi
if [ $NGX_GOOGLE_PERFTOOLS = YES ]; then
. auto/lib/google-perftools/conf
fi
if [ $NGX_LIBATOMIC != NO ]; then
. auto/lib/libatomic/conf
fi

38
auto/lib/libatomic/conf Normal file
View File

@ -0,0 +1,38 @@
# Copyright (C) Igor Sysoev
if [ $NGX_LIBATOMIC != YES ]; then
have=NGX_HAVE_LIBATOMIC . auto/have
CORE_INCS="$CORE_INCS $NGX_LIBATOMIC/src"
LINK_DEPS="$LINK_DEPS $NGX_LIBATOMIC/src/libatomic_ops.a"
CORE_LIBS="$CORE_LIBS $NGX_LIBATOMIC/src/libatomic_ops.a"
else
ngx_feature="atomic_ops library"
ngx_feature_name=NGX_HAVE_LIBATOMIC
ngx_feature_run=no
ngx_feature_incs="#include <atomic_ops.h>"
ngx_feature_path=
ngx_feature_libs="-latomic_ops"
ngx_feature_test="AO_t *n;
AO_compare_and_swap(n, 0, 1);
AO_fetch_and_add(n, 1);
AO_nop();"
. auto/feature
if [ $ngx_found = yes ]; then
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
else
cat << END
$0: error: libatomic_ops library was not found.
END
exit 1
fi
fi

13
auto/lib/libatomic/make Normal file
View File

@ -0,0 +1,13 @@
# Copyright (C) Igor Sysoev
cat << END >> $NGX_MAKEFILE
$NGX_LIBATOMIC/src/libatomic_ops.a: $NGX_LIBATOMIC/Makefile
cd $NGX_LIBATOMIC && make
$NGX_LIBATOMIC/Makefile: $NGX_MAKEFILE
cd $NGX_LIBATOMIC && ./configure
END

View File

@ -22,6 +22,10 @@ if [ $ZLIB != NONE -a $ZLIB != NO -a $ZLIB != YES ]; then
. auto/lib/zlib/make
fi
if [ $NGX_LIBATOMIC != NO -a $NGX_LIBATOMIC != YES ]; then
. auto/lib/libatomic/make
fi
if [ $USE_PERL = YES ]; then
. auto/lib/perl/make
fi

View File

@ -132,6 +132,8 @@ USE_LIBGD=NO
NGX_GOOGLE_PERFTOOLS=NO
NGX_CPP_TEST=NO
NGX_LIBATOMIC=NO
NGX_CPU_CACHE_LINE=
opt=
@ -266,6 +268,9 @@ do
--with-zlib-opt=*) ZLIB_OPT="$value" ;;
--with-zlib-asm=*) ZLIB_ASM="$value" ;;
--with-libatomic) NGX_LIBATOMIC=YES ;;
--with-libatomic=*) NGX_LIBATOMIC="$value" ;;
--test-build-devpoll) NGX_TEST_BUILD_DEVPOLL=YES ;;
--test-build-eventport) NGX_TEST_BUILD_EVENTPORT=YES ;;
--test-build-epoll) NGX_TEST_BUILD_EPOLL=YES ;;
@ -400,6 +405,9 @@ cat << END
for specified CPU, the valid values:
pentium, pentiumpro
--with-libatomic force libatomic_ops library usage
--with-libatomic=DIR set path to libatomic_ops library sources
--with-openssl=DIR set path to OpenSSL library sources
--with-openssl-opt=OPTIONS set additional options for OpenSSL building

View File

@ -12,7 +12,31 @@
#include <ngx_core.h>
#if (NGX_DARWIN_ATOMIC)
#if (NGX_HAVE_LIBATOMIC)
#include <atomic_ops.h>
#define NGX_HAVE_ATOMIC_OPS 1
typedef long ngx_atomic_int_t;
typedef AO_t ngx_atomic_uint_t;
typedef volatile ngx_atomic_uint_t ngx_atomic_t;
#if (NGX_PTR_SIZE == 8)
#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
#else
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
#endif
#define ngx_atomic_cmp_set(lock, old, new) \
AO_compare_and_swap(lock, old, new)
#define ngx_atomic_fetch_add(value, add) \
AO_fetch_and_add(value, add)
#define ngx_memory_barrier() AO_nop()
#define ngx_cpu_pause()
#elif (NGX_DARWIN_ATOMIC)
/*
* use Darwin 8 atomic(3) and barrier(3) operations