[svn-commits] moy: branch moy/mfcr2-1.2 r129308 - /team/moy/mfcr2-1.2/channels/chan_zap.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 8 22:47:27 CDT 2008


Author: moy
Date: Tue Jul  8 22:47:26 2008
New Revision: 129308

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

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

Modified: team/moy/mfcr2-1.2/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/moy/mfcr2-1.2/channels/chan_zap.c?view=diff&rev=129308&r1=129307&r2=129308
==============================================================================
--- team/moy/mfcr2-1.2/channels/chan_zap.c (original)
+++ team/moy/mfcr2-1.2/channels/chan_zap.c Tue Jul  8 22:47:26 2008
@@ -1308,16 +1308,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)
@@ -1333,6 +1339,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)
@@ -1369,7 +1378,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)
@@ -1461,9 +1474,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) {
@@ -1481,7 +1496,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? */
 			p->owner->_softhangup |= AST_SOFTHANGUP_DEV;
@@ -9908,9 +9925,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;
@@ -10138,7 +10152,6 @@
 			continue;
 		}
 		openr2_proto_set_idle(p->r2chan);
-		openr2_proto_handle_abcd_change(p->r2chan);
 		if (channo != -1) {
 			break;
 		} else {
@@ -10169,7 +10182,6 @@
 			continue;
 		}
 		openr2_proto_set_blocked(p->r2chan);
-		openr2_proto_handle_abcd_change(p->r2chan);
 		if (channo != -1) {
 			break;
 		} else {




More information about the svn-commits mailing list