]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Fix DEBUG_THREADS issue with out-of-tree modules.
authorJason Parker <jparker@digium.com>
Thu, 25 Mar 2010 19:39:23 +0000 (19:39 +0000)
committerJason Parker <jparker@digium.com>
Thu, 25 Mar 2010 19:39:23 +0000 (19:39 +0000)
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.4@254714 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/astobj2.h
main/astobj2.c

index b9d814e9fe46c7fba4b2b3c37a6b5f959631aca3..20621e2e83f436e877056ea856e1eb59a5f98245 100644 (file)
@@ -185,18 +185,16 @@ 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
 
-#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
 
 /*!
@@ -205,11 +203,10 @@ int __ao2_trylock(void *a, const char *file, const char *func, int line, const c
  * \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
 
 /*!
index 392aa09de18887c227f513d6d14f5466db460460..b88732ea25dc7f20daeb3c849cdc23f845d64029 100644 (file)
@@ -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);