[asterisk-commits] trunk r33953 - in /trunk: ./ include/asterisk/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Jun 13 14:35:30 MST 2006
Author: kpfleming
Date: Tue Jun 13 16:35:29 2006
New Revision: 33953
URL: http://svn.digium.com/view/asterisk?rev=33953&view=rev
Log:
use atomic operations provided by the compiler if they are available (yay for gcc 4.1 users!)
Modified:
trunk/configure
trunk/configure.ac
trunk/include/asterisk/autoconfig.h.in
trunk/include/asterisk/lock.h
Modified: trunk/configure
URL: http://svn.digium.com/view/asterisk/trunk/configure?rev=33953&r1=33952&r2=33953&view=diff
==============================================================================
--- trunk/configure (original)
+++ trunk/configure Tue Jun 13 16:35:29 2006
@@ -26314,6 +26314,74 @@
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
Modified: trunk/configure.ac
URL: http://svn.digium.com/view/asterisk/trunk/configure.ac?rev=33953&r1=33952&r2=33953&view=diff
==============================================================================
--- trunk/configure.ac (original)
+++ trunk/configure.ac Tue Jun 13 16:35:29 2006
@@ -723,6 +723,14 @@
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
Modified: trunk/include/asterisk/autoconfig.h.in
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/autoconfig.h.in?rev=33953&r1=33952&r2=33953&view=diff
==============================================================================
--- trunk/include/asterisk/autoconfig.h.in (original)
+++ trunk/include/asterisk/autoconfig.h.in Tue Jun 13 16:35:29 2006
@@ -93,6 +93,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
Modified: trunk/include/asterisk/lock.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/lock.h?rev=33953&r1=33952&r2=33953&view=diff
==============================================================================
--- trunk/include/asterisk/lock.h (original)
+++ trunk/include/asterisk/lock.h Tue Jun 13 16:35:29 2006
@@ -738,12 +738,17 @@
#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 @@
/*! \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
More information about the asterisk-commits
mailing list