From: Jason Parker Date: Thu, 25 Mar 2010 19:59:04 +0000 (+0000) Subject: Fix DEBUG_THREADS issue with out-of-tree modules. X-Git-Tag: 1.6.0.27-rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8c55f67ce53f614b5d0967434fe92afc7267cef3;p=thirdparty%2Fasterisk.git Fix DEBUG_THREADS issue with out-of-tree modules. Take 2, without ABI breakage this time. Review: https://reviewboard.asterisk.org/r/588/ git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.6.0@254716 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index 22270c19a7..822f4ba4d3 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -192,11 +192,10 @@ int ao2_ref(void *o, int delta); * \param a A pointer to the object we want lock. * \return 0 on success, other values on error. */ -#ifndef DEBUG_THREADS int ao2_lock(void *a); -#else -#define ao2_lock(a) _ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) int _ao2_lock(void *a, const char *file, const char *func, int line, const char *var); +#ifdef DEBUG_THREADS +#define ao2_lock(a) _ao2_lock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) #endif /*! \brief @@ -205,11 +204,10 @@ int _ao2_lock(void *a, const char *file, const char *func, int line, const char * \param a A pointer to the object we want unlock. * \return 0 on success, other values on error. */ -#ifndef DEBUG_THREADS int ao2_unlock(void *a); -#else -#define ao2_unlock(a) _ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) int _ao2_unlock(void *a, const char *file, const char *func, int line, const char *var); +#ifdef DEBUG_THREADS +#define ao2_unlock(a) _ao2_unlock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) #endif /*! \brief @@ -218,11 +216,10 @@ int _ao2_unlock(void *a, const char *file, const char *func, int line, const cha * \param a A pointer to the object we want to lock. * \return 0 on success, other values on error. */ -#ifndef DEBUG_THREADS int ao2_trylock(void *a); -#else -#define ao2_trylock(a) _ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) int _ao2_trylock(void *a, const char *file, const char *func, int line, const char *var); +#ifdef DEBUG_THREADS +#define ao2_trylock(a) _ao2_trylock(a, __FILE__, __PRETTY_FUNCTION__, __LINE__, #a) #endif /*! diff --git a/main/astobj2.c b/main/astobj2.c index 11846d6695..ae2b2b65d9 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -126,11 +126,28 @@ static inline struct astobj2 *INTERNAL_OBJ(void *user_data) */ #define EXTERNAL_OBJ(_p) ((_p) == NULL ? NULL : (_p)->user_data) -#ifndef DEBUG_THREADS +#ifdef DEBUG_THREADS +/* Need to override the macros defined in astobj2.h */ +#undef ao2_lock +#undef ao2_trylock +#undef ao2_unlock +#endif + int ao2_lock(void *user_data) -#else -int _ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var) +{ + struct astobj2 *p = INTERNAL_OBJ(user_data); + + if (p == NULL) + return -1; + +#ifdef AO2_DEBUG + ast_atomic_fetchadd_int(&ao2.total_locked, 1); #endif + + return ast_mutex_lock(&p->priv_data.lock); +} + +int _ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var) { struct astobj2 *p = INTERNAL_OBJ(user_data); @@ -148,11 +165,21 @@ int _ao2_lock(void *user_data, const char *file, const char *func, int line, con #endif } -#ifndef DEBUG_THREADS int ao2_unlock(void *user_data) -#else -int _ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var) +{ + struct astobj2 *p = INTERNAL_OBJ(user_data); + + if (p == NULL) + return -1; + +#ifdef AO2_DEBUG + ast_atomic_fetchadd_int(&ao2.total_locked, -1); #endif + + return ast_mutex_unlock(&p->priv_data.lock); +} + +int _ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var) { struct astobj2 *p = INTERNAL_OBJ(user_data); @@ -170,11 +197,23 @@ int _ao2_unlock(void *user_data, const char *file, const char *func, int line, c #endif } -#ifndef DEBUG_THREADS int ao2_trylock(void *user_data) -#else -int _ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var) +{ + struct astobj2 *p = INTERNAL_OBJ(user_data); + int ret; + + if (p == NULL) + return -1; + ret = ast_mutex_trylock(&p->priv_data.lock); + +#ifdef AO2_DEBUG + if (!ret) + ast_atomic_fetchadd_int(&ao2.total_locked, 1); #endif + return ret; +} + +int _ao2_trylock(void *user_data, const char *file, const char *func, int line, const char *var) { struct astobj2 *p = INTERNAL_OBJ(user_data); int ret;