|
|
|
|
@ -1353,6 +1353,162 @@ static inline int _ast_rwlock_wrlock(ast_rwlock_t *t, const char *name,
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ast_rwlock_timedrdlock(a,b) \
|
|
|
|
|
_ast_rwlock_timedrdlock(a, # a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
|
|
|
|
|
|
|
|
|
static inline int _ast_rwlock_timedrdlock(ast_rwlock_t *t, const char *name,
|
|
|
|
|
const struct timespec *abs_timeout, const char *filename, int line, const char *func)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
struct ast_lock_track *lt = &t->track;
|
|
|
|
|
int canlog = strcmp(filename, "logger.c") & t->tracking;
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
struct ast_bt *bt = NULL;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
|
|
|
|
if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
|
|
|
|
|
/* Don't warn abount uninitialized lock.
|
|
|
|
|
* Simple try to initialize it.
|
|
|
|
|
* May be not needed in linux system.
|
|
|
|
|
*/
|
|
|
|
|
res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
|
|
|
|
|
if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
|
|
|
|
|
__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
|
|
|
|
|
filename, line, func, name);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
|
|
|
|
|
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
if (lt->reentrancy != AST_MAX_REENTRANCY) {
|
|
|
|
|
ast_bt_get_addresses(<->backtrace[lt->reentrancy]);
|
|
|
|
|
bt = <->backtrace[lt->reentrancy];
|
|
|
|
|
}
|
|
|
|
|
ast_reentrancy_unlock(lt);
|
|
|
|
|
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
|
|
|
|
|
#else
|
|
|
|
|
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
res = pthread_rwlock_timedrdlock(&t->lock, abs_timeout);
|
|
|
|
|
if (!res) {
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
if (lt->reentrancy < AST_MAX_REENTRANCY) {
|
|
|
|
|
lt->file[lt->reentrancy] = filename;
|
|
|
|
|
lt->lineno[lt->reentrancy] = line;
|
|
|
|
|
lt->func[lt->reentrancy] = func;
|
|
|
|
|
lt->thread[lt->reentrancy] = pthread_self();
|
|
|
|
|
lt->reentrancy++;
|
|
|
|
|
}
|
|
|
|
|
ast_reentrancy_unlock(lt);
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_mark_lock_acquired(t);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
if (lt->reentrancy) {
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
bt = <->backtrace[lt->reentrancy-1];
|
|
|
|
|
} else {
|
|
|
|
|
bt = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_remove_lock_info(t, bt);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_remove_lock_info(t);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
__ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
|
|
|
|
|
filename, line, func, strerror(res));
|
|
|
|
|
DO_THREAD_CRASH;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define ast_rwlock_timedwrlock(a,b) \
|
|
|
|
|
_ast_rwlock_timedwrlock(a, # a, b, __FILE__, __LINE__, __PRETTY_FUNCTION__)
|
|
|
|
|
|
|
|
|
|
static inline int _ast_rwlock_timedwrlock(ast_rwlock_t *t, const char *name,
|
|
|
|
|
const struct timespec *abs_timeout, const char *filename, int line, const char *func)
|
|
|
|
|
{
|
|
|
|
|
int res;
|
|
|
|
|
struct ast_lock_track *lt = &t->track;
|
|
|
|
|
int canlog = strcmp(filename, "logger.c") & t->tracking;
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
struct ast_bt *bt = NULL;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
|
|
|
|
if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
|
|
|
|
|
/* Don't warn abount uninitialized lock.
|
|
|
|
|
* Simple try to initialize it.
|
|
|
|
|
* May be not needed in linux system.
|
|
|
|
|
*/
|
|
|
|
|
res = __ast_rwlock_init(t->tracking, filename, line, func, name, t);
|
|
|
|
|
if ((t->lock) == ((pthread_rwlock_t) __AST_RWLOCK_INIT_VALUE)) {
|
|
|
|
|
__ast_mutex_logger("%s line %d (%s): Error: rwlock '%s' is uninitialized and unable to initialize.\n",
|
|
|
|
|
filename, line, func, name);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif /* AST_MUTEX_INIT_W_CONSTRUCTORS */
|
|
|
|
|
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
if (lt->reentrancy != AST_MAX_REENTRANCY) {
|
|
|
|
|
ast_bt_get_addresses(<->backtrace[lt->reentrancy]);
|
|
|
|
|
bt = <->backtrace[lt->reentrancy];
|
|
|
|
|
}
|
|
|
|
|
ast_reentrancy_unlock(lt);
|
|
|
|
|
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t, bt);
|
|
|
|
|
#else
|
|
|
|
|
ast_store_lock_info(AST_WRLOCK, filename, line, func, name, t);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
res = pthread_rwlock_timedwrlock(&t->lock, abs_timeout);
|
|
|
|
|
if (!res) {
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
if (lt->reentrancy < AST_MAX_REENTRANCY) {
|
|
|
|
|
lt->file[lt->reentrancy] = filename;
|
|
|
|
|
lt->lineno[lt->reentrancy] = line;
|
|
|
|
|
lt->func[lt->reentrancy] = func;
|
|
|
|
|
lt->thread[lt->reentrancy] = pthread_self();
|
|
|
|
|
lt->reentrancy++;
|
|
|
|
|
}
|
|
|
|
|
ast_reentrancy_unlock(lt);
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_mark_lock_acquired(t);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
#ifdef HAVE_BKTR
|
|
|
|
|
if (lt->reentrancy) {
|
|
|
|
|
ast_reentrancy_lock(lt);
|
|
|
|
|
bt = <->backtrace[lt->reentrancy-1];
|
|
|
|
|
} else {
|
|
|
|
|
bt = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_remove_lock_info(t, bt);
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
if (t->tracking) {
|
|
|
|
|
ast_remove_lock_info(t);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
__ast_mutex_logger("%s line %d (%s): Error obtaining read lock: %s\n",
|
|
|
|
|
filename, line, func, strerror(res));
|
|
|
|
|
DO_THREAD_CRASH;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int _ast_rwlock_tryrdlock(ast_rwlock_t *t, const char *name,
|
|
|
|
|
const char *filename, int line, const char *func)
|
|
|
|
|
{
|
|
|
|
|
@ -1601,6 +1757,11 @@ static inline int ast_rwlock_rdlock(ast_rwlock_t *prwlock)
|
|
|
|
|
return pthread_rwlock_rdlock(prwlock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int ast_rwlock_timedrdlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
|
|
|
|
|
{
|
|
|
|
|
return pthread_rwlock_timedrdlock(prwlock, abs_timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int ast_rwlock_tryrdlock(ast_rwlock_t *prwlock)
|
|
|
|
|
{
|
|
|
|
|
return pthread_rwlock_tryrdlock(prwlock);
|
|
|
|
|
@ -1611,6 +1772,11 @@ static inline int ast_rwlock_wrlock(ast_rwlock_t *prwlock)
|
|
|
|
|
return pthread_rwlock_wrlock(prwlock);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int ast_rwlock_timedwrlock(ast_rwlock_t *prwlock, const struct timespec *abs_timeout)
|
|
|
|
|
{
|
|
|
|
|
return pthread_rwlock_timedwrlock(prwlock, abs_timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int ast_rwlock_trywrlock(ast_rwlock_t *prwlock)
|
|
|
|
|
{
|
|
|
|
|
return pthread_rwlock_trywrlock(prwlock);
|
|
|
|
|
|