[svn-commits] qwell: branch 1.6.0 r254716 - in /branches/1.6.0: include/asterisk/ main/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 25 14:59:07 CDT 2010


Author: qwell
Date: Thu Mar 25 14:59:04 2010
New Revision: 254716

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=254716
Log:
Fix DEBUG_THREADS issue with out-of-tree modules.
  
Take 2, without ABI breakage this time.

Review: https://reviewboard.asterisk.org/r/588/

Modified:
    branches/1.6.0/include/asterisk/astobj2.h
    branches/1.6.0/main/astobj2.c

Modified: branches/1.6.0/include/asterisk/astobj2.h
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.0/include/asterisk/astobj2.h?view=diff&rev=254716&r1=254715&r2=254716
==============================================================================
--- branches/1.6.0/include/asterisk/astobj2.h (original)
+++ branches/1.6.0/include/asterisk/astobj2.h Thu Mar 25 14:59:04 2010
@@ -192,11 +192,10 @@
  * \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
+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)
-int _ao2_lock(void *a, const char *file, const char *func, int line, const char *var);
 #endif
 
 /*! \brief
@@ -205,11 +204,10 @@
  * \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
+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)
-int _ao2_unlock(void *a, const char *file, const char *func, int line, const char *var);
 #endif
 
 /*! \brief
@@ -218,11 +216,10 @@
  * \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
+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)
-int _ao2_trylock(void *a, const char *file, const char *func, int line, const char *var);
 #endif
 
 /*! 

Modified: branches/1.6.0/main/astobj2.c
URL: http://svnview.digium.com/svn/asterisk/branches/1.6.0/main/astobj2.c?view=diff&rev=254716&r1=254715&r2=254716
==============================================================================
--- branches/1.6.0/main/astobj2.c (original)
+++ branches/1.6.0/main/astobj2.c Thu Mar 25 14:59:04 2010
@@ -126,11 +126,28 @@
  */
 #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
+{
+	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)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 
@@ -148,11 +165,21 @@
 #endif
 }
 
-#ifndef DEBUG_THREADS
 int ao2_unlock(void *user_data)
-#else
+{
+	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)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 
@@ -170,11 +197,23 @@
 #endif
 }
 
-#ifndef DEBUG_THREADS
 int ao2_trylock(void *user_data)
-#else
+{
+	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)
-#endif
 {
 	struct astobj2 *p = INTERNAL_OBJ(user_data);
 	int ret;




More information about the svn-commits mailing list