diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-11-25 17:34:50 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2008-11-25 17:34:50 +0000 |
commit | b4a7bb15ed240b0cd91e856b0ad876e95a4fab45 (patch) | |
tree | 87e3a58fc1dcbe961719eb2caf4e2eb4ad0d7f73 /main/astobj2.c | |
parent | fc98939e4f2e7aec7f136a1dc2bdfc780143bf1a (diff) |
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
Diffstat (limited to 'main/astobj2.c')
-rw-r--r-- | main/astobj2.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/main/astobj2.c b/main/astobj2.c index 2614cf7b4..efebaf42f 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -148,6 +148,33 @@ int _ao2_lock(void *user_data, const char *file, const char *func, int line, con } #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 int _ao2_unlock(void *user_data, const char *file, const char *func, int line, const char *var) |