[svn-commits] kpfleming: branch 1.4 r46083 - /branches/1.4/main/translate.c

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Oct 23 20:53:32 MST 2006


Author: kpfleming
Date: Mon Oct 23 22:53:32 2006
New Revision: 46083

URL: http://svn.digium.com/view/asterisk?rev=46083&view=rev
Log:
ensure that the translation matrix is properly lock-protected every place it is used

Modified:
    branches/1.4/main/translate.c

Modified: branches/1.4/main/translate.c
URL: http://svn.digium.com/view/asterisk/branches/1.4/main/translate.c?rev=46083&r1=46082&r2=46083&view=diff
==============================================================================
--- branches/1.4/main/translate.c (original)
+++ branches/1.4/main/translate.c Mon Oct 23 22:53:32 2006
@@ -63,6 +63,9 @@
  * until step->dstfmt == desired_format.
  *
  * Array indexes are 'src' and 'dest', in that order.
+ *
+ * Note: the lock in the 'translators' list is also used to protect
+ * this structure.
  */
 static struct translator_path tr_matrix[MAX_FORMAT][MAX_FORMAT];
 
@@ -253,18 +256,22 @@
 	source = powerof(source);
 	dest = powerof(dest);
 	
+	AST_LIST_LOCK(&translators);
+
 	while (source != dest) {
 		struct ast_trans_pvt *cur;
 		struct ast_translator *t = tr_matrix[source][dest].step;
 		if (!t) {
 			ast_log(LOG_WARNING, "No translator path from %s to %s\n", 
 				ast_getformatname(source), ast_getformatname(dest));
+			AST_LIST_UNLOCK(&translators);
 			return NULL;
 		}
 		if (!(cur = newpvt(t))) {
 			ast_log(LOG_WARNING, "Failed to build translator step from %d to %d\n", source, dest);
 			if (head)
 				ast_translator_free_path(head);	
+			AST_LIST_UNLOCK(&translators);
 			return NULL;
 		}
 		if (!head)
@@ -276,6 +283,8 @@
 		/* Keep going if this isn't the final destination */
 		source = cur->t->dstfmt;
 	}
+
+	AST_LIST_UNLOCK(&translators);
 	return head;
 }
 
@@ -768,13 +777,20 @@
 
 unsigned int ast_translate_path_steps(unsigned int dest, unsigned int src)
 {
+	unsigned int res = -1;
+
 	/* convert bitwise format numbers into array indices */
 	src = powerof(src);
 	dest = powerof(dest);
-	if (!tr_matrix[src][dest].step)
-		return -1;
-	else
-		return tr_matrix[src][dest].multistep + 1;
+
+	AST_LIST_LOCK(&translators);
+
+	if (tr_matrix[src][dest].step)
+		res = tr_matrix[src][dest].multistep + 1;
+
+	AST_LIST_UNLOCK(&translators);
+
+	return res;
 }
 
 unsigned int ast_translate_available_formats(unsigned int dest, unsigned int src)
@@ -783,6 +799,8 @@
 	unsigned int x;
 	unsigned int src_audio = powerof(src & AST_FORMAT_AUDIO_MASK);
 	unsigned int src_video = powerof(src & AST_FORMAT_VIDEO_MASK);
+
+	AST_LIST_LOCK(&translators);
 
 	for (x = 1; x < AST_FORMAT_MAX_AUDIO; x <<= 1) {
 		/* if this is not a desired format, nothing to do */
@@ -817,5 +835,7 @@
 			res &= ~x;
 	}
 
+	AST_LIST_UNLOCK(&translators);
+
 	return res;
 }



More information about the svn-commits mailing list