[asterisk-commits] moy: branch moy/mfcr2 r175922 - /team/moy/mfcr2/channels/chan_dahdi.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Feb 15 18:05:00 CST 2009


Author: moy
Date: Sun Feb 15 18:05:00 2009
New Revision: 175922

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=175922
Log:
change strategy for allocation of r2links, now we allocate an r2link per each 10 channels

Modified:
    team/moy/mfcr2/channels/chan_dahdi.c

Modified: team/moy/mfcr2/channels/chan_dahdi.c
URL: http://svn.digium.com/svn-view/asterisk/team/moy/mfcr2/channels/chan_dahdi.c?view=diff&rev=175922&r1=175921&r2=175922
==============================================================================
--- team/moy/mfcr2/channels/chan_dahdi.c (original)
+++ team/moy/mfcr2/channels/chan_dahdi.c Sun Feb 15 18:05:00 2009
@@ -473,12 +473,10 @@
 	openr2_calling_party_category_t category;
 };
 
-/* malloc'd r2links */
+/* malloc'd array of malloc'd r2links */
 static struct dahdi_mfcr2 **r2links; 
 /* how many r2links have been malloc'd */
-static int r2links_count; 
-/* current link when configuring */
-static int r2links_index; 
+static int r2links_count = 0; 
 
 #endif /* HAVE_OPENR2 */
 
@@ -9555,31 +9553,34 @@
 	ast_free(r2links);
 	r2links = NULL;
 	r2links_count = 0;
-	r2links_index = 0;
-}
-
+}
+
+#define R2_LINK_CAPACITY 10
 static struct dahdi_mfcr2 *dahdi_r2_get_link(void)
 {
 	struct dahdi_mfcr2 *new_r2link = NULL;
 	struct dahdi_mfcr2 **new_r2links = NULL;
-	if (r2links_index == r2links_count) {
+	/* this function is called just when starting up and no monitor threads have been launched, 
+	   no need to lock monitored_count member */
+	if (!r2links_count || (r2links[r2links_count - 1]->monitored_count == R2_LINK_CAPACITY)) {
 		new_r2link = ast_calloc(1, sizeof(**r2links));
 		if (!new_r2link) {
-			ast_log(LOG_ERROR, "Cannot allocate another R2 link!\n");
+			ast_log(LOG_ERROR, "Cannot allocate R2 link!\n");
 			return NULL;
 		}
 		new_r2links = ast_realloc(r2links, ((r2links_count + 1) * sizeof(*r2links)));
 		if (!new_r2links) {
-			ast_log(LOG_ERROR, "Cannot allocate another R2 link!\n");
+			ast_log(LOG_ERROR, "Cannot allocate R2 link!\n");
 			ast_free(new_r2link);
 			return NULL;
 		}
 		r2links = new_r2links;
 		new_r2link->r2master = AST_PTHREADT_NULL;
-		r2links[r2links_index] = new_r2link;
+		r2links[r2links_count] = new_r2link;
 		r2links_count++;
-	}
-	return r2links[r2links_index];
+		ast_log(LOG_DEBUG, "Created new R2 link!\n");
+	}
+	return r2links[r2links_count - 1];
 }
 
 static int dahdi_r2_set_context(struct dahdi_mfcr2 *r2_link, const struct dahdi_chan_conf *conf)
@@ -11603,7 +11604,6 @@
 	while (1) {
 		/* we trust here that the mfcr2 channel list will not ever change once
 		   the module is loaded */
-		nextms = openr2_context_get_time_to_next_event(mfcr2->protocol_context);
 		ast_mutex_lock(&mfcr2->monitored_count_lock);
 		if (mfcr2->monitored_count == 0) {
 			ast_log(LOG_DEBUG, "No one requires my monitoring services :-(\n");
@@ -11630,6 +11630,7 @@
 		if (quit_loop) {
 			break;
 		}
+		nextms = openr2_context_get_time_to_next_event(mfcr2->protocol_context);
 		/* probably poll() is a valid cancel point, lets just be on the safe side
 		   by calling pthread_testcancel */
 		pthread_testcancel();
@@ -15605,11 +15606,6 @@
 				return -1;
 			}
 		}
-#ifdef HAVE_OPENR2
-		if ((reload != 1) && (r2links_index < r2links_count) && r2links[r2links_index]->protocol_context) {
-			r2links_index++;
-		}
-#endif
 	}
 
 	return 0;




More information about the asterisk-commits mailing list