[asterisk-commits] russell: branch 1.4 r159158 - in /branches/1.4: include/asterisk/ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 25 11:34:50 CST 2008


Author: russell
Date: Tue Nov 25 11:34:50 2008
New Revision: 159158

URL: http://svn.digium.com/view/asterisk?view=rev&rev=159158
Log:
Add ao2_trylock() to go along with ao2_lock() and ao2_unlock()

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

Modified: branches/1.4/include/asterisk/astobj2.h
URL: http://svn.digium.com/view/asterisk/branches/1.4/include/asterisk/astobj2.h?view=diff&rev=159158&r1=159157&r2=159158
==============================================================================
--- branches/1.4/include/asterisk/astobj2.h (original)
+++ branches/1.4/include/asterisk/astobj2.h Tue Nov 25 11:34:50 2008
@@ -190,6 +190,13 @@
 #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);
+#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);
 #endif
 
 /*!

Modified: branches/1.4/main/astobj2.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/astobj2.c?view=diff&rev=159158&r1=159157&r2=159158
==============================================================================
--- branches/1.4/main/astobj2.c (original)
+++ branches/1.4/main/astobj2.c Tue Nov 25 11:34:50 2008
@@ -145,6 +145,33 @@
 #else
 	return __ast_pthread_mutex_lock(file, line, func, var, &p->priv_data.lock);
 #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 res;
+
+	if (p == NULL)
+		return -1;
+
+#ifndef DEBUG_THREADS
+	res = ast_mutex_trylock(&p->priv_data.lock);
+#else
+	res = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock);
+#endif
+
+#ifdef AO2_DEBUG
+	if (!res) {
+		ast_atomic_fetchadd_int(&ao2.total_locked, 1);
+	}
+#endif
+
+	return res;
 }
 
 #ifndef DEBUG_THREADS




More information about the asterisk-commits mailing list