[svn-commits] russell: branch 1.4 r94801 - /branches/1.4/main/autoservice.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Dec 26 13:04:32 CST 2007


Author: russell
Date: Wed Dec 26 13:04:31 2007
New Revision: 94801

URL: http://svn.digium.com/view/asterisk?view=rev&rev=94801
Log:
Just in case the AST_FLAG_END_DTMF_ONLY flag was already set before starting
autoservice, remember it and ensure that the channel has the same setting when
autoservice gets stopped.  (pointed out by d1mas, patched up by me)

Modified:
    branches/1.4/main/autoservice.c

Modified: branches/1.4/main/autoservice.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/autoservice.c?view=diff&rev=94801&r1=94800&r2=94801
==============================================================================
--- branches/1.4/main/autoservice.c (original)
+++ branches/1.4/main/autoservice.c Wed Dec 26 13:04:31 2007
@@ -58,6 +58,7 @@
 	 *  channel.  It will ensure that it doesn't actually get stopped until 
 	 *  it gets stopped for the last time. */
 	unsigned int use_count;
+	unsigned int orig_end_dtmf_flag:1;
 	AST_LIST_HEAD_NOLOCK(, ast_frame) dtmf_frames;
 	AST_LIST_ENTRY(asent) list;
 };
@@ -157,42 +158,51 @@
 	int res = 0;
 	struct asent *as;
 
-	AST_LIST_LOCK(&aslist);
-
 	/* Check if the channel already has autoservice */
+	AST_LIST_LOCK(&aslist);
 	AST_LIST_TRAVERSE(&aslist, as, list) {
 		if (as->chan == chan) {
 			as->use_count++;
 			break;
 		}
 	}
-
-	/* If not, start autoservice on channel */
+	AST_LIST_UNLOCK(&aslist);
+
 	if (as) {
-		/* Entry extist, autoservice is already handling this channel */
-	} else if ((as = ast_calloc(1, sizeof(*as))) == NULL) {
-		/* Memory allocation failed */
-		res = -1;
-	} else {
-		/* New entry created */
-		as->chan = chan;
+		/* Entry exists, autoservice is already handling this channel */
+		return 0;
+	}
+
+	if (!(as = ast_calloc(1, sizeof(*as))))
+		return -1;
+	
+	/* New entry created */
+	as->chan = chan;
+	as->use_count = 1;
+
+	ast_channel_lock(chan);
+	as->orig_end_dtmf_flag = ast_test_flag(chan, AST_FLAG_END_DTMF_ONLY) ? 1 : 0;
+	if (!as->orig_end_dtmf_flag)
 		ast_set_flag(chan, AST_FLAG_END_DTMF_ONLY);
-		as->use_count = 1;
-		AST_LIST_INSERT_HEAD(&aslist, as, list);
-		if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
-			if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
-				ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
-				/* There will only be a single member in the list at this point,
-				   the one we just added. */
-				AST_LIST_REMOVE(&aslist, as, list);
-				free(as);
-				res = -1;
-			} else
-				pthread_kill(asthread, SIGURG);
-		}
-	}
-
-	AST_LIST_UNLOCK(&aslist);
+	ast_channel_unlock(chan);
+
+	AST_LIST_LOCK(&aslist);
+	AST_LIST_INSERT_HEAD(&aslist, as, list);
+	AST_LIST_UNLOCK(&aslist);
+
+	if (asthread == AST_PTHREADT_NULL) { /* need start the thread */
+		if (ast_pthread_create_background(&asthread, NULL, autoservice_run, NULL)) {
+			ast_log(LOG_WARNING, "Unable to create autoservice thread :(\n");
+			/* There will only be a single member in the list at this point,
+			   the one we just added. */
+			AST_LIST_LOCK(&aslist);
+			AST_LIST_REMOVE(&aslist, as, list);
+			AST_LIST_UNLOCK(&aslist);
+			free(as);
+			res = -1;
+		} else
+			pthread_kill(asthread, SIGURG);
+	}
 
 	return res;
 }
@@ -204,6 +214,7 @@
 	AST_LIST_HEAD_NOLOCK(, ast_frame) dtmf_frames;
 	struct ast_frame *f;
 	int removed = 0;
+	int orig_end_dtmf_flag = 0;
 
 	AST_LIST_HEAD_INIT_NOLOCK(&dtmf_frames);
 
@@ -215,11 +226,11 @@
 				break;
 			AST_LIST_REMOVE_CURRENT(&aslist, list);
 			AST_LIST_APPEND_LIST(&dtmf_frames, &as->dtmf_frames, frame_list);
+			orig_end_dtmf_flag = as->orig_end_dtmf_flag;
 			free(as);
 			removed = 1;
 			if (!chan->_softhangup)
 				res = 0;
-			ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
 			break;
 		}
 	}
@@ -232,6 +243,9 @@
 
 	if (!removed)
 		return 0;
+
+	if (!orig_end_dtmf_flag)
+		ast_clear_flag(chan, AST_FLAG_END_DTMF_ONLY);
 
 	/* Wait for it to un-block */
 	while (ast_test_flag(chan, AST_FLAG_BLOCKING))




More information about the svn-commits mailing list