[asterisk-commits] russell: branch russell/console_devices r99226 - /team/russell/console_device...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 22 10:39:05 CST 2008


Author: russell
Date: Sat Jan 19 23:41:06 2008
New Revision: 99226

URL: http://svn.digium.com/view/asterisk?view=rev&rev=99226
Log:
- fix finding the right input and output device for a non-default device
- make tracking of the active console device thread safe

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

Change Statistics:
 team/russell/console_devices/channels/chan_console.c |   37 +++++++---
 1 file changed, 26 insertions(+), 11 deletions(-)

Modified: team/russell/console_devices/channels/chan_console.c
URL: http://svn.digium.com/view/asterisk/team/russell/console_devices/channels/chan_console.c?view=diff&rev=99226&r1=99225&r2=99226
==============================================================================
--- team/russell/console_devices/channels/chan_console.c (original)
+++ team/russell/console_devices/channels/chan_console.c Sat Jan 19 23:41:06 2008
@@ -173,6 +173,7 @@
 #define NUM_PVT_BUCKETS 7
 
 static struct console_pvt *active_pvt;
+AST_RWLOCK_DEFINE_STATIC(active_lock);
 
 /*! 
  * \brief Global jitterbuffer configuration 
@@ -319,8 +320,8 @@
 		def_output = Pa_GetDefaultOutputDevice();
 
 		for (index = 0; 
-			index < num_devices && input_params.device == paNoDevice 
-				&& output_params.device == paNoDevice; 
+			index < num_devices && (input_params.device == paNoDevice 
+				|| output_params.device == paNoDevice); 
 			index++) 
 		{
 			const PaDeviceInfo *dev = Pa_GetDeviceInfo(index);
@@ -365,7 +366,7 @@
 
 	res = open_stream(pvt);
 	if (res != paNoError) {
-		ast_log(LOG_WARNING, "Failed to open default audio device - (%d) %s\n",
+		ast_log(LOG_WARNING, "Failed to open stream - (%d) %s\n",
 			res, Pa_GetErrorText(res));
 		ret_val = -1;
 		goto return_unlock;
@@ -673,10 +674,21 @@
 	return *ext;
 }
 
+static struct console_pvt *get_active_pvt(void)
+{
+	struct console_pvt *pvt;
+
+	ast_rwlock_rdlock(&active_lock);
+	pvt = ref_pvt(active_pvt);	
+	ast_rwlock_unlock(&active_lock);
+
+	return pvt;
+}
+
 static char *cli_console_autoanswer(struct ast_cli_entry *e, int cmd, 
 	struct ast_cli_args *a)
 {
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 	char *res = CLI_SUCCESS;
 
 	switch (cmd) {
@@ -724,7 +736,7 @@
 static char *cli_console_flash(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH };
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 
 	if (cmd == CLI_INIT) {
 		e->command = "console flash";
@@ -762,7 +774,7 @@
 {
 	char *s = NULL;
 	const char *mye = NULL, *myc = NULL; 
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 
 	if (cmd == CLI_INIT) {
 		e->command = "console dial";
@@ -834,7 +846,7 @@
 
 static char *cli_console_hangup(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 
 	if (cmd == CLI_INIT) {
 		e->command = "console hangup";
@@ -871,7 +883,7 @@
 static char *cli_console_mute(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char *s;
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 	char *res = CLI_SUCCESS;
 
 	if (cmd == CLI_INIT) {
@@ -1017,7 +1029,7 @@
 static char *cli_console_answer(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_ANSWER };
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -1067,7 +1079,7 @@
 static char *cli_console_sendtext(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 {
 	char buf[TEXT_SIZE];
-	struct console_pvt *pvt = ref_pvt(active_pvt);
+	struct console_pvt *pvt = get_active_pvt();
 	struct ast_frame f = {
 		.frametype = AST_FRAME_TEXT,
 		.data = buf,
@@ -1185,10 +1197,11 @@
 	if (!ast_true(value))
 		return;
 
+	ast_rwlock_wrlock(&active_lock);
 	if (active_pvt)
 		unref_pvt(active_pvt);
-	
 	active_pvt = ref_pvt(pvt);
+	ast_rwlock_unlock(&active_lock);
 }
 
 /*!
@@ -1286,8 +1299,10 @@
 	while ((pvt = ao2_iterator_next(&i))) {
 		if (pvt->destroy) {
 			ao2_unlink(pvts, pvt);
+			ast_rwlock_wrlock(&active_lock);
 			if (active_pvt == pvt)
 				active_pvt = unref_pvt(pvt);
+			ast_rwlock_unlock(&active_lock);
 		}
 		unref_pvt(pvt);
 	}




More information about the asterisk-commits mailing list