[asterisk-commits] russell: trunk r82728 - in /trunk: apps/ channels/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Mon Sep 17 17:59:36 CDT 2007
Author: russell
Date: Mon Sep 17 17:59:36 2007
New Revision: 82728
URL: http://svn.digium.com/view/asterisk?view=rev&rev=82728
Log:
convert various places that access the channel lock directly to use the channel lock wrappers
Modified:
trunk/apps/app_zapscan.c
trunk/channels/chan_agent.c
trunk/channels/chan_alsa.c
trunk/channels/chan_iax2.c
trunk/channels/chan_local.c
trunk/channels/chan_mgcp.c
trunk/channels/chan_zap.c
Modified: trunk/apps/app_zapscan.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_zapscan.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/apps/app_zapscan.c (original)
+++ trunk/apps/app_zapscan.c Mon Sep 17 17:59:36 2007
@@ -332,7 +332,7 @@
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;
}
Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Mon Sep 17 17:59:36 2007
@@ -1183,10 +1183,8 @@
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");
Modified: trunk/channels/chan_alsa.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_alsa.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_alsa.c (original)
+++ trunk/channels/chan_alsa.c Mon Sep 17 17:59:36 2007
@@ -508,7 +508,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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");
Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Mon Sep 17 17:59:36 2007
@@ -1596,14 +1596,14 @@
{
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 @@
{
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 @@
{
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 @@
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 @@
}
}
if (owner) {
- ast_mutex_unlock(&owner->lock);
+ ast_channel_unlock(owner);
}
if (callno & 0x4000)
update_max_trunk();
@@ -7543,7 +7543,7 @@
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 @@
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 @@
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 @@
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);
}
}
}
Modified: trunk/channels/chan_local.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_local.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_local.c (original)
+++ trunk/channels/chan_local.c Mon Sep 17 17:59:36 2007
@@ -184,11 +184,11 @@
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 @@
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 @@
/* 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
Modified: trunk/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_mgcp.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_mgcp.c (original)
+++ trunk/channels/chan_mgcp.c Mon Sep 17 17:59:36 2007
@@ -599,9 +599,9 @@
{
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 @@
{
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);
Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?view=diff&rev=82728&r1=82727&r2=82728
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Mon Sep 17 17:59:36 2007
@@ -924,13 +924,13 @@
#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 @@
#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 @@
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 @@
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 @@
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 @@
/* 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 @@
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 @@
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 @@
}
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
}
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);
More information about the asterisk-commits
mailing list