From b4a7bb15ed240b0cd91e856b0ad876e95a4fab45 Mon Sep 17 00:00:00 2001 From: russell Date: Tue, 25 Nov 2008 17:34:50 +0000 Subject: Add ao2_trylock() to go along with ao2_lock() and ao2_unlock() git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@159158 f38db490-d61c-443f-a65b-d21fe96a405b --- main/astobj2.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'main') diff --git a/main/astobj2.c b/main/astobj2.c index 2614cf7b4..efebaf42f 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -147,6 +147,33 @@ int _ao2_lock(void *user_data, const char *file, const char *func, int line, con #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 int ao2_unlock(void *user_data) #else -- cgit v1.2.3