[asterisk-commits] moy: branch moy/mfcr2 r129306 - /team/moy/mfcr2/channels/chan_zap.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jul 8 22:38:30 CDT 2008
Author: moy
Date: Tue Jul 8 22:38:29 2008
New Revision: 129306
URL: http://svn.digium.com/view/asterisk?view=rev&rev=129306
Log:
fixed race condition between incoming and outgoing calls over the same pvt structure
Modified:
team/moy/mfcr2/channels/chan_zap.c
Modified: team/moy/mfcr2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2/channels/chan_zap.c?view=diff&rev=129306&r1=129305&r2=129306
==============================================================================
--- team/moy/mfcr2/channels/chan_zap.c (original)
+++ team/moy/mfcr2/channels/chan_zap.c Tue Jul 8 22:38:29 2008
@@ -1285,16 +1285,22 @@
static void zt_r2_on_call_init(openr2_chan_t *r2chan)
{
+ /* TODO: how do we know that an external thread (just finished zt_request) is not requesting this very same
+ interface but has not yet seized the line, and if we DO know, what to do here? */
struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_mutex_lock(&p->lock);
p->mfcr2call = 1;
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_NOTICE, "New MFC/R2 call detected on chan %d.\n", openr2_chan_get_number(r2chan));
}
static void zt_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm)
{
struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_mutex_lock(&p->lock);
+ p->inalarm = alarm ? 1 : 0;
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_WARNING, "Zap alarm on chan %d.\n", openr2_chan_get_number(r2chan));
- p->inalarm = alarm ? 1 : 0;
}
static void zt_r2_on_os_error(openr2_chan_t *r2chan, int errorcode)
@@ -1310,6 +1316,9 @@
p->owner->hangupcause = AST_CAUSE_PROTOCOL_ERROR;
p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
}
+ ast_mutex_lock(&p->lock);
+ p->mfcr2call = 0;
+ ast_mutex_unlock(&p->lock);
}
static void zt_r2_on_call_offered(openr2_chan_t *r2chan, const char *ani, const char *dnis, openr2_calling_party_category_t category)
@@ -1346,7 +1355,11 @@
static void zt_r2_on_call_end(openr2_chan_t *r2chan)
{
- ast_log(LOG_NOTICE, "MFC/R2 call end on chan %d\n", openr2_chan_get_number(r2chan));
+ struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_log(LOG_NOTICE, "MFC/R2 call end on chan %d\n", p->channel);
+ ast_mutex_lock(&p->lock);
+ p->mfcr2call = 0;
+ ast_mutex_unlock(&p->lock);
}
static void zt_r2_update_monitor_count(struct zt_mfcr2 *mfcr2, int increment)
@@ -1437,9 +1450,11 @@
{
struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
ast_log(LOG_NOTICE, "MFC/R2 call disconnected on chan %d\n", openr2_chan_get_number(r2chan));
+ ast_mutex_lock(&p->lock);
if (p->owner) {
if (p->owner->_state == AST_STATE_UP) {
p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
+ ast_mutex_unlock(&p->lock);
} else if (openr2_chan_get_direction(r2chan) == OR2_DIR_FORWARD) {
/* being the forward side we must report what happened to the call to whoever requested it */
switch (cause) {
@@ -1457,7 +1472,9 @@
default:
p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
}
+ ast_mutex_unlock(&p->lock);
} else {
+ ast_mutex_unlock(&p->lock);
/* being the backward side and not UP yet, we only need to request hangup */
/* TODO: what about doing this same thing when were AST_STATE_UP? */
ast_queue_hangup_with_cause(p->owner, zt_r2_cause_to_ast_cause(cause));
@@ -1495,11 +1512,19 @@
static void zt_r2_on_line_blocked(openr2_chan_t *r2chan)
{
+ struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_mutex_lock(&p->lock);
+ p->remotelyblocked = 1;
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_NOTICE, "Far end blocked on chan %d\n", openr2_chan_get_number(r2chan));
}
static void zt_r2_on_line_idle(openr2_chan_t *r2chan)
{
+ struct zt_pvt *p = openr2_chan_get_client_data(r2chan);
+ ast_mutex_lock(&p->lock);
+ p->remotelyblocked = 0;
+ ast_mutex_unlock(&p->lock);
ast_log(LOG_NOTICE, "Far end unblocked on chan %d\n", openr2_chan_get_number(r2chan));
}
@@ -10565,9 +10590,6 @@
if (mfcr2->pvts[i]->owner) {
continue;
}
- if (mfcr2->pvts[i]->mfcr2call) {
- mfcr2->pvts[i]->mfcr2call = 0;
- }
openr2_chan_enable_read(mfcr2->pvts[i]->r2chan);
pollers[i].events = POLLIN | POLLPRI;
pollers[i].fd = mfcr2->pvts[i]->subs[SUB_REAL].zfd;
@@ -12742,7 +12764,9 @@
continue;
}
openr2_proto_set_idle(p->r2chan);
- openr2_proto_handle_abcd_change(p->r2chan);
+ ast_mutex_lock(&p->lock);
+ p->locallyblocked = 0;
+ ast_mutex_unlock(&p->lock);
if (channo != -1) {
break;
} else {
@@ -12785,7 +12809,9 @@
continue;
}
openr2_proto_set_blocked(p->r2chan);
- openr2_proto_handle_abcd_change(p->r2chan);
+ ast_mutex_lock(&p->lock);
+ p->locallyblocked = 1;
+ ast_mutex_unlock(&p->lock);
if (channo != -1) {
break;
} else {
More information about the asterisk-commits
mailing list