[asterisk-commits] moy: branch moy/mfcr2-1.4 r129309 - /team/moy/mfcr2-1.4/channels/chan_zap.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jul 8 23:17:26 CDT 2008


Author: moy
Date: Tue Jul  8 23:17:25 2008
New Revision: 129309

URL: http://svn.digium.com/view/asterisk?view=rev&rev=129309
Log:
fixed race condition between incoming and outgoing calls

Modified:
    team/moy/mfcr2-1.4/channels/chan_zap.c

Modified: team/moy/mfcr2-1.4/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2-1.4/channels/chan_zap.c?view=diff&rev=129309&r1=129308&r2=129309
==============================================================================
--- team/moy/mfcr2-1.4/channels/chan_zap.c (original)
+++ team/moy/mfcr2-1.4/channels/chan_zap.c Tue Jul  8 23:17:25 2008
@@ -899,16 +899,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)
@@ -924,6 +930,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)
@@ -960,7 +969,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)
@@ -1051,9 +1064,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) {
@@ -1071,7 +1086,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(p->owner);
@@ -8547,9 +8564,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;
@@ -10639,7 +10653,6 @@
 			continue;
 		}
 		openr2_proto_set_idle(p->r2chan);
-		openr2_proto_handle_abcd_change(p->r2chan);
 		if (channo != -1) {
 			break;
 		} else {
@@ -10670,7 +10683,6 @@
 			continue;
 		}
 		openr2_proto_set_blocked(p->r2chan);
-		openr2_proto_handle_abcd_change(p->r2chan);
 		if (channo != -1) {
 			break;
 		} else {




More information about the asterisk-commits mailing list