[asterisk-commits] mmichelson: branch group/CCSS r219815 - in /team/group/CCSS: include/asterisk...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 22 15:34:57 CDT 2009


Author: mmichelson
Date: Tue Sep 22 15:34:54 2009
New Revision: 219815

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219815
Log:
Logic for canceling the available timer.

Tested and it works like a charm. There's a new monitor
callback now for canceling the available timer.


Modified:
    team/group/CCSS/include/asterisk/ccss.h
    team/group/CCSS/main/ccss.c

Modified: team/group/CCSS/include/asterisk/ccss.h
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/include/asterisk/ccss.h?view=diff&rev=219815&r1=219814&r2=219815
==============================================================================
--- team/group/CCSS/include/asterisk/ccss.h (original)
+++ team/group/CCSS/include/asterisk/ccss.h Tue Sep 22 15:34:54 2009
@@ -564,6 +564,15 @@
 	/* Unsuspend monitoring callback */
 	int (*unsuspend)(struct ast_cc_monitor *monitor, const int core_id);
 	/*!
+	 * Cancel the running available timer.
+	 *
+	 * In most cases, this function will likely consist of just a 
+	 * call to AST_SCHED_DEL. It might have been possible to do this
+	 * within the core, but unfortunately the mixture of sched_thread
+	 * and sched usage in Asterisk prevents such usage.
+	 */
+	int (*cancel_available_timer)(struct ast_cc_monitor *monitor, const int core_id, int *sched_id);
+	/*!
 	 * Destroy callback 
 	 *
 	 * This destructor is never called directly. Instead, it is passed

Modified: team/group/CCSS/main/ccss.c
URL: http://svnview.digium.com/svn/asterisk/team/group/CCSS/main/ccss.c?view=diff&rev=219815&r1=219814&r2=219815
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Tue Sep 22 15:34:54 2009
@@ -996,6 +996,7 @@
 		if (link_iter->core_id == core_id) {
 			prune_links(link_iter->child, core_id, link_iter);
 			AST_LIST_REMOVE_CURRENT(next_child);
+			link_iter->child->callbacks->cancel_available_timer(link_iter->child, core_id, &link_iter->child_avail_id);
 			destroy_link(link_iter);
 		}
 	}
@@ -1250,6 +1251,7 @@
 			ast_log(LOG_NOTICE, "Invalid state change request. Cannot go from %d to %d\n", core_instance->current_state, args->state);
 		}
 		core_instance->current_state = args->state;
+		core_instance->monitor->callbacks->cancel_available_timer(core_instance->monitor, core_instance->core_id, NULL);
 		core_instance->agent->callbacks->recall(core_instance->agent);
 		break;
 	case CC_COMPLETE:
@@ -1366,6 +1368,7 @@
 static int cc_extension_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id);
 static enum ast_device_state cc_extension_monitor_status_request(struct ast_cc_monitor *monitor, const int core_id);
 static int cc_extension_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id);
+static int cc_extension_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id);
 static void cc_extension_monitor_destructor(void *monitor);
 
 static struct ast_cc_monitor_callbacks extension_monitor_cbs = {
@@ -1375,6 +1378,7 @@
 	.suspend = cc_extension_monitor_suspend,
 	.status_request = cc_extension_monitor_status_request,
 	.unsuspend = cc_extension_monitor_unsuspend,
+	.cancel_available_timer = cc_extension_monitor_cancel_available_timer,
 	.destructor = cc_extension_monitor_destructor,
 };
 
@@ -1455,6 +1459,20 @@
 	return 0;
 }
 
+static int cc_extension_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id)
+{
+	struct ast_cc_monitor_link *link_iter;
+	AST_LIST_TRAVERSE(&monitor->child_links, link_iter, next_child) {
+		if (link_iter->core_id != core_id) {
+			continue;
+		}
+		ast_assert(link_iter->child != NULL);
+		ast_assert(link_iter->child->callbacks != NULL);
+		link_iter->child->callbacks->cancel_available_timer(link_iter->child, core_id, &link_iter->child_avail_id);
+	}
+	return 0;
+}
+
 static void cc_extension_monitor_destructor(void *monitor)
 {
 	struct ast_cc_monitor *mon = monitor;
@@ -1468,6 +1486,7 @@
 static int cc_generic_monitor_suspend(struct ast_cc_monitor *monitor, const int core_id);
 static enum ast_device_state cc_generic_monitor_status_request(struct ast_cc_monitor *monitor, const int core_id);
 static int cc_generic_monitor_unsuspend(struct ast_cc_monitor *monitor, const int core_id);
+static int cc_generic_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id);
 static void cc_generic_monitor_destructor(void *monitor);
 
 static struct ast_cc_monitor_callbacks generic_monitor_cbs = {
@@ -1477,6 +1496,7 @@
 	.suspend = cc_generic_monitor_suspend,
 	.status_request = cc_generic_monitor_status_request,
 	.unsuspend = cc_generic_monitor_unsuspend,
+	.cancel_available_timer = cc_generic_monitor_cancel_available_timer,
 	.destructor = cc_generic_monitor_destructor,
 };
 
@@ -1529,6 +1549,12 @@
 	 */
 	prune_links(child_monitor, core_id, link);
 	AST_LIST_REMOVE(&parent_monitor->child_links, link, next_child);
+	/* We need to set the scheduler ID to -1 here so that 
+	 * the cancel_available_timer callback will know not to
+	 * try to delete the scheduler entry while the scheduler
+	 * callback is running.
+	 */
+	link->child_avail_id = -1;
 	destroy_link(link);
 
 	/* Of course, if this link is the only remaining child
@@ -1633,6 +1659,20 @@
 	return 0;
 }
 
+
+static int cc_generic_monitor_cancel_available_timer(struct ast_cc_monitor *monitor, const int core_id, int *sched_id)
+{
+	ast_assert(sched_id != NULL);
+
+	if (*sched_id == -1) {
+		return 0;
+	}
+
+	ast_log(LOG_NOTICE, "Canceling generic monitor available timer for monitor %s\n", monitor->interface->name);
+	ast_sched_thread_del(cc_sched_thread, *sched_id);
+	return 0;
+}
+
 static void cc_generic_monitor_destructor(void *monitor)
 {
 	struct ast_cc_monitor *mon = monitor;




More information about the asterisk-commits mailing list