aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-12 16:28:06 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2009-02-12 16:28:06 +0000
commit84a9682d1f96fe25becaa455957aba7b95d35791 (patch)
tree08e260fab87992f69f95cacda7f3038f92cc0a2c
parentff056adc90530329aba1a0e1bff28bd2bf4b6d6e (diff)
Make lock information for ao2_trylock be more useful and gnarly
Core show locks information involving an ao2_trylock did not show the function that called ao2_trylock, but would instead show ao2_trylock as the source of the lock. This is not useful when trying to debug locking issues. One bizarre note is that this logic is already in 1.4 but somehow did not get merged to trunk or the 1.6.X branches. git-svn-id: http://svn.digium.com/svn/asterisk/trunk@175121 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--include/asterisk/astobj2.h5
-rw-r--r--main/astobj2.c11
2 files changed, 15 insertions, 1 deletions
diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h
index 040f6726a..1484d2bd0 100644
--- a/include/asterisk/astobj2.h
+++ b/include/asterisk/astobj2.h
@@ -478,7 +478,12 @@ 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);
+#endif
/*! \brief
* Return the lock address of an object
diff --git a/main/astobj2.c b/main/astobj2.c
index 21dc92733..8e33f94ae 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -188,14 +188,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)
+#endif
{
struct astobj2 *p = INTERNAL_OBJ(user_data);
int ret;
if (p == NULL)
return -1;
- ret = ast_mutex_trylock(&p->priv_data.lock);
+#ifndef DEBUG_THREADS
+ ret = ast_mutex_trylock(&p->priv_data.lock);
+#else
+ ret = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock);
+#endif
+
#ifdef AO2_DEBUG
if (!ret)
ast_atomic_fetchadd_int(&ao2.total_locked, 1);