mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
This commit fixes the following issues:
- Deadlock in ast_write (issue #10406) - Deadlock in ast_read (issue #10406) - Possible mutex initialization error in lock.h (issue #10571) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@85158 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -148,6 +148,11 @@ void ast_store_lock_info(enum ast_lock_type type, const char *filename,
|
|||||||
*/
|
*/
|
||||||
void ast_mark_lock_acquired(void);
|
void ast_mark_lock_acquired(void);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Mark the last lock as failed (trylock)
|
||||||
|
*/
|
||||||
|
void ast_mark_lock_failed(void);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief remove lock info for the current thread
|
* \brief remove lock info for the current thread
|
||||||
*
|
*
|
||||||
@@ -165,6 +170,7 @@ static inline int __ast_pthread_mutex_init_attr(int track, const char *filename,
|
|||||||
const char *mutex_name, ast_mutex_t *t,
|
const char *mutex_name, ast_mutex_t *t,
|
||||||
pthread_mutexattr_t *attr)
|
pthread_mutexattr_t *attr)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
#ifdef AST_MUTEX_INIT_W_CONSTRUCTORS
|
||||||
int canlog = strcmp(filename, "logger.c");
|
int canlog = strcmp(filename, "logger.c");
|
||||||
|
|
||||||
@@ -180,10 +186,12 @@ static inline int __ast_pthread_mutex_init_attr(int track, const char *filename,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
t->file[0] = filename;
|
for (i = 0; i < AST_MAX_REENTRANCY; i++) {
|
||||||
t->lineno[0] = lineno;
|
t->file[i] = NULL;
|
||||||
t->func[0] = func;
|
t->lineno[i] = 0;
|
||||||
t->thread[0] = 0;
|
t->func[i] = NULL;
|
||||||
|
t->thread[i] = 0;
|
||||||
|
}
|
||||||
t->reentrancy = 0;
|
t->reentrancy = 0;
|
||||||
t->track = track;
|
t->track = track;
|
||||||
|
|
||||||
|
@@ -2181,6 +2181,7 @@ static void ast_read_generator_actions(struct ast_channel *chan, struct ast_fram
|
|||||||
static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
|
static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
|
||||||
{
|
{
|
||||||
struct ast_frame *f = NULL; /* the return value */
|
struct ast_frame *f = NULL; /* the return value */
|
||||||
|
struct ast_channel *base = NULL;
|
||||||
int blah;
|
int blah;
|
||||||
int prestate;
|
int prestate;
|
||||||
|
|
||||||
@@ -2204,6 +2205,23 @@ static struct ast_frame *__ast_read(struct ast_channel *chan, int dropaudio)
|
|||||||
}
|
}
|
||||||
prestate = chan->_state;
|
prestate = chan->_state;
|
||||||
|
|
||||||
|
/* Check if there's an underlying channel */
|
||||||
|
if (chan->tech->get_base_channel && (base = chan->tech->get_base_channel(chan)) != chan) {
|
||||||
|
int count = 0;
|
||||||
|
while (!base || ast_mutex_trylock(&base->lock)) {
|
||||||
|
if (count++ > 10) {
|
||||||
|
f = &ast_null_frame;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
ast_mutex_unlock(&chan->lock);
|
||||||
|
usleep(1);
|
||||||
|
ast_mutex_lock(&chan->lock);
|
||||||
|
base = chan->tech->get_base_channel(chan);
|
||||||
|
}
|
||||||
|
ast_mutex_unlock(&chan->lock);
|
||||||
|
chan = base;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF | AST_FLAG_IN_DTMF) &&
|
if (!ast_test_flag(chan, AST_FLAG_DEFER_DTMF | AST_FLAG_EMULATE_DTMF | AST_FLAG_IN_DTMF) &&
|
||||||
!ast_strlen_zero(chan->dtmfq) &&
|
!ast_strlen_zero(chan->dtmfq) &&
|
||||||
(ast_tvzero(chan->dtmf_tv) || ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) > AST_MIN_DTMF_GAP) ) {
|
(ast_tvzero(chan->dtmf_tv) || ast_tvdiff_ms(ast_tvnow(), chan->dtmf_tv) > AST_MIN_DTMF_GAP) ) {
|
||||||
@@ -2941,9 +2959,20 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
|
|||||||
/* and now put it through the regular translator */
|
/* and now put it through the regular translator */
|
||||||
f = (chan->writetrans) ? ast_translate(chan->writetrans, f, 0) : f;
|
f = (chan->writetrans) ? ast_translate(chan->writetrans, f, 0) : f;
|
||||||
}
|
}
|
||||||
if (f)
|
if (f) {
|
||||||
res = chan->tech->write(chan, f);
|
struct ast_channel *base = NULL;
|
||||||
else
|
if (!chan->tech->get_base_channel || chan == chan->tech->get_base_channel(chan))
|
||||||
|
res = chan->tech->write(chan, f);
|
||||||
|
else {
|
||||||
|
while (chan->tech->get_base_channel && (((base = chan->tech->get_base_channel(chan)) && ast_mutex_trylock(&base->lock)) || base == NULL)) {
|
||||||
|
ast_mutex_unlock(&chan->lock);
|
||||||
|
usleep(1);
|
||||||
|
ast_mutex_lock(&chan->lock);
|
||||||
|
}
|
||||||
|
res = base->tech->write(base, f);
|
||||||
|
ast_mutex_unlock(&base->lock);
|
||||||
|
}
|
||||||
|
} else
|
||||||
res = 0;
|
res = 0;
|
||||||
break;
|
break;
|
||||||
case AST_FRAME_NULL:
|
case AST_FRAME_NULL:
|
||||||
|
17
main/utils.c
17
main/utils.c
@@ -540,7 +540,7 @@ struct thr_lock_info {
|
|||||||
int times_locked;
|
int times_locked;
|
||||||
enum ast_lock_type type;
|
enum ast_lock_type type;
|
||||||
/*! This thread is waiting on this lock */
|
/*! This thread is waiting on this lock */
|
||||||
unsigned int pending:1;
|
int pending:2;
|
||||||
} locks[AST_MAX_LOCKS];
|
} locks[AST_MAX_LOCKS];
|
||||||
/*! This is the number of locks currently held by this thread.
|
/*! This is the number of locks currently held by this thread.
|
||||||
* The index (num_locks - 1) has the info on the last one in the
|
* The index (num_locks - 1) has the info on the last one in the
|
||||||
@@ -636,6 +636,19 @@ void ast_mark_lock_acquired(void)
|
|||||||
pthread_mutex_unlock(&lock_info->lock);
|
pthread_mutex_unlock(&lock_info->lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ast_mark_lock_failed(void)
|
||||||
|
{
|
||||||
|
struct thr_lock_info *lock_info;
|
||||||
|
|
||||||
|
if (!(lock_info = ast_threadstorage_get(&thread_lock_info, sizeof(*lock_info))))
|
||||||
|
return;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&lock_info->lock);
|
||||||
|
lock_info->locks[lock_info->num_locks - 1].pending = -1;
|
||||||
|
lock_info->locks[lock_info->num_locks - 1].times_locked--;
|
||||||
|
pthread_mutex_unlock(&lock_info->lock);
|
||||||
|
}
|
||||||
|
|
||||||
void ast_remove_lock_info(void *lock_addr)
|
void ast_remove_lock_info(void *lock_addr)
|
||||||
{
|
{
|
||||||
struct thr_lock_info *lock_info;
|
struct thr_lock_info *lock_info;
|
||||||
@@ -708,7 +721,7 @@ static int handle_show_locks(int fd, int argc, char *argv[])
|
|||||||
pthread_mutex_lock(&lock_info->lock);
|
pthread_mutex_lock(&lock_info->lock);
|
||||||
for (i = 0; i < lock_info->num_locks; i++) {
|
for (i = 0; i < lock_info->num_locks; i++) {
|
||||||
ast_cli(fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
|
ast_cli(fd, "=== ---> %sLock #%d (%s): %s %d %s %s %p (%d)\n",
|
||||||
lock_info->locks[i].pending ? "Waiting for " : "", i,
|
lock_info->locks[i].pending > 0 ? "Waiting for " : lock_info->locks[i].pending < 0 ? "Tried and failed to get " : "", i,
|
||||||
lock_info->locks[i].file,
|
lock_info->locks[i].file,
|
||||||
locktype2str(lock_info->locks[i].type),
|
locktype2str(lock_info->locks[i].type),
|
||||||
lock_info->locks[i].line_num,
|
lock_info->locks[i].line_num,
|
||||||
|
Reference in New Issue
Block a user