diff options
author | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-06-13 21:35:29 +0000 |
---|---|---|
committer | kpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b> | 2006-06-13 21:35:29 +0000 |
commit | 6d3448b51e0bae74f3a5e4867caab69cc25e5f1a (patch) | |
tree | 326057f16fd8a5c141dd07a413345c9d1fc689a4 /include/asterisk | |
parent | 7d7f932c01b560eeaf9aae975898ab360e86a8ea (diff) |
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
Diffstat (limited to 'include/asterisk')
-rw-r--r-- | include/asterisk/autoconfig.h.in | 3 | ||||
-rw-r--r-- | include/asterisk/lock.h | 19 |
2 files changed, 18 insertions, 4 deletions
diff --git a/include/asterisk/autoconfig.h.in b/include/asterisk/autoconfig.h.in index 4eab724e1..3e11ac04f 100644 --- a/include/asterisk/autoconfig.h.in +++ b/include/asterisk/autoconfig.h.in @@ -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 diff --git a/include/asterisk/lock.h b/include/asterisk/lock.h index db85c497b..f60e04e1a 100644 --- a/include/asterisk/lock.h +++ b/include/asterisk/lock.h @@ -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 |