Properly defuse race in chan_local, fix extremely unlikely path for losing lock in chan_agent
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1276 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
1d12de4da6
commit
29802d2ff5
|
@ -560,6 +560,8 @@ static struct ast_channel *agent_new(struct agent_pvt *p, int state)
|
||||||
tmp->pvt->pvt = NULL;
|
tmp->pvt->pvt = NULL;
|
||||||
p->app_sleep_cond = 1;
|
p->app_sleep_cond = 1;
|
||||||
ast_channel_free( tmp );
|
ast_channel_free( tmp );
|
||||||
|
ast_pthread_mutex_unlock(&p->lock); /* For other thread to read the condition. */
|
||||||
|
ast_pthread_mutex_unlock(&p->app_lock);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,11 +71,14 @@ static struct local_pvt {
|
||||||
|
|
||||||
static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f)
|
static int local_queue_frame(struct local_pvt *p, int isoutbound, struct ast_frame *f)
|
||||||
{
|
{
|
||||||
struct ast_channel *other;
|
struct ast_channel *other, *us;
|
||||||
if (isoutbound)
|
if (isoutbound) {
|
||||||
|
us = p->chan;
|
||||||
other = p->owner;
|
other = p->owner;
|
||||||
else
|
} else {
|
||||||
|
us = p->owner;
|
||||||
other = p->chan;
|
other = p->chan;
|
||||||
|
}
|
||||||
if (!other)
|
if (!other)
|
||||||
return 0;
|
return 0;
|
||||||
p->glaredetect = 1;
|
p->glaredetect = 1;
|
||||||
|
@ -90,8 +93,11 @@ retrylock:
|
||||||
if (pthread_mutex_trylock(&other->lock)) {
|
if (pthread_mutex_trylock(&other->lock)) {
|
||||||
/* Failed to lock. Release main lock and try again */
|
/* Failed to lock. Release main lock and try again */
|
||||||
ast_pthread_mutex_unlock(&p->lock);
|
ast_pthread_mutex_unlock(&p->lock);
|
||||||
|
ast_pthread_mutex_unlock(&us->lock);
|
||||||
/* Wait just a bit */
|
/* Wait just a bit */
|
||||||
usleep(1);
|
usleep(1);
|
||||||
|
/* Only we can destroy ourselves, so we can't disappear here */
|
||||||
|
ast_pthread_mutex_lock(&us->lock);
|
||||||
ast_pthread_mutex_lock(&p->lock);
|
ast_pthread_mutex_lock(&p->lock);
|
||||||
goto retrylock;
|
goto retrylock;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue