cfed068c1d
Compiler built-ins used, where possible. Necessary configure checks added. New macros: nxt_atomic_or_fetch(ptr, val) nxt_atomic_and_fetch(ptr, val) Syntax and behaviour is similar to __sync_or_and_fetch and __sync_and_and_fetch GCC build-ins.
122 lines
3.8 KiB
Text
122 lines
3.8 KiB
Text
|
|
# Copyright (C) Igor Sysoev
|
|
# Copyright (C) NGINX, Inc.
|
|
|
|
|
|
# GCC 4.1+ builtin atomic operations.
|
|
|
|
nxt_feature="GCC builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_GCC_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
nxt_feature_test="int main() {
|
|
long n = 0;
|
|
|
|
if (!__sync_bool_compare_and_swap(&n, 0, 3))
|
|
return 1;
|
|
if (__sync_fetch_and_add(&n, 1) != 3)
|
|
return 1;
|
|
if (__sync_lock_test_and_set(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
if (__sync_or_and_fetch(&n, 2) != 7)
|
|
return 1;
|
|
if (__sync_and_and_fetch(&n, 5) != 5)
|
|
return 1;
|
|
__sync_lock_release(&n);
|
|
if (n != 0)
|
|
return 1;
|
|
return 0;
|
|
}"
|
|
. auto/feature
|
|
|
|
|
|
# Solaris 10 builtin atomic operations.
|
|
|
|
if [ $nxt_found = no ]; then
|
|
|
|
nxt_feature="Solaris builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_SOLARIS_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
nxt_feature_test="#include <atomic.h>
|
|
|
|
int main() {
|
|
ulong_t n = 0;
|
|
|
|
if (atomic_cas_ulong(&n, 0, 3) != 0)
|
|
return 1;
|
|
if (atomic_add_long_nv(&n, 1) != 4)
|
|
return 1;
|
|
if (atomic_swap_ulong(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
if (atomic_or_ulong_nv(&n, 2) != 7)
|
|
return 1;
|
|
if (atomic_and_ulong_nv(&n, 5) != 5)
|
|
return 1;
|
|
return 0;
|
|
}"
|
|
. auto/feature
|
|
fi
|
|
|
|
|
|
# AIX xlC builtin atomic operations.
|
|
|
|
if [ $nxt_found = no ]; then
|
|
|
|
if [ $NXT_64BIT = 1 ]; then
|
|
nxt_feature_test="int main() {
|
|
long n = 0;
|
|
long o = 0;
|
|
|
|
if (!__compare_and_swaplp(&n, &o, 3))
|
|
return 1;
|
|
if (__fetch_and_addlp(&n, 1) != 3)
|
|
return 1;
|
|
if (__fetch_and_swaplp(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
__isync();
|
|
__lwsync();
|
|
return 0;
|
|
}"
|
|
else
|
|
nxt_feature_test="int main() {
|
|
int n = 0;
|
|
int o = 0;
|
|
|
|
if (!__compare_and_swap(&n, &o, 3))
|
|
return 1;
|
|
if (__fetch_and_add(&n, 1) != 3)
|
|
return 1;
|
|
if (__fetch_and_swap(&n, 5) != 4)
|
|
return 1;
|
|
if (n != 5)
|
|
return 1;
|
|
__isync();
|
|
__lwsync();
|
|
return 0;
|
|
}"
|
|
fi
|
|
|
|
nxt_feature="xlC builtin atomic operations"
|
|
nxt_feature_name=NXT_HAVE_XLC_ATOMIC
|
|
nxt_feature_run=yes
|
|
nxt_feature_incs=
|
|
nxt_feature_libs=
|
|
. auto/feature
|
|
fi
|
|
|
|
|
|
if [ $nxt_found = no ]; then
|
|
$echo
|
|
$echo $0: error: no atomic operations found.
|
|
$echo
|
|
exit 1;
|
|
fi
|