dect
/
asterisk
Archived
13
0
Fork 0

convert various places that access the channel lock directly to use the channel lock wrappers

git-svn-id: http://svn.digium.com/svn/asterisk/trunk@82728 f38db490-d61c-443f-a65b-d21fe96a405b
This commit is contained in:
russell 2007-09-17 22:59:36 +00:00
parent cb3876e55f
commit b9f37c0e99
7 changed files with 64 additions and 68 deletions

View File

@ -332,7 +332,7 @@ static int conf_exec(struct ast_channel *chan, void *data)
if((mygroup = pbx_builtin_getvar_helper(tempchan, "GROUP")) && (!strcmp(mygroup, desired_group))) {
ast_verb(3, "Found Matching Channel %s in group %s\n", tempchan->name, desired_group);
} else {
ast_mutex_unlock(&tempchan->lock);
ast_channel_unlock(tempchan);
lastchan = tempchan;
continue;
}

View File

@ -1183,10 +1183,8 @@ static int check_availability(struct agent_pvt *newlyavailable, int needlock)
ast_copy_string(parent->context, chan->context, sizeof(parent->context));
/* Go ahead and mark the channel as a zombie so that masquerade will
destroy it for us, and we need not call ast_hangup */
ast_mutex_lock(&parent->lock);
ast_set_flag(chan, AST_FLAG_ZOMBIE);
ast_channel_masquerade(parent, chan);
ast_mutex_unlock(&parent->lock);
p->abouttograb = 0;
} else {
ast_debug(1, "Sneaky, parent disappeared in the mean time...\n");

View File

@ -508,7 +508,7 @@ static int alsa_text(struct ast_channel *c, const char *text)
static void grab_owner(void)
{
while (alsa.owner && ast_mutex_trylock(&alsa.owner->lock)) {
while (alsa.owner && ast_channel_trylock(alsa.owner)) {
ast_mutex_unlock(&alsalock);
usleep(1);
ast_mutex_lock(&alsalock);
@ -527,7 +527,7 @@ static int alsa_call(struct ast_channel *c, char *dest, int timeout)
if (alsa.owner) {
f.subclass = AST_CONTROL_ANSWER;
ast_queue_frame(alsa.owner, &f);
ast_mutex_unlock(&alsa.owner->lock);
ast_channel_unlock(alsa.owner);
}
} else {
ast_verbose(" << Type 'answer' to answer, or use 'autoanswer' for future calls >> \n");
@ -535,7 +535,7 @@ static int alsa_call(struct ast_channel *c, char *dest, int timeout)
if (alsa.owner) {
f.subclass = AST_CONTROL_RINGING;
ast_queue_frame(alsa.owner, &f);
ast_mutex_unlock(&alsa.owner->lock);
ast_channel_unlock(alsa.owner);
}
write(sndcmd[1], &res, sizeof(res));
}
@ -901,7 +901,7 @@ static int console_answer(int fd, int argc, char *argv[])
if (alsa.owner) {
struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
ast_queue_frame(alsa.owner, &f);
ast_mutex_unlock(&alsa.owner->lock);
ast_channel_unlock(alsa.owner);
}
answer_sound();
}
@ -950,7 +950,7 @@ static int console_sendtext(int fd, int argc, char *argv[])
f.data = NULL;
f.datalen = 0;
ast_queue_frame(alsa.owner, &f);
ast_mutex_unlock(&alsa.owner->lock);
ast_channel_unlock(alsa.owner);
}
}
@ -982,7 +982,7 @@ static int console_hangup(int fd, int argc, char *argv[])
grab_owner();
if (alsa.owner) {
ast_queue_hangup(alsa.owner);
ast_mutex_unlock(&alsa.owner->lock);
ast_channel_unlock(alsa.owner);
}
}
@ -1010,7 +1010,6 @@ static int console_dial(int fd, int argc, char *argv[])
if (alsa.owner) {
if (argc == 3) {
d = argv[2];
grab_owner();
if (alsa.owner) {
struct ast_frame f = { AST_FRAME_DTMF };
while (*d) {
@ -1018,7 +1017,6 @@ static int console_dial(int fd, int argc, char *argv[])
ast_queue_frame(alsa.owner, &f);
d++;
}
ast_mutex_unlock(&alsa.owner->lock);
}
} else {
ast_cli(fd, "You're already in a call. You can use this only to dial digits until you hangup\n");

View File

@ -1596,14 +1596,14 @@ static int iax2_queue_frame(int callno, struct ast_frame *f)
{
for (;;) {
if (iaxs[callno] && iaxs[callno]->owner) {
if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
if (ast_channel_trylock(iaxs[callno]->owner)) {
/* Avoid deadlock by pausing and trying again */
ast_mutex_unlock(&iaxsl[callno]);
usleep(1);
ast_mutex_lock(&iaxsl[callno]);
} else {
ast_queue_frame(iaxs[callno]->owner, f);
ast_mutex_unlock(&iaxs[callno]->owner->lock);
ast_channel_unlock(iaxs[callno]->owner);
break;
}
} else
@ -1629,14 +1629,14 @@ static int iax2_queue_hangup(int callno)
{
for (;;) {
if (iaxs[callno] && iaxs[callno]->owner) {
if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
if (ast_channel_trylock(iaxs[callno]->owner)) {
/* Avoid deadlock by pausing and trying again */
ast_mutex_unlock(&iaxsl[callno]);
usleep(1);
ast_mutex_lock(&iaxsl[callno]);
} else {
ast_queue_hangup(iaxs[callno]->owner);
ast_mutex_unlock(&iaxs[callno]->owner->lock);
ast_channel_unlock(iaxs[callno]->owner);
break;
}
} else
@ -1663,14 +1663,14 @@ static int iax2_queue_control_data(int callno,
{
for (;;) {
if (iaxs[callno] && iaxs[callno]->owner) {
if (ast_mutex_trylock(&iaxs[callno]->owner->lock)) {
if (ast_channel_trylock(iaxs[callno]->owner)) {
/* Avoid deadlock by pausing and trying again */
ast_mutex_unlock(&iaxsl[callno]);
usleep(1);
ast_mutex_lock(&iaxsl[callno]);
} else {
ast_queue_control_data(iaxs[callno]->owner, control, data, datalen);
ast_mutex_unlock(&iaxs[callno]->owner->lock);
ast_channel_unlock(iaxs[callno]->owner);
break;
}
} else
@ -2109,7 +2109,7 @@ retry:
owner = pvt ? pvt->owner : NULL;
if (owner) {
if (ast_mutex_trylock(&owner->lock)) {
if (ast_channel_trylock(owner)) {
ast_log(LOG_NOTICE, "Avoiding IAX destroy deadlock\n");
ast_mutex_unlock(&iaxsl[callno]);
usleep(1);
@ -2160,7 +2160,7 @@ retry:
}
}
if (owner) {
ast_mutex_unlock(&owner->lock);
ast_channel_unlock(owner);
}
if (callno & 0x4000)
update_max_trunk();
@ -7543,7 +7543,7 @@ static int socket_process(struct iax2_thread *thread)
if (iaxs[fr->callno]->owner) {
int orignative;
retryowner:
if (ast_mutex_trylock(&iaxs[fr->callno]->owner->lock)) {
if (ast_channel_trylock(iaxs[fr->callno]->owner)) {
ast_mutex_unlock(&iaxsl[fr->callno]);
usleep(1);
ast_mutex_lock(&iaxsl[fr->callno]);
@ -7556,7 +7556,7 @@ retryowner:
if (iaxs[fr->callno]->owner->readformat)
ast_set_read_format(iaxs[fr->callno]->owner, iaxs[fr->callno]->owner->readformat);
iaxs[fr->callno]->owner->nativeformats = orignative;
ast_mutex_unlock(&iaxs[fr->callno]->owner->lock);
ast_channel_unlock(iaxs[fr->callno]->owner);
}
} else {
ast_debug(1, "Neat, somebody took away the channel at a magical time but i found it!\n");
@ -7971,7 +7971,7 @@ retryowner:
iaxs[fr->callno]->owner->nativeformats = iaxs[fr->callno]->peerformat;
ast_verb(3, "Format for call is %s\n", ast_getformatname(iaxs[fr->callno]->owner->nativeformats));
retryowner2:
if (ast_mutex_trylock(&iaxs[fr->callno]->owner->lock)) {
if (ast_channel_trylock(iaxs[fr->callno]->owner)) {
ast_mutex_unlock(&iaxsl[fr->callno]);
usleep(1);
ast_mutex_lock(&iaxsl[fr->callno]);
@ -7984,7 +7984,7 @@ retryowner2:
ast_set_write_format(iaxs[fr->callno]->owner, iaxs[fr->callno]->owner->writeformat);
if (iaxs[fr->callno]->owner->readformat)
ast_set_read_format(iaxs[fr->callno]->owner, iaxs[fr->callno]->owner->readformat);
ast_mutex_unlock(&iaxs[fr->callno]->owner->lock);
ast_channel_unlock(iaxs[fr->callno]->owner);
}
}
}

View File

@ -184,11 +184,11 @@ retrylock:
ast_clear_flag(p, LOCAL_GLARE_DETECT);
return 0;
}
if (ast_mutex_trylock(&other->lock)) {
if (ast_channel_trylock(other)) {
/* Failed to lock. Release main lock and try again */
ast_mutex_unlock(&p->lock);
if (us) {
if (ast_mutex_unlock(&us->lock)) {
if (ast_channel_unlock(us)) {
ast_log(LOG_WARNING, "%s wasn't locked while sending %d/%d\n",
us->name, f->frametype, f->subclass);
us = NULL;
@ -198,12 +198,12 @@ retrylock:
usleep(1);
/* Only we can destroy ourselves, so we can't disappear here */
if (us)
ast_mutex_lock(&us->lock);
ast_channel_lock(us);
ast_mutex_lock(&p->lock);
goto retrylock;
}
ast_queue_frame(other, f);
ast_mutex_unlock(&other->lock);
ast_channel_unlock(other);
ast_clear_flag(p, LOCAL_GLARE_DETECT);
return 0;
}
@ -245,16 +245,16 @@ static void check_bridge(struct local_pvt *p, int isoutbound)
/* Lock everything we need, one by one, and give up if
we can't get everything. Remember, we'll get another
chance in just a little bit */
if (!ast_mutex_trylock(&(p->chan->_bridge)->lock)) {
if (!ast_channel_trylock(p->chan->_bridge)) {
if (!ast_check_hangup(p->chan->_bridge)) {
if (!ast_mutex_trylock(&p->owner->lock)) {
if (!ast_channel_trylock(p->owner)) {
if (!ast_check_hangup(p->owner)) {
ast_channel_masquerade(p->owner, p->chan->_bridge);
ast_set_flag(p, LOCAL_ALREADY_MASQED);
}
ast_mutex_unlock(&p->owner->lock);
ast_channel_unlock(p->owner);
}
ast_mutex_unlock(&(p->chan->_bridge)->lock);
ast_channel_unlock(p->chan->_bridge);
}
}
/* We only allow masquerading in one 'direction'... it's important to preserve the state

View File

@ -599,9 +599,9 @@ static void mgcp_queue_frame(struct mgcp_subchannel *sub, struct ast_frame *f)
{
for(;;) {
if (sub->owner) {
if (!ast_mutex_trylock(&sub->owner->lock)) {
if (!ast_channel_trylock(sub->owner)) {
ast_queue_frame(sub->owner, f);
ast_mutex_unlock(&sub->owner->lock);
ast_channel_unlock(sub->owner);
break;
} else {
ast_mutex_unlock(&sub->lock);
@ -617,9 +617,9 @@ static void mgcp_queue_hangup(struct mgcp_subchannel *sub)
{
for(;;) {
if (sub->owner) {
if (!ast_mutex_trylock(&sub->owner->lock)) {
if (!ast_channel_trylock(sub->owner)) {
ast_queue_hangup(sub->owner);
ast_mutex_unlock(&sub->owner->lock);
ast_channel_unlock(sub->owner);
break;
} else {
ast_mutex_unlock(&sub->lock);

View File

@ -924,13 +924,13 @@ static void wakeup_sub(struct zt_pvt *p, int a, void *pri)
#endif
for (;;) {
if (p->subs[a].owner) {
if (ast_mutex_trylock(&p->subs[a].owner->lock)) {
if (ast_channel_trylock(p->subs[a].owner)) {
ast_mutex_unlock(&p->lock);
usleep(1);
ast_mutex_lock(&p->lock);
} else {
ast_queue_frame(p->subs[a].owner, &ast_null_frame);
ast_mutex_unlock(&p->subs[a].owner->lock);
ast_channel_unlock(p->subs[a].owner);
break;
}
} else
@ -971,13 +971,13 @@ static void zap_queue_frame(struct zt_pvt *p, struct ast_frame *f, void *data)
#endif
for (;;) {
if (p->owner) {
if (ast_mutex_trylock(&p->owner->lock)) {
if (ast_channel_trylock(p->owner)) {
ast_mutex_unlock(&p->lock);
usleep(1);
ast_mutex_lock(&p->lock);
} else {
ast_queue_frame(p->owner, f);
ast_mutex_unlock(&p->owner->lock);
ast_channel_unlock(p->owner);
break;
}
} else
@ -3474,23 +3474,22 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
if (flags & (AST_BRIDGE_DTMF_CHANNEL_0 | AST_BRIDGE_DTMF_CHANNEL_1))
return AST_BRIDGE_FAILED_NOWARN;
ast_mutex_lock(&c0->lock);
ast_mutex_lock(&c1->lock);
ast_channel_lock_both(c0, c1);
p0 = c0->tech_pvt;
p1 = c1->tech_pvt;
/* cant do pseudo-channels here */
if (!p0 || (!p0->sig) || !p1 || (!p1->sig)) {
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
return AST_BRIDGE_FAILED_NOWARN;
}
oi0 = zt_get_index(c0, p0, 0);
oi1 = zt_get_index(c1, p1, 0);
if ((oi0 < 0) || (oi1 < 0)) {
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
return AST_BRIDGE_FAILED;
}
@ -3503,16 +3502,16 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
if (ast_mutex_trylock(&p0->lock)) {
/* Don't block, due to potential for deadlock */
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
return AST_BRIDGE_RETRY;
}
if (ast_mutex_trylock(&p1->lock)) {
/* Don't block, due to potential for deadlock */
ast_mutex_unlock(&p0->lock);
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
ast_log(LOG_NOTICE, "Avoiding deadlock...\n");
return AST_BRIDGE_RETRY;
}
@ -3617,8 +3616,8 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
ast_mutex_unlock(&p0->lock);
ast_mutex_unlock(&p1->lock);
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
/* Native bridge failed */
if ((!master || !slave) && !nothingok) {
@ -3641,8 +3640,8 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
/* Here's our main loop... Start by locking things, looking for private parts,
and then balking if anything is wrong */
ast_mutex_lock(&c0->lock);
ast_mutex_lock(&c1->lock);
ast_channel_lock_both(c0, c1);
p0 = c0->tech_pvt;
p1 = c1->tech_pvt;
@ -3650,8 +3649,9 @@ static enum ast_bridge_result zt_bridge(struct ast_channel *c0, struct ast_chann
i0 = zt_get_index(c0, p0, 1);
if (op1 == p1)
i1 = zt_get_index(c1, p1, 1);
ast_mutex_unlock(&c0->lock);
ast_mutex_unlock(&c1->lock);
ast_channel_unlock(c0);
ast_channel_unlock(c1);
if (!timeoutms ||
(op0 != p0) ||
@ -3821,7 +3821,7 @@ static int attempt_transfer(struct zt_pvt *p)
return -1;
}
/* Orphan the channel after releasing the lock */
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
unalloc_sub(p, SUB_THREEWAY);
} else if (ast_bridged_channel(p->subs[SUB_THREEWAY].owner)) {
ast_queue_control(p->subs[SUB_REAL].owner, AST_CONTROL_UNHOLD);
@ -3850,7 +3850,7 @@ static int attempt_transfer(struct zt_pvt *p)
}
/* Three-way is now the REAL */
swap_subs(p, SUB_THREEWAY, SUB_REAL);
ast_mutex_unlock(&p->subs[SUB_REAL].owner->lock);
ast_channel_unlock(p->subs[SUB_REAL].owner);
unalloc_sub(p, SUB_THREEWAY);
/* Tell the caller not to hangup */
return 1;
@ -4167,15 +4167,15 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
unsigned int mssinceflash;
/* Here we have to retain the lock on both the main channel, the 3-way channel, and
the private structure -- not especially easy or clean */
while (p->subs[SUB_THREEWAY].owner && ast_mutex_trylock(&p->subs[SUB_THREEWAY].owner->lock)) {
while (p->subs[SUB_THREEWAY].owner && ast_channel_trylock(p->subs[SUB_THREEWAY].owner)) {
/* Yuck, didn't get the lock on the 3-way, gotta release everything and re-grab! */
ast_mutex_unlock(&p->lock);
ast_mutex_unlock(&ast->lock);
ast_channel_unlock(ast);
usleep(1);
/* We can grab ast and p in that order, without worry. We should make sure
nothing seriously bad has happened though like some sort of bizarre double
masquerade! */
ast_mutex_lock(&ast->lock);
ast_channel_lock(ast);
ast_mutex_lock(&p->lock);
if (p->owner != ast) {
ast_log(LOG_WARNING, "This isn't good...\n");
@ -4195,7 +4195,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
ast_queue_hangup(p->subs[SUB_THREEWAY].owner);
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
ast_debug(1, "Looks like a bounced flash, hanging up both calls on %d\n", p->channel);
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
} else if ((ast->pbx) || (ast->_state == AST_STATE_UP)) {
if (p->transfer) {
/* In any case this isn't a threeway call anymore */
@ -4203,7 +4203,7 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
p->subs[SUB_THREEWAY].inthreeway = 0;
/* Only attempt transfer if the phone is ringing; why transfer to busy tone eh? */
if (!p->transfertobusy && ast->_state == AST_STATE_BUSY) {
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
/* Swap subs and dis-own channel */
swap_subs(p, SUB_THREEWAY, SUB_REAL);
p->owner = NULL;
@ -4213,21 +4213,21 @@ static struct ast_frame *zt_handle_event(struct ast_channel *ast)
if ((res = attempt_transfer(p)) < 0) {
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
} else if (res) {
/* Don't actually hang up at this point */
if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
break;
}
}
} else {
p->subs[SUB_THREEWAY].owner->_softhangup |= AST_SOFTHANGUP_DEV;
if (p->subs[SUB_THREEWAY].owner)
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
}
} else {
ast_mutex_unlock(&p->subs[SUB_THREEWAY].owner->lock);
ast_channel_unlock(p->subs[SUB_THREEWAY].owner);
/* Swap subs and dis-own channel */
swap_subs(p, SUB_THREEWAY, SUB_REAL);
p->owner = NULL;
@ -9238,7 +9238,7 @@ static int pri_hangup_all(struct zt_pvt *p, struct zt_pri *pri)
do {
redo = 0;
for (x = 0; x < 3; x++) {
while (p->subs[x].owner && ast_mutex_trylock(&p->subs[x].owner->lock)) {
while (p->subs[x].owner && ast_channel_trylock(p->subs[x].owner)) {
redo++;
ast_mutex_unlock(&p->lock);
usleep(1);
@ -9246,7 +9246,7 @@ static int pri_hangup_all(struct zt_pvt *p, struct zt_pri *pri)
}
if (p->subs[x].owner) {
ast_queue_hangup(p->subs[x].owner);
ast_mutex_unlock(&p->subs[x].owner->lock);
ast_channel_unlock(p->subs[x].owner);
}
}
} while (redo);