|
|
|
@ -126,11 +126,28 @@ static inline struct astobj2 *INTERNAL_OBJ(void *user_data)
|
|
|
|
|
*/
|
|
|
|
|
#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
|
|
|
|
|
int _ao2_lock(void *user_data, const char *file, const char *func, int line, const char *var)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct astobj2 *p = INTERNAL_OBJ(user_data);
|
|
|
|
|
|
|
|
|
@ -148,11 +165,21 @@ int _ao2_lock(void *user_data, const char *file, const char *func, int line, con
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct astobj2 *p = INTERNAL_OBJ(user_data);
|
|
|
|
|
|
|
|
|
@ -170,11 +197,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)
|
|
|
|
|
{
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
struct astobj2 *p = INTERNAL_OBJ(user_data);
|
|
|
|
|
int ret;
|
|
|
|
|