dect
/
asterisk
Archived
13
0
Fork 0

use atomic operations provided by the compiler if they are available (yay for gcc 4.1 users!)

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@33953 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
kpfleming 2006-06-13 21:35:29 +00:00
parent 7d7f932c01
commit 6d3448b51e
4 changed files with 94 additions and 4 deletions

68
configure vendored
View File

@ -26314,6 +26314,74 @@ fi
done
echo -n "checking for compiler atomic operations..."
cat >conftest.$ac_ext <<_ACEOF
/* confdefs.h. */
_ACEOF
cat confdefs.h >>conftest.$ac_ext
cat >>conftest.$ac_ext <<_ACEOF
/* end confdefs.h. */
int
main ()
{
int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);
;
return 0;
}
_ACEOF
rm -f conftest.$ac_objext
if { (ac_try="$ac_compile"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_compile") 2>conftest.er1
ac_status=$?
grep -v '^ *+' conftest.er1 >conftest.err
rm -f conftest.er1
cat conftest.err >&5
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); } &&
{ ac_try='test -z "$ac_c_werror_flag" || test ! -s conftest.err'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; } &&
{ ac_try='test -s conftest.$ac_objext'
{ (case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
(eval "$ac_try") 2>&5
ac_status=$?
echo "$as_me:$LINENO: \$? = $ac_status" >&5
(exit $ac_status); }; }; then
{ echo "$as_me:$LINENO: result: yes" >&5
echo "${ECHO_T}yes" >&6; }
cat >>confdefs.h <<\_ACEOF
#define HAVE_GCC_ATOMICS 1
_ACEOF
else
echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
{ echo "$as_me:$LINENO: result: no" >&5
echo "${ECHO_T}no" >&6; }
fi
rm -f conftest.err conftest.$ac_objext conftest.$ac_ext
ac_config_files="$ac_config_files build_tools/menuselect-deps makeopts"
cat >confcache <<\_ACEOF

View File

@ -723,6 +723,14 @@ AC_FUNC_UTIME_NULL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([atexit bzero dup2 endpwent floor ftruncate getcwd gethostbyname gethostname gettimeofday inet_ntoa isascii localtime_r memchr memmove memset mkdir munmap pow putenv re_comp regcomp rint select setenv socket sqrt strcasecmp strchr strcspn strdup strerror strncasecmp strndup strnlen strrchr strsep strspn strstr strtol unsetenv utime strtoq strcasestr asprintf vasprintf])
echo -n "checking for compiler atomic operations... "
AC_COMPILE_IFELSE(
AC_LANG_PROGRAM([], [int foo1; int foo2 = __sync_fetch_and_add(&foo1, 1);]),
AC_MSG_RESULT(yes)
AC_DEFINE([HAVE_GCC_ATOMICS], 1, [Define to 1 if your GCC C compiler provides atomic operations.]),
AC_MSG_RESULT(no)
)
AC_CONFIG_FILES([build_tools/menuselect-deps makeopts])
AC_OUTPUT

View File

@ -94,6 +94,9 @@
/* Define to 1 if you have the `ftruncate' function. */
#undef HAVE_FTRUNCATE
/* Define to 1 if your GCC C compiler provides atomic operations. */
#undef HAVE_GCC_ATOMICS
/* Define to 1 if you have the `getcwd' function. */
#undef HAVE_GETCWD

View File

@ -738,12 +738,17 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v);
#include "asterisk/inline_api.h"
/*! \brief Atomically add v to *pp and return * the previous value of *p.
/*! \brief Atomically add v to *p and return * the previous value of *p.
* This can be used to handle reference counts, and the return value
* can be used to generate unique identifiers.
*/
#if defined ( __i386__)
#if defined(HAVE_GCC_ATOMICS)
AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
{
return __sync_fetch_and_add(p, v);
})
#elif defined ( __i386__)
AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
{
__asm __volatile (
@ -763,12 +768,18 @@ AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
/*! \brief decrement *p by 1 and return true if the variable has reached 0.
* Useful e.g. to check if a refcount has reached 0.
*/
#if defined(HAVE_GCC_ATOMICS)
AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
{
return __sync_sub_and_fetch(p, 1) == 0;
})
#else
AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
{
int a = ast_atomic_fetchadd_int(p, -1);
return a == 1; /* true if the value is 0 now (so it was 1 previously) */
}
)
})
#endif
#ifndef DEBUG_CHANNEL_LOCKS
/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined