aboutsummaryrefslogtreecommitdiffstats
path: root/main/astobj2.c
diff options
context:
space:
mode:
authorqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-03-25 19:39:23 +0000
committerqwell <qwell@f38db490-d61c-443f-a65b-d21fe96a405b>2010-03-25 19:39:23 +0000
commitbc49afad0901b61eb23a054f06098f16b8d72eae (patch)
tree0f67ad4658bb271c4ab36012d186bec82a8edbe0 /main/astobj2.c
parent28e34f474cd2f309e8a66eb3a23c9850f3f5c091 (diff)
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: http://svn.digium.com/svn/asterisk/branches/1.4@254714 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/astobj2.c')
-rw-r--r--main/astobj2.c60
1 files changed, 51 insertions, 9 deletions
diff --git a/main/astobj2.c b/main/astobj2.c
index 392aa09de..b88732ea2 100644
--- a/main/astobj2.c
+++ b/main/astobj2.c
@@ -125,11 +125,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);
@@ -147,11 +164,26 @@ int __ao2_lock(void *user_data, const char *file, const char *func, int line, co
#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 res;
+
+ if (p == NULL)
+ return -1;
+
+ res = ast_mutex_trylock(&p->priv_data.lock);
+
+#ifdef AO2_DEBUG
+ if (!res) {
+ ast_atomic_fetchadd_int(&ao2.total_locked, 1);
+ }
#endif
+
+ return res;
+}
+
+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 res;
@@ -174,11 +206,21 @@ int __ao2_trylock(void *user_data, const char *file, const char *func, int line,
return res;
}
-#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);