[asterisk-commits] mmichelson: branch group/CCSS r247740 - /team/group/CCSS/main/ccss.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Feb 18 15:08:46 CST 2010


Author: mmichelson
Date: Thu Feb 18 15:08:42 2010
New Revision: 247740

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=247740
Log:
Change from doubly-linked lists to singly-linked lists.

The change made two commits ago to allow for all devices to be added to
the CC_INTERFACES channel variable changed how list traversal is done
when making monitor callbacks. The result is that there is no longer
a good reason to be using doubly-linked lists. Therefore, they have
been removed. The backwards traversals are all forward traversals now.


Modified:
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=247740&r1=247739&r2=247740
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Thu Feb 18 15:08:42 2010
@@ -163,7 +163,7 @@
  * to use it, and it may last beyond the lifetime of a single
  * thread.
  */
-AST_DLLIST_HEAD(ast_cc_interface_tree, ast_cc_monitor);
+AST_LIST_HEAD(ast_cc_interface_tree, ast_cc_monitor);
 
 /*!
  * \internal
@@ -1372,13 +1372,13 @@
 {
 	struct ast_cc_interface_tree *cc_interface_tree = data;
 	struct ast_cc_monitor *monitor;
-	while ((monitor = AST_DLLIST_REMOVE_HEAD(cc_interface_tree, next))) {
+	while ((monitor = AST_LIST_REMOVE_HEAD(cc_interface_tree, next))) {
 		if (monitor->callbacks) {
 			monitor->callbacks->cancel_available_timer(monitor, &monitor->available_timer_id);
 		}
 		cc_unref(monitor, "Destroying all monitors");
 	}
-	AST_DLLIST_HEAD_DESTROY(cc_interface_tree);
+	AST_LIST_HEAD_DESTROY(cc_interface_tree);
 }
 
 /*!
@@ -1561,22 +1561,22 @@
 	id = cc_interfaces->dial_parent_id;
 	ast_channel_unlock(incoming);
 
-	AST_DLLIST_LOCK(interface_tree);
-	AST_DLLIST_TRAVERSE(interface_tree, monitor, next) {
+	AST_LIST_LOCK(interface_tree);
+	AST_LIST_TRAVERSE(interface_tree, monitor, next) {
 		if (monitor->id == id) {
 			break;
 		}
 	}
 
 	if (!monitor) {
-		AST_DLLIST_UNLOCK(interface_tree);
+		AST_LIST_UNLOCK(interface_tree);
 		cc_unref(interface_tree, "Done with interface tree");
 		return;
 	}
 
 	extension_pvt = monitor->private_data;
 	if (!(child_dialstring = ast_calloc(1, sizeof(*child_dialstring)))) {
-		AST_DLLIST_UNLOCK(interface_tree);
+		AST_LIST_UNLOCK(interface_tree);
 		cc_unref(interface_tree, "Done with interface tree");
 		return;
 	}
@@ -1584,7 +1584,7 @@
 	ast_copy_string(child_dialstring->device_name, device_name, sizeof(child_dialstring->device_name));
 	child_dialstring->is_valid = 1;
 	AST_LIST_INSERT_TAIL(&extension_pvt->child_dialstrings, child_dialstring, next);
-	AST_DLLIST_UNLOCK(interface_tree);
+	AST_LIST_UNLOCK(interface_tree);
 	cc_unref(interface_tree, "Done with interface tree");
 }
 
@@ -1594,7 +1594,7 @@
 	struct extension_monitor_pvt *extension_pvt;
 	struct extension_child_dialstring *child_dialstring;
 
-	AST_DLLIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->id == parent_id) {
 			break;
 		}
@@ -1715,8 +1715,8 @@
 	}
 
 	/* Finally, all that allocation is done... */
-	AST_DLLIST_HEAD_INIT(interfaces->interface_tree);
-	AST_DLLIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
+	AST_LIST_HEAD_INIT(interfaces->interface_tree);
+	AST_LIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
 	cc_ref(monitor, "List's reference to extension monitor");
 	dial_cc_datastore->data = interfaces;
 	dial_cc_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
@@ -1918,17 +1918,17 @@
 	 * This traversal helps us to not create duplicate tree items in
 	 * case a device queues multiple CC control frames.
 	 */
-	AST_DLLIST_LOCK(cc_interfaces->interface_tree);
-	AST_DLLIST_TRAVERSE(cc_interfaces->interface_tree, monitor, next) {
+	AST_LIST_LOCK(cc_interfaces->interface_tree);
+	AST_LIST_TRAVERSE(cc_interfaces->interface_tree, monitor, next) {
 		if (!strcmp(monitor->interface->device_name, device_name)) {
 			ast_log_dynamic_level(cc_logger_level, "Device %s sent us multiple CC control frames. Ignoring those beyond the first.\n", device_name);
-			AST_DLLIST_UNLOCK(cc_interfaces->interface_tree);
+			AST_LIST_UNLOCK(cc_interfaces->interface_tree);
 			cc_unref(core_instance, "Returning early from ast_handle_cc_control_frame");
 			call_destructor_with_no_monitor(cc_data->monitor_type, cc_data->private_data);
 			return;
 		}
 	}
-	AST_DLLIST_UNLOCK(cc_interfaces->interface_tree);
+	AST_LIST_UNLOCK(cc_interfaces->interface_tree);
 
 	if (!(monitor = cc_device_monitor_init(device_name, dialstring, cc_data, cc_interfaces->core_id))) {
 		ast_log(LOG_WARNING, "Unable to create CC device interface for '%s'. CC services will be unavailable on this interface.\n", device_name);
@@ -1937,10 +1937,10 @@
 		return;
 	}
 
-	AST_DLLIST_LOCK(cc_interfaces->interface_tree);
+	AST_LIST_LOCK(cc_interfaces->interface_tree);
 	cc_ref(monitor, "Interface tree's reference to the monitor");
-	AST_DLLIST_INSERT_TAIL(cc_interfaces->interface_tree, monitor, next);
-	AST_DLLIST_UNLOCK(cc_interfaces->interface_tree);
+	AST_LIST_INSERT_TAIL(cc_interfaces->interface_tree, monitor, next);
+	AST_LIST_UNLOCK(cc_interfaces->interface_tree);
 
 	cc_extension_monitor_change_is_valid(core_instance, monitor->parent_id, monitor->interface->device_name, 0);
 
@@ -2022,10 +2022,10 @@
 	 * on the datastore, so we need to copy that into this monitor.
 	 */
 	monitor->dialstring = ast_strdup(interfaces->current_extension_dialstring);
-	AST_DLLIST_LOCK(interfaces->interface_tree);
+	AST_LIST_LOCK(interfaces->interface_tree);
 	cc_ref(monitor, "Interface tree's reference to the monitor");
-	AST_DLLIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
-	AST_DLLIST_UNLOCK(interfaces->interface_tree);
+	AST_LIST_INSERT_TAIL(interfaces->interface_tree, monitor, next);
+	AST_LIST_UNLOCK(interfaces->interface_tree);
 	interfaces->dial_parent_id = monitor->id;
 	cc_unref(monitor, "Unref monitor's allocation reference");
 	return 0;
@@ -2587,7 +2587,7 @@
 	struct ast_cc_monitor *iter;
 	int res = 0;
 
-	AST_DLLIST_TRAVERSE(core_instance->monitors, iter, next) {
+	AST_LIST_TRAVERSE(core_instance->monitors, iter, next) {
 		if (iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			res = 1;
 			break;
@@ -2600,11 +2600,11 @@
 static void request_cc(struct cc_core_instance *core_instance)
 {
 	struct ast_cc_monitor *monitor_iter;
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			if (monitor_iter->callbacks->request_cc(monitor_iter, &monitor_iter->available_timer_id)) {
-				AST_DLLIST_REMOVE_CURRENT(next);
+				AST_LIST_REMOVE_CURRENT(next);
 				cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id, 
 						monitor_iter->interface->device_name, 1);
 				cc_unref(monitor_iter, "request_cc failed. Unref list's reference to monitor");
@@ -2617,12 +2617,12 @@
 			}
 		}
 	}
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (!has_device_monitors(core_instance)) {
 		ast_cc_failed(core_instance->core_id, "All device monitors failed to request CC");
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 }
 
 static int cc_caller_requested(struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
@@ -2644,23 +2644,23 @@
 static void unsuspend(struct cc_core_instance *core_instance)
 {
 	struct ast_cc_monitor *monitor_iter;
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			if (monitor_iter->callbacks->unsuspend(monitor_iter)) {
-				AST_DLLIST_REMOVE_CURRENT(next);
+				AST_LIST_REMOVE_CURRENT(next);
 				cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id, 
 						monitor_iter->interface->device_name, 1);
 				cc_unref(monitor_iter, "unsuspend failed. Unref list's reference to monitor");
 			}
 		}
 	}
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (!has_device_monitors(core_instance)) {
 		ast_cc_failed(core_instance->core_id, "All device monitors failed to unsuspend CC");
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 }
 
 static int cc_active(struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
@@ -2694,23 +2694,23 @@
 static void suspend(struct cc_core_instance *core_instance)
 {
 	struct ast_cc_monitor *monitor_iter;
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			if (monitor_iter->callbacks->suspend(monitor_iter)) {
-				AST_DLLIST_REMOVE_CURRENT(next);
+				AST_LIST_REMOVE_CURRENT(next);
 				cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id, 
 						monitor_iter->interface->device_name, 1);
 				cc_unref(monitor_iter, "suspend failed. Unref list's reference to monitor");
 			}
 		}
 	}
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (!has_device_monitors(core_instance)) {
 		ast_cc_failed(core_instance->core_id, "All device monitors failed to suspend CC");
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 }
 
 static int cc_caller_busy(struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
@@ -2730,23 +2730,23 @@
 static void cancel_available_timer(struct cc_core_instance *core_instance)
 {
 	struct ast_cc_monitor *monitor_iter;
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			if (monitor_iter->callbacks->cancel_available_timer(monitor_iter, &monitor_iter->available_timer_id)) {
-				AST_DLLIST_REMOVE_CURRENT(next);
+				AST_LIST_REMOVE_CURRENT(next);
 				cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id, 
 						monitor_iter->interface->device_name, 1);
 				cc_unref(monitor_iter, "cancel_available_timer failed. Unref list's reference to monitor");
 			}
 		}
 	}
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (!has_device_monitors(core_instance)) {
 		ast_cc_failed(core_instance->core_id, "All device monitors failed to cancel their available timers");
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 }
 
 static int cc_recalling(struct cc_core_instance *core_instance, struct cc_state_change_args *args, enum cc_state previous_state)
@@ -2999,18 +2999,18 @@
 	 * Now we need to find out if the channel device name
 	 * is in the list of interfaces in the called tree.
 	 */
-	AST_DLLIST_LOCK(interface_tree);
-	AST_DLLIST_TRAVERSE(interface_tree, device_monitor, next) {
+	AST_LIST_LOCK(interface_tree);
+	AST_LIST_TRAVERSE(interface_tree, device_monitor, next) {
 		if (!strcmp(device_monitor->interface->device_name, device_name) &&
 				!strcmp(device_monitor->interface->monitor_type, monitor_type)) {
 			/* BOOM! Device is in the tree! We have a winner! */
 			*core_id = core_id_candidate;
-			AST_DLLIST_UNLOCK(interface_tree);
+			AST_LIST_UNLOCK(interface_tree);
 			cc_unref(interface_tree, "Found a match in recall tree.");
 			return 1;
 		}
 	}
-	AST_DLLIST_UNLOCK(interface_tree);
+	AST_LIST_UNLOCK(interface_tree);
 	cc_unref(interface_tree, "No match in recall tree.");
 	return 0;
 }
@@ -3024,15 +3024,15 @@
 		return NULL;
 	}
 
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
 		if (!strcmp(monitor_iter->interface->device_name, device_name)) {
 			/* Found a monitor. */
 			cc_ref(monitor_iter, "Hand the requester of the monitor a reference");
 			break;
 		}
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 	cc_unref(core_instance, "Done with core instance ref in ast_cc_get_monitor_by_recall_core_id");
 	return monitor_iter;
 }
@@ -3070,7 +3070,7 @@
 	}
 
 	/* And now we get the dialstrings from each of the device monitors */
-	while ((monitor_iter = AST_DLLIST_NEXT(monitor_iter, next))) {
+	while ((monitor_iter = AST_LIST_NEXT(monitor_iter, next))) {
 		if (monitor_iter->parent_id == top_level_id) {
 			cc_unique_append(var_value, monitor_iter->dialstring);
 		}
@@ -3102,10 +3102,10 @@
 	interface_tree = cc_ref(recall_data->interface_tree, "Getting ref of recall interface tree");
 	ast_channel_unlock(chan);
 
-	AST_DLLIST_LOCK(interface_tree);
-	monitor = AST_DLLIST_FIRST(interface_tree);
+	AST_LIST_LOCK(interface_tree);
+	monitor = AST_LIST_FIRST(interface_tree);
 	set_cc_interfaces_chanvar(monitor, chan);
-	AST_DLLIST_UNLOCK(interface_tree);
+	AST_LIST_UNLOCK(interface_tree);
 
 	cc_unref(interface_tree, "Done with interface tree while setting CC_INTERFACES");
 	return 0;
@@ -3127,8 +3127,8 @@
 	interface_tree = cc_ref(recall_data->interface_tree, "Get reference to recall data interface tree");
 	ast_channel_unlock(chan);
 
-	AST_DLLIST_LOCK(interface_tree);
-	AST_DLLIST_TRAVERSE(interface_tree, monitor_iter, next) {
+	AST_LIST_LOCK(interface_tree);
+	AST_LIST_TRAVERSE(interface_tree, monitor_iter, next) {
 		if (!strcmp(monitor_iter->interface->device_name, extension)) {
 			break;
 		}
@@ -3139,13 +3139,13 @@
 		 * we have been directed into an unexpected extension because
 		 * the admin has changed a CC_INTERFACES variable at some point.
 		 */
-		AST_DLLIST_UNLOCK(interface_tree);
+		AST_LIST_UNLOCK(interface_tree);
 		cc_unref(interface_tree, "Couldn't find the extension specified");
 		return -1;
 	}
 
 	set_cc_interfaces_chanvar(monitor_iter, chan);
-	AST_DLLIST_UNLOCK(interface_tree);
+	AST_LIST_UNLOCK(interface_tree);
 	cc_unref(interface_tree, "Done writing the CC_INTERFACES channel variable");
 	return 0;
 }
@@ -3344,11 +3344,11 @@
 		return -1;
 	}
 
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
 			if (!strcmp(monitor_iter->interface->device_name, failure_data->device_name)) {
-				AST_DLLIST_REMOVE_CURRENT(next);
+				AST_LIST_REMOVE_CURRENT(next);
 				cc_extension_monitor_change_is_valid(core_instance, monitor_iter->parent_id, 
 						monitor_iter->interface->device_name, 1);
 				monitor_iter->callbacks->cancel_available_timer(monitor_iter, &monitor_iter->available_timer_id);
@@ -3356,12 +3356,12 @@
 			}
 		}
 	}
-	AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
+	AST_LIST_TRAVERSE_SAFE_END;
 
 	if (!has_device_monitors(core_instance)) {
 		ast_cc_failed(core_instance->core_id, "All monitors have failed\n");
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 	cc_unref(core_instance, "Finished with core_instance in cc_monitor_failed\n");
 
 	ast_free((char *) failure_data->device_name);
@@ -3506,14 +3506,14 @@
 
 	ast_free(args);
 
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
 		if (monitor_iter->interface->monitor_class == AST_CC_DEVICE_MONITOR &&
 				monitor_iter->callbacks->status_response) {
 			monitor_iter->callbacks->status_response(monitor_iter, devstate);
 		}
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 	cc_unref(core_instance, "Status response finished. Unref core instance");
 	return 0;
 }
@@ -3759,15 +3759,15 @@
 	const char *monitor_type = cb_data->monitor_type;
 	struct ast_cc_monitor *monitor_iter;
 
-	AST_DLLIST_LOCK(core_instance->monitors);
-	AST_DLLIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
+	AST_LIST_LOCK(core_instance->monitors);
+	AST_LIST_TRAVERSE(core_instance->monitors, monitor_iter, next) {
 		if (!strcmp(monitor_iter->interface->device_name, device_name) && 
 				!strcmp(monitor_iter->interface->monitor_type, monitor_type)) {
 			cb_data->count++;
 			break;
 		}
 	}
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_UNLOCK(core_instance->monitors);
 	return 0;
 }
 
@@ -3825,7 +3825,7 @@
 	}
 	ast_cli(fd, "\n");
 
-	while ((child_monitor_iter = AST_DLLIST_NEXT(child_monitor_iter, next))) {
+	while ((child_monitor_iter = AST_LIST_NEXT(child_monitor_iter, next))) {
 		if (child_monitor_iter->parent_id == monitor->id) {
 			cc_cli_print_monitor_stats(child_monitor_iter, fd, child_monitor_iter->id);
 		}
@@ -3839,9 +3839,9 @@
 
 	ast_cli(*cli_fd, "%d\t\t%s\t\t%s\n", core_instance->core_id, core_instance->agent->device_name,
 			cc_state_to_string(core_instance->current_state));
-	AST_DLLIST_LOCK(core_instance->monitors);
-	cc_cli_print_monitor_stats(AST_DLLIST_FIRST(core_instance->monitors), *cli_fd, 0);
-	AST_DLLIST_UNLOCK(core_instance->monitors);
+	AST_LIST_LOCK(core_instance->monitors);
+	cc_cli_print_monitor_stats(AST_LIST_FIRST(core_instance->monitors), *cli_fd, 0);
+	AST_LIST_UNLOCK(core_instance->monitors);
 	return 0;
 }
 




More information about the asterisk-commits mailing list