[Asterisk-cvs] asterisk channel.c,1.90,1.91

markster at lists.digium.com markster at lists.digium.com
Fri Apr 2 16:58:51 CST 2004


Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv23961

Modified Files:
	channel.c 
Log Message:
Fix generator race (bug #1202)


Index: channel.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channel.c,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -d -r1.90 -r1.91
--- channel.c	27 Mar 2004 07:34:37 -0000	1.90
+++ channel.c	2 Apr 2004 21:58:10 -0000	1.91
@@ -743,7 +743,9 @@
 	return 0;
 }
 
-void ast_deactivate_generator(struct ast_channel *chan)
+
+
+static void __ast_deactivate_generator(struct ast_channel *chan)
 {
 	if (chan->generatordata) {
 		if (chan->generator && chan->generator->release) 
@@ -754,6 +756,12 @@
 	}
 }
 
+void ast_deactivate_generator(struct ast_channel *chan)
+{
+	ast_mutex_lock(&chan->lock);
+	__ast_deactivate_generator(chan);
+	ast_mutex_unlock(&chan->lock);
+}
 int ast_activate_generator(struct ast_channel *chan, struct ast_generator *gen, void *params)
 {
 	if (chan->generatordata) {
@@ -1059,7 +1067,7 @@
 	/* Stop if we're a zombie or need a soft hangup */
 	if (chan->zombie || ast_check_hangup(chan)) {
 		if (chan->generator)
-			ast_deactivate_generator(chan);
+			__ast_deactivate_generator(chan);
 		ast_mutex_unlock(&chan->lock);
 		return NULL;
 	}
@@ -1193,7 +1201,7 @@
 	if (!f) {
 		chan->_softhangup |= AST_SOFTHANGUP_DEV;
 		if (chan->generator)
-			ast_deactivate_generator(chan);
+			__ast_deactivate_generator(chan);
 		/* End the CDR if appropriate */
 		if (chan->cdr)
 			ast_cdr_end(chan->cdr);
@@ -1208,21 +1216,25 @@
 		ast_setstate(chan, AST_STATE_UP);
 		ast_cdr_answer(chan->cdr);
 	} 
-	ast_mutex_unlock(&chan->lock);
 
 	/* Run any generator sitting on the line */
 	if (f && (f->frametype == AST_FRAME_VOICE) && chan->generatordata) {
 		/* Mask generator data temporarily */
 		void *tmp;
 		int res;
+		int (*generate)(struct ast_channel *chan, void *tmp, int datalen, int samples);
 		tmp = chan->generatordata;
 		chan->generatordata = NULL;
-		res = chan->generator->generate(chan, tmp, f->datalen, f->samples);
+		generate = chan->generator->generate;
+		ast_mutex_unlock(&chan->lock);
+		res = generate(chan, tmp, f->datalen, f->samples);
+		ast_mutex_lock(&chan->lock);
 		chan->generatordata = tmp;
 		if (res) {
 			ast_log(LOG_DEBUG, "Auto-deactivating generator\n");
-			ast_deactivate_generator(chan);
+			__ast_deactivate_generator(chan);
 		}
+		ast_mutex_unlock(&chan->lock);
 	}
 	if (chan->fin & 0x80000000)
 		ast_frame_dump(chan->name, f, "<<");
@@ -1230,6 +1242,7 @@
 		chan->fin &= 0x80000000;
 	else
 		chan->fin++;
+	ast_mutex_unlock(&chan->lock);
 	return f;
 }
 
@@ -1415,7 +1428,7 @@
 	}
 	if (chan->generatordata) {
 		if (chan->writeinterrupt)
-			ast_deactivate_generator(chan);
+			__ast_deactivate_generator(chan);
 		else {
 			ast_mutex_unlock(&chan->lock);
 			return 0;




More information about the svn-commits mailing list