diff --git a/include/asterisk/astobj2.h b/include/asterisk/astobj2.h index 344d150199..540af30ff7 100644 --- a/include/asterisk/astobj2.h +++ b/include/asterisk/astobj2.h @@ -211,7 +211,19 @@ int ao2_unlock(void *a); #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 -int ao2_trylock(void *user_data); + +/*! \brief + * Try locking-- (don't block if fail) + * + * \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); +#endif /*! * diff --git a/main/astobj2.c b/main/astobj2.c index 032a232b89..6b664ccbb6 100644 --- a/main/astobj2.c +++ b/main/astobj2.c @@ -170,14 +170,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) +#endif { struct astobj2 *p = INTERNAL_OBJ(user_data); int ret; if (p == NULL) return -1; - ret = ast_mutex_trylock(&p->priv_data.lock); +#ifndef DEBUG_THREADS + ret = ast_mutex_trylock(&p->priv_data.lock); +#else + ret = __ast_pthread_mutex_trylock(file, line, func, var, &p->priv_data.lock); +#endif + #ifdef AO2_DEBUG if (!ret) ast_atomic_fetchadd_int(&ao2.total_locked, 1);