[asterisk-commits] russell: branch russell/chan_console r49043 - /team/russell/chan_console/chan...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Thu Dec 28 17:06:59 MST 2006


Author: russell
Date: Thu Dec 28 18:06:59 2006
New Revision: 49043

URL: http://svn.digium.com/view/asterisk?view=rev&rev=49043
Log:
Move console_lock into the singleton instance of the pvt struct to start
preparing for multiple device support.

Modified:
    team/russell/chan_console/channels/chan_console.c

Modified: team/russell/chan_console/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/russell/chan_console/channels/chan_console.c?view=diff&rev=49043&r1=49042&r2=49043
==============================================================================
--- team/russell/chan_console/channels/chan_console.c (original)
+++ team/russell/chan_console/channels/chan_console.c Thu Dec 28 18:06:59 2006
@@ -66,15 +66,15 @@
 	char write_buf[NUM_SAMPLES * 2];
 	unsigned int write_dst;
 	ast_cond_t cond;
+	ast_mutex_t lock;
 	unsigned int hookstate:1;
 	unsigned int overridecontext:1;
 	unsigned int incallback:1;
 	AST_LIST_HEAD_NOLOCK(, ast_frame) frames;
 } pvt = {
 	.name = "default",
+	.lock = AST_MUTEX_INIT_VALUE,
 };
-
-AST_MUTEX_DEFINE_STATIC(console_lock);
 
 /*! Global jitterbuffer configuration - by default, jb is disabled */
 static struct ast_jb_conf default_jbconf = {
@@ -120,7 +120,7 @@
 };
 
 /*!
- * \note Called with console_lock locked
+ * \note Called with the pvt struct locked
  */
 static struct ast_channel *console_new(struct console_pvt *pvt, const char *ext, const char *ctx, int state)
 {
@@ -166,14 +166,13 @@
 		return NULL;
 	}
 
-	ast_mutex_lock(&console_lock);
+	ast_mutex_lock(&pvt.lock);
 	if (pvt.owner) {
 		ast_log(LOG_NOTICE, "Console channel already active!\n");
 		*cause = AST_CAUSE_BUSY;
 	} else if (!(chan = console_new(&pvt, NULL, NULL, AST_STATE_DOWN)))
 		ast_log(LOG_WARNING, "Unable to create new Console channel!\n");
-
-	ast_mutex_unlock(&console_lock);
+	ast_mutex_unlock(&pvt.lock);
 
 	return chan;
 }
@@ -208,9 +207,9 @@
 	pvt.hookstate = 0;
 
 	while (pvt.incallback) { /* :( */
-		ast_mutex_lock(&console_lock);
+		ast_mutex_lock(&pvt.lock);
 		ast_cond_signal(&pvt.cond);
-		ast_mutex_unlock(&console_lock);
+		ast_mutex_unlock(&pvt.lock);
 		usleep(10);
 	}
 
@@ -227,10 +226,10 @@
 
 	ast_verbose(" -=- Call from Console has been Answered -=-\n");
 
-	ast_mutex_lock(&console_lock);
+	ast_mutex_lock(&pvt.lock);
 	ast_setstate(c, AST_STATE_UP);
 	res = start_stream();
-	ast_mutex_unlock(&console_lock);
+	ast_mutex_unlock(&pvt.lock);
 
 	return res;
 }
@@ -267,10 +266,10 @@
 
 	if (!fr)
 		return -1; 
-	ast_mutex_lock(&console_lock);
+	ast_mutex_lock(&pvt.lock);
 	AST_LIST_INSERT_TAIL(&pvt.frames, fr, frame_list);
 	ast_cond_signal(&pvt.cond);
-	ast_mutex_unlock(&console_lock);
+	ast_mutex_unlock(&pvt.lock);
 
 	return 0;
 }
@@ -303,9 +302,9 @@
 
 static int console_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
 {
-	ast_mutex_lock(&console_lock);
+	ast_mutex_lock(&pvt.lock);
 	pvt.owner = newchan;
-	ast_mutex_unlock(&console_lock);
+	ast_mutex_unlock(&pvt.lock);
 
 	return 0;
 }
@@ -320,7 +319,7 @@
 		unsigned int src = 0;
 		unsigned int num_samples;
 		struct ast_frame *fr;
-		ast_mutex_lock(&console_lock);
+		ast_mutex_lock(&pvt.lock);
 		if (pvt.write_dst) {
 			num_samples = (pvt.write_dst * 2) > frame_count ? pvt.write_dst * 2 : frame_count;
 			memcpy(output, &pvt.write_buf, num_samples * 2);
@@ -330,11 +329,11 @@
 		}
 		while (frame_count) { 
 			while (!(fr = AST_LIST_REMOVE_HEAD(&pvt.frames, frame_list))) {
-				ast_cond_wait(&pvt.cond, &console_lock);
+				ast_cond_wait(&pvt.cond, &pvt.lock);
 				if (!pvt.hookstate) {
 					if (fr)
 						ast_frfree(fr);
-					ast_mutex_unlock(&console_lock);
+					ast_mutex_unlock(&pvt.lock);
 					pvt.incallback = 0;
 					return paAbort;	
 				}
@@ -348,7 +347,7 @@
 			}
 			ast_frfree(fr);
 		}
-		ast_mutex_unlock(&console_lock);
+		ast_mutex_unlock(&pvt.lock);
 
 		if (frame_count) {
 			ast_log(LOG_WARNING, "console_callback didn't get %lu of the samples it wanted :(\n", frame_count);
@@ -565,15 +564,15 @@
 }
 
 /*!
- * \note Called with console_lock locked
+ * \note Called with pvt struct locked
  */
 static int stop_stream(void)
 {
-	ast_mutex_lock(&console_lock);
+	ast_mutex_lock(&pvt.lock);
 	Pa_AbortStream(pvt.stream);
 	Pa_CloseStream(pvt.stream);
 	ast_cond_signal(&pvt.cond);
-	ast_mutex_unlock(&console_lock);
+	ast_mutex_unlock(&pvt.lock);
 
 	return 0;
 }



More information about the asterisk-commits mailing list