[asterisk-commits] mmichelson: branch group/CCSS r219947 - /team/group/CCSS/main/ccss.c
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Sep 23 16:46:41 CDT 2009
Author: mmichelson
Date: Wed Sep 23 16:46:38 2009
New Revision: 219947
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=219947
Log:
Make a cc_ref and cc_unref macro.
This is for convenience and I find the code to be a bit
easier to understand this way. Also, this will help me
with the upcoming refcount work I need to do.
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=219947&r1=219946&r2=219947
==============================================================================
--- team/group/CCSS/main/ccss.c (original)
+++ team/group/CCSS/main/ccss.c Wed Sep 23 16:46:38 2009
@@ -85,6 +85,9 @@
const struct ast_cc_agent_callbacks *callbacks;
};
+#define cc_ref(obj, debug) ({ao2_t_ref((obj), +1, (debug)); (obj);})
+#define cc_unref(obj, debug) ({ao2_t_ref((obj), -1, (debug)); NULL;})
+
/* XXX I'm making these defaults up right now with no real regard for
* what they *should* be. This can be revisited.
*/
@@ -621,8 +624,7 @@
ast_free(agent);
return NULL;
}
- ao2_t_ref(interface_tree, +1, "Agent now has reference to interface tree");
- agent->interface_tree = interface_tree;
+ agent->interface_tree = cc_ref(interface_tree, "Agent now has reference to interface tree");
ast_log(LOG_NOTICE, "I created an agent with core_id %d and caller %s\n", agent->core_id, agent->interface);
return agent;
}
@@ -679,12 +681,12 @@
core_instance->core_id = ast_atomic_fetchadd_int(&core_id_counter, +1);
if (!(core_instance->agent = cc_agent_init(caller_chan, caller, core_instance->core_id, called_tree))) {
- ao2_t_ref(core_instance, -1, "Couldn't allocate agent, unref core_instance");
+ cc_unref(core_instance, "Couldn't allocate agent, unref core_instance");
return -1;
}
ao2_t_link(cc_core_instances, core_instance, "Link core instance into container");
- ao2_t_ref(core_instance, -1, "Linked core instance, unref from ao2_alloc()"); /* From ao2_alloc. */
+ cc_unref(core_instance, "Linked core instance, unref from ao2_alloc()"); /* From ao2_alloc. */
return core_instance->core_id;
}
@@ -844,7 +846,7 @@
ast_sched_thread_del(cc_sched_thread, agent_pvt->offer_timer_id);
- ao2_t_ref(agent->interface_tree, -1, "Agent destructor");
+ agent->interface_tree = cc_unref(agent->interface_tree, "Agent destructor");
ast_free(agent_pvt);
}
@@ -908,17 +910,15 @@
}
if (!(new_link = ast_calloc(1, sizeof(*new_link)))) {
- ao2_t_ref(new_monitor, -1, "Couldn't allocate link, so unref monitor");
+ cc_unref(new_monitor, "Couldn't allocate link, so unref monitor");
ao2_t_unlink(cc_monitors, new_monitor, "Couldn't allocate link, so unlink monitor");
return NULL;
}
AST_LIST_HEAD_INIT(&new_monitor->parent_links);
AST_LIST_HEAD_INIT(&new_monitor->child_links);
- new_link->child = new_monitor;
- new_link->parent = parent;
- ao2_t_ref(new_link->child, +1, "Link's child reference");
- ao2_t_ref(new_link->parent, +1, "Link's parent reference");
+ new_link->child = cc_ref(new_monitor, "Link's child reference");
+ new_link->parent = cc_ref(parent, "Link's parent reference");
new_link->core_id = core_id;
new_link->service = tree_item->service_offered;
ast_atomic_fetchadd_int(&new_monitor->num_requests, +1);
@@ -941,7 +941,7 @@
/* Device monitors won't have children, so don't bother looking.
*/
if (current_place->interface->monitor_class == AST_CC_DEVICE_MONITOR) {
- ao2_t_ref(monitor, -1, "Device monitor unref from finding or creating");
+ cc_unref(monitor, "Device monitor unref from finding or creating");
return;
}
@@ -950,7 +950,7 @@
interface_tree_to_monitor(tree_item, monitor, core_id);
}
}
- ao2_t_ref(monitor, -1, "Unref extension monitor from finding or creating");
+ cc_unref(monitor, "Unref extension monitor from finding or creating");
}
static int cc_monitor_tree_init(const int core_id)
@@ -968,7 +968,7 @@
root_monitor, core_instance->core_id);
core_instance->monitor = root_monitor;
- ao2_t_ref(core_instance, -1, "Unref the core instance we just found");
+ cc_unref(core_instance, "Unref the core instance we just found");
return 0;
}
@@ -983,8 +983,8 @@
ast_log(LOG_NOTICE, "Destroying link with parent %s and child %s\n",
link->parent->interface->name, link->child->interface->name);
ast_atomic_fetchadd_int(&link->child->num_requests, -1);
- ao2_t_ref(link->child, -1, "Unref link's child");
- ao2_t_ref(link->parent, -1, "Unref link's parent");
+ link->child = cc_unref(link->child, "Unref link's child");
+ link->parent = cc_unref(link->parent, "Unref link's parent");
ast_free(link);
return;
}
@@ -1068,7 +1068,7 @@
}
if (monitor->interface->monitor_class == AST_CC_ROOT_MONITOR) {
- ao2_t_ref(core_instance, -1, "Unref core_instance from earlier ao2_find");
+ cc_unref(core_instance, "Unref core_instance from earlier ao2_find");
ast_cc_request_state_change(CC_CALLEE_READY, core_id, "Device being monitored has become available");
return 0;
}
@@ -1091,7 +1091,7 @@
}
pass_availability_up(link->parent, core_id);
- ao2_t_ref(core_instance, -1, "Unref core_instance from earlier ao2_find");
+ cc_unref(core_instance, "Unref core_instance from earlier ao2_find");
return 0;
}
@@ -1117,7 +1117,7 @@
if (link && !link->is_suspended) {
pass_availability_up(link->parent, link->core_id);
- ao2_t_ref(monitor, -1, "Kill reference from ast_cc_monitor_announce_availabilty");
+ cc_unref(monitor, "Kill reference from ast_cc_monitor_announce_availabilty");
return 0;
}
@@ -1137,13 +1137,13 @@
* are suspended. Either way, this isn't a particularly big
* deal.
*/
- ao2_t_ref(monitor, -1, "Kill reference from ast_cc_monitor_announce_availabilty");
+ cc_unref(monitor, "Kill reference from ast_cc_monitor_announce_availabilty");
return 0;
}
monitor->saved_link = link;
pass_availability_up(link->parent, link->core_id);
- ao2_t_ref(monitor, -1, "Kill reference from ast_cc_monitor_announce_availabilty");
+ cc_unref(monitor, "Kill reference from ast_cc_monitor_announce_availabilty");
return 0;
}
@@ -1251,6 +1251,8 @@
if (core_instance->current_state != CC_RECALLING) {
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;
+ prune_links(core_instance->monitor, core_instance->core_id, NULL);
break;
case CC_FAILED:
/* Something along the way failed, call agent and monitor destructor functions
@@ -1265,7 +1267,7 @@
}
ast_free(args);
- ao2_t_ref(core_instance, -1, "Unref since state change has completed"); /* From ao2_find */
+ cc_unref(core_instance, "Unref since state change has completed"); /* From ao2_find */
return 0;
}
@@ -1311,7 +1313,7 @@
if (strcmp(core_instance->agent->callbacks->type, "generic")) {
ast_log(LOG_NOTICE, "CallCompletionRequest is only for generic agent types.\n");
- ao2_t_ref(core_instance, -1, "Unref core_instance since CallCompletionRequest was called with native agent");
+ cc_unref(core_instance, "Unref core_instance since CallCompletionRequest was called with native agent");
return -1;
}
@@ -1319,7 +1321,7 @@
ast_sched_thread_del(cc_sched_thread, generic_pvt->offer_timer_id);
res = ast_cc_request_state_change(CC_CALLER_REQUESTED, core_instance->core_id, "CallCompletionRequest called");
- ao2_t_ref(core_instance, -1, "Done with CallCompletionRequest");
+ cc_unref(core_instance, "Done with CallCompletionRequest");
return res;
}
@@ -1346,11 +1348,11 @@
if (strcmp(core_instance->agent->callbacks->type, "generic")) {
ast_log(LOG_WARNING, "CallCompletionCancel may only be used for calles with a generic agent\n");
- ao2_t_ref(core_instance, -1, "Unref core instance found during CallCompletionCancel");
+ cc_unref(core_instance, "Unref core instance found during CallCompletionCancel");
return -1;
}
res = ast_cc_request_state_change(CC_FAILED, core_instance->core_id, "Call completion request Cancelled");
- ao2_t_ref(core_instance, -1, "Unref core instance found during CallCompletionCancel");
+ cc_unref(core_instance, "Unref core instance found during CallCompletionCancel");
return res;
}
@@ -1538,7 +1540,7 @@
if (new_state == AST_DEVICE_NOT_INUSE) {
ast_cc_monitor_announce_availability(monitor);
}
- ao2_t_ref(monitor, -1, "Kill reference from generic_monitor_devstate_cb");
+ cc_unref(monitor, "Kill reference from generic_monitor_devstate_cb");
ast_free(gtcd);
return 0;
}
@@ -1557,8 +1559,7 @@
return;
}
- ao2_t_ref(monitor, +1, "Keep reference until taskprocessor callback executes");
- gtcd->monitor = monitor;
+ gtcd->monitor = cc_ref(monitor, "Keep reference until taskprocessor callback executes");
gtcd->new_state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
ast_taskprocessor_push(cc_core_taskprocessor, generic_monitor_devstate_tp_cb, gtcd);
@@ -1726,7 +1727,7 @@
}
retval = monitor->num_requests;
- ao2_t_ref(monitor, -1, "Unref from ao2_find");
+ cc_unref(monitor, "Unref from ao2_find");
return retval;
}
@@ -1762,8 +1763,8 @@
}
int ast_cc_monitor_announce_availability(struct ast_cc_monitor *monitor) {
- ao2_t_ref(monitor, +1, "Bump reference count until cc_devstate_change executes");
- return ast_taskprocessor_push(cc_core_taskprocessor, cc_devstate_change, monitor);
+ return ast_taskprocessor_push(cc_core_taskprocessor, cc_devstate_change,
+ cc_ref(monitor, "Bump reference count until cc_devstate_change executes"));
}
struct cc_recall_ds_data {
@@ -1779,15 +1780,15 @@
if (!new_data) {
return NULL;
}
- ao2_t_ref(old_data->interface_tree, +1, "Bump refcount of interface tree for recall");
- memcpy(new_data, old_data, sizeof(*new_data));
+ new_data->interface_tree = cc_ref(old_data->interface_tree, "Bump refcount of interface tree for recall");
+ new_data->core_id = old_data->core_id;
return new_data;
}
static void cc_recall_ds_destroy(void *data)
{
struct cc_recall_ds_data *recall_data = data;
- ao2_t_ref(recall_data->interface_tree, -1, "Unref recall interface tree");
+ recall_data->interface_tree = cc_unref(recall_data->interface_tree, "Unref recall interface tree");
ast_free(recall_data);
}
@@ -1811,9 +1812,8 @@
return -1;
}
- ao2_t_ref(agent->interface_tree, +1, "Bump refcount for interface tree for agent");
+ recall_data->interface_tree = cc_ref(agent->interface_tree, "Bump refcount for interface tree for agent");
recall_data->core_id = agent->core_id;
- recall_data->interface_tree = agent->interface_tree;
recall_datastore->data = recall_data;
recall_datastore->inheritance = DATASTORE_INHERIT_FOREVER;
ast_channel_lock(chan);
@@ -1942,6 +1942,7 @@
return -1;
}
ast_log(LOG_NOTICE, "Successfully created the root CC monitor\n");
- ao2_t_ref(root_monitor, -1, "Unref root monitor from allocation");
+ /* FOR THE LOVE OF GOD DO NOT SET root_monitor TO NULL HERE */
+ cc_unref(root_monitor, "Unref root monitor from allocation");
return res;
}
More information about the asterisk-commits
mailing list