]> 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 20:03:59 +0000 (20:03 +0000)
committerJason Parker <jparker@digium.com>
Thu, 25 Mar 2010 20:03:59 +0000 (20:03 +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.6.1@254717 65c4cc65-6c06-0410-ace0-fbb531ad65f3

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

index 0c780a26dcc8555d1689aa13eddd2912b6be7bdf..3b605720a1368fd82405d9f7bc9e90bcf43f08bb 100644 (file)
@@ -467,11 +467,10 @@ int _ao2_ref(void *o, int delta);
  * \param a A pointer to the object we want to 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
@@ -480,11 +479,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
@@ -493,11 +491,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
 
 /*!
index 17dcb28b204865c909ff5debe02654b72eff2352..ab040b351af8e46e6902c27c0cb8501c862d3e4c 100644 (file)
@@ -138,11 +138,28 @@ static void *__ao2_callback(struct ao2_container *c,
                                         char *tag, char *file, int line, const char *funcname);
 static void * __ao2_iterator_next(struct ao2_iterator *a, struct bucket_list **q);
 
-#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);
 
@@ -160,11 +177,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);
 
@@ -182,11 +209,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;