[asterisk-commits] branch 1.2 - r7709 /branches/1.2/apps/app_mixmonitor.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Mon Jan 2 01:31:55 CST 2006


Author: tilghman
Date: Mon Jan  2 01:31:54 2006
New Revision: 7709

URL: http://svn.digium.com/view/asterisk?rev=7709&view=rev
Log:
Bug 6084 - MixMonitor after a 'cli stop monitor' deadlocks

Modified:
    branches/1.2/apps/app_mixmonitor.c

Modified: branches/1.2/apps/app_mixmonitor.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/apps/app_mixmonitor.c?rev=7709&r1=7708&r2=7709&view=diff
==============================================================================
--- branches/1.2/apps/app_mixmonitor.c (original)
+++ branches/1.2/apps/app_mixmonitor.c Mon Jan  2 01:31:54 2006
@@ -79,6 +79,7 @@
 static const char *mixmonitor_spy_type = "MixMonitor";
 
 struct mixmonitor {
+	AST_LIST_ENTRY(mixmonitor) list;
 	struct ast_channel *chan;
 	char *filename;
 	char *post_process;
@@ -87,12 +88,15 @@
 	int writevol;
 };
 
+AST_LIST_HEAD_STATIC(monitors, mixmonitor);
+
 enum {
 	MUXFLAG_APPEND = (1 << 1),
 	MUXFLAG_BRIDGED = (1 << 2),
 	MUXFLAG_VOLUME = (1 << 3),
 	MUXFLAG_READVOLUME = (1 << 4),
 	MUXFLAG_WRITEVOLUME = (1 << 5),
+	FLAG_STOP = (1 << 6),
 } mixmonitor_flags;
 
 enum {
@@ -156,6 +160,10 @@
 	char post_process[1024] = "";
 	
 	STANDARD_INCREMENT_USECOUNT;
+
+	AST_LIST_LOCK(&monitors);
+	AST_LIST_INSERT_HEAD(&monitors, mixmonitor, list);
+	AST_LIST_UNLOCK(&monitors);
 
 	name = ast_strdupa(mixmonitor->chan->name);
 
@@ -211,7 +219,7 @@
 
 		ast_channel_spy_trigger_wait(&spy);
 		
-		if (ast_check_hangup(mixmonitor->chan) || spy.status != CHANSPY_RUNNING) {
+		if (ast_check_hangup(mixmonitor->chan) || spy.status != CHANSPY_RUNNING || ast_test_flag(mixmonitor, FLAG_STOP)) {
 			ast_mutex_unlock(&spy.lock);
 			break;
 		}
@@ -237,6 +245,8 @@
 		ast_mutex_unlock(&spy.lock);
 	}
 	
+	stopmon(mixmonitor->chan, &spy);
+
 	if (mixmonitor->post_process) {
 		char *p;
 
@@ -248,8 +258,6 @@
 		pbx_substitute_variables_helper(mixmonitor->chan, mixmonitor->post_process, post_process, sizeof(post_process) - 1);
 	}
 
-	stopmon(mixmonitor->chan, &spy);
-
 	if (option_verbose > 1)
 		ast_verbose(VERBOSE_PREFIX_2 "End MixMonitor Recording %s\n", name);
 
@@ -266,6 +274,10 @@
 		ast_closestream(fs);
 
 out:
+	AST_LIST_LOCK(&monitors);
+	AST_LIST_REMOVE(&monitors, mixmonitor, list);
+	AST_LIST_UNLOCK(&monitors);
+
 	free(mixmonitor);
 
 	STANDARD_DECREMENT_USECOUNT;
@@ -396,6 +408,7 @@
 static int mixmonitor_cli(int fd, int argc, char **argv) 
 {
 	struct ast_channel *chan;
+	struct mixmonitor *mon;
 
 	if (argc < 3)
 		return RESULT_SHOWUSAGE;
@@ -407,8 +420,13 @@
 
 	if (!strcasecmp(argv[1], "start"))
 		mixmonitor_exec(chan, argv[3]);
-	else if (!strcasecmp(argv[1], "stop"))
-		ast_channel_spy_stop_by_type(chan, mixmonitor_spy_type);
+	else if (!strcasecmp(argv[1], "stop")) {
+		AST_LIST_TRAVERSE_SAFE_BEGIN(&monitors, mon, list) {
+			if (chan == mon->chan)
+				ast_set_flag(mon, FLAG_STOP);
+		}
+		AST_LIST_TRAVERSE_SAFE_END;
+	}
 
 	ast_mutex_unlock(&chan->lock);
 



More information about the asterisk-commits mailing list