[svn-commits] russell: branch russell/sla_updates r54139 - /team/russell/sla_updates/apps/

svn-commits at lists.digium.com svn-commits at lists.digium.com
Mon Feb 12 13:34:46 MST 2007


Author: russell
Date: Mon Feb 12 14:34:46 2007
New Revision: 54139

URL: http://svn.digium.com/view/asterisk?view=rev&rev=54139
Log:
Instead of having the SLA thread sit in a busy loop while there are trunks that
are ringing, always wait on the thread condition at the top of the loop until
signalled by one of the following:
 - the dial API state change callback
 - a ringing trunk being added/removed
 - sla_destroy() when the module is being unloaded

Modified:
    team/russell/sla_updates/apps/app_meetme.c

Modified: team/russell/sla_updates/apps/app_meetme.c
URL: http://svn.digium.com/view/asterisk/team/russell/sla_updates/apps/app_meetme.c?view=diff&rev=54139&r1=54138&r2=54139
==============================================================================
--- team/russell/sla_updates/apps/app_meetme.c (original)
+++ team/russell/sla_updates/apps/app_meetme.c Mon Feb 12 14:34:46 2007
@@ -3025,6 +3025,13 @@
 	return NULL;
 }
 
+static void sla_dial_state_callback(struct ast_dial *dial)
+{
+	ast_mutex_lock(&sla.lock);
+	ast_cond_signal(&sla.cond);
+	ast_mutex_unlock(&sla.lock);
+}
+
 static void *sla_thread(void *data)
 {
 	AST_LIST_HEAD_NOLOCK_STATIC(ringing_stations, sla_station_ref);
@@ -3037,18 +3044,16 @@
 	struct sla_station_ref *station_ref;
 	struct sla_failed_station *failed_station;
 
+	ast_mutex_lock(&sla.lock);
+
 	for (; !sla.stop;) {
 		struct sla_trunk_ref *trunk_ref = NULL;
 		struct sla_event *event;
 		enum ast_dial_result dial_res = AST_DIAL_RESULT_TRYING;
 
-		ast_mutex_lock(&sla.lock);
-		if (AST_LIST_EMPTY(&sla.ringing_trunks) && AST_LIST_EMPTY(&sla.event_q)) {
-			ast_cond_wait(&sla.cond, &sla.lock);
-			if (sla.stop)
-				break;
-			ast_log(LOG_DEBUG, "Ooh, I was woken up!\n");
-		}
+		ast_cond_wait(&sla.cond, &sla.lock);
+		if (sla.stop)
+			break;
 
 		while ((event = AST_LIST_REMOVE_HEAD(&sla.event_q, entry))) {
 			switch (event->type) {
@@ -3107,6 +3112,7 @@
 					continue;
 				if (!(dial = ast_dial_create()))
 					continue;
+				ast_dial_set_state_callback(dial, sla_dial_state_callback);
 				tech_data = ast_strdupa(station_ref->station->device);
 				tech = strsep(&tech_data, "/");
 				if (ast_dial_append(dial, tech, tech_data) == -1) {
@@ -3132,7 +3138,6 @@
 				ast_log(LOG_DEBUG, "Started dialing station '%s'\n", station_ref->station->name);
 			}
 		}
-		ast_mutex_unlock(&sla.lock);
 		/* Now, all of the stations that should be ringing, are ringing. */
 		
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&ringing_stations, station_ref, entry) {
@@ -3159,7 +3164,6 @@
 				AST_LIST_REMOVE_CURRENT(&ringing_stations, entry);
 				/* Find the appropriate trunk to answer. */
 				AST_LIST_TRAVERSE(&station_ref->station->trunks, s_trunk_ref, entry) {
-					ast_mutex_lock(&sla.lock);
 					AST_LIST_TRAVERSE_SAFE_BEGIN(&sla.ringing_trunks, trunk_ref, entry) {
 						if (s_trunk_ref->trunk == trunk_ref->trunk) {
 							AST_LIST_REMOVE_CURRENT(&sla.ringing_trunks, entry);
@@ -3167,7 +3171,6 @@
 						}
 					}
 					AST_LIST_TRAVERSE_SAFE_END
-					ast_mutex_unlock(&sla.lock);
 					if (trunk_ref)
 						break;
 				}
@@ -3211,12 +3214,10 @@
 		AST_LIST_TRAVERSE_SAFE_BEGIN(&ringing_stations, station_ref, entry) {
 			AST_LIST_TRAVERSE(&station_ref->station->trunks, trunk_ref, entry) {
 				struct sla_trunk_ref *ringing_ref;
-				ast_mutex_lock(&sla.lock);
 				AST_LIST_TRAVERSE(&sla.ringing_trunks, ringing_ref, entry) {
 					if (trunk_ref->trunk == ringing_ref->trunk)
 						break;
 				}
-				ast_mutex_unlock(&sla.lock);
 				if (ringing_ref)
 					break;
 			}
@@ -3230,6 +3231,8 @@
 		}
 		AST_LIST_TRAVERSE_SAFE_END
 	}
+
+	ast_mutex_unlock(&sla.lock);
 
 	while ((station_ref = AST_LIST_REMOVE_HEAD(&ringing_stations, entry)))
 		free(station_ref);
@@ -3493,8 +3496,7 @@
 	change_trunk_state(trunk, SLA_TRUNK_STATE_RINGING, 0);
 
 	ast_mutex_lock(&sla.lock);
-	if (AST_LIST_EMPTY(&sla.ringing_trunks))
-		ast_cond_signal(&sla.cond);
+	ast_cond_signal(&sla.cond);
 	AST_LIST_INSERT_HEAD(&sla.ringing_trunks, trunk_ref, entry);
 	ast_mutex_unlock(&sla.lock);
 



More information about the svn-commits mailing list