mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-30 10:33:13 +00:00
use atomic operations provided by the compiler if they are available (yay for gcc 4.1 users!)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@33953 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
68
configure
vendored
68
configure
vendored
@@ -26314,6 +26314,74 @@ fi
|
|||||||
done
|
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"
|
ac_config_files="$ac_config_files build_tools/menuselect-deps makeopts"
|
||||||
|
|
||||||
cat >confcache <<\_ACEOF
|
cat >confcache <<\_ACEOF
|
||||||
|
@@ -723,6 +723,14 @@ AC_FUNC_UTIME_NULL
|
|||||||
AC_FUNC_VPRINTF
|
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])
|
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_CONFIG_FILES([build_tools/menuselect-deps makeopts])
|
||||||
AC_OUTPUT
|
AC_OUTPUT
|
||||||
|
|
||||||
|
@@ -94,6 +94,9 @@
|
|||||||
/* Define to 1 if you have the `ftruncate' function. */
|
/* Define to 1 if you have the `ftruncate' function. */
|
||||||
#undef HAVE_FTRUNCATE
|
#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. */
|
/* Define to 1 if you have the `getcwd' function. */
|
||||||
#undef HAVE_GETCWD
|
#undef HAVE_GETCWD
|
||||||
|
|
||||||
|
@@ -738,12 +738,17 @@ int ast_atomic_fetchadd_int_slow(volatile int *p, int v);
|
|||||||
|
|
||||||
#include "asterisk/inline_api.h"
|
#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
|
* This can be used to handle reference counts, and the return value
|
||||||
* can be used to generate unique identifiers.
|
* 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),
|
AST_INLINE_API(int ast_atomic_fetchadd_int(volatile int *p, int v),
|
||||||
{
|
{
|
||||||
__asm __volatile (
|
__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.
|
/*! \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.
|
* 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),
|
AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
|
||||||
{
|
{
|
||||||
int a = ast_atomic_fetchadd_int(p, -1);
|
int a = ast_atomic_fetchadd_int(p, -1);
|
||||||
return a == 1; /* true if the value is 0 now (so it was 1 previously) */
|
return a == 1; /* true if the value is 0 now (so it was 1 previously) */
|
||||||
}
|
})
|
||||||
)
|
#endif
|
||||||
|
|
||||||
#ifndef DEBUG_CHANNEL_LOCKS
|
#ifndef DEBUG_CHANNEL_LOCKS
|
||||||
/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
||||||
|
Reference in New Issue
Block a user