From 213cad8e815a5a017a1fe2b254b5c041ea830d86 Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Wed, 25 Nov 2009 17:55:25 +0000 Subject: [PATCH] libatomic_ops support --- auto/lib/conf | 5 +++++ auto/lib/libatomic/conf | 38 ++++++++++++++++++++++++++++++++++++++ auto/lib/libatomic/make | 13 +++++++++++++ auto/lib/make | 4 ++++ auto/options | 8 ++++++++ src/os/unix/ngx_atomic.h | 26 +++++++++++++++++++++++++- 6 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 auto/lib/libatomic/conf create mode 100644 auto/lib/libatomic/make diff --git a/auto/lib/conf b/auto/lib/conf index edb15bc3b..60e891b9e 100644 --- a/auto/lib/conf +++ b/auto/lib/conf @@ -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 diff --git a/auto/lib/libatomic/conf b/auto/lib/libatomic/conf new file mode 100644 index 000000000..a06ab1a88 --- /dev/null +++ b/auto/lib/libatomic/conf @@ -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 " + 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 diff --git a/auto/lib/libatomic/make b/auto/lib/libatomic/make new file mode 100644 index 000000000..e1672e324 --- /dev/null +++ b/auto/lib/libatomic/make @@ -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 diff --git a/auto/lib/make b/auto/lib/make index 170311c63..f22767eb4 100644 --- a/auto/lib/make +++ b/auto/lib/make @@ -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 diff --git a/auto/options b/auto/options index a7c33c7b1..f3c82d2c6 100644 --- a/auto/options +++ b/auto/options @@ -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 diff --git a/src/os/unix/ngx_atomic.h b/src/os/unix/ngx_atomic.h index b478cc8d4..39b3e6b7f 100644 --- a/src/os/unix/ngx_atomic.h +++ b/src/os/unix/ngx_atomic.h @@ -12,7 +12,31 @@ #include -#if (NGX_DARWIN_ATOMIC) +#if (NGX_HAVE_LIBATOMIC) + +#include + +#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