[asterisk-commits] mmichelson: branch mmichelson/pool_shark r380424 - /team/mmichelson/pool_shar...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Jan 29 15:23:52 CST 2013
Author: mmichelson
Date: Tue Jan 29 15:23:49 2013
New Revision: 380424
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380424
Log:
Account for case where task to destroy SIP work runs in the threadpool.
Modified:
team/mmichelson/pool_shark/res/res_sip.c
Modified: team/mmichelson/pool_shark/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/res/res_sip.c?view=diff&rev=380424&r1=380423&r2=380424
==============================================================================
--- team/mmichelson/pool_shark/res/res_sip.c (original)
+++ team/mmichelson/pool_shark/res/res_sip.c Tue Jan 29 15:23:49 2013
@@ -377,7 +377,13 @@
static int execute_tasks(void *data)
{
struct ast_sip_work *work = data;
+ /* We bump the refcount of work here so that in case the task
+ * that gets run calls ast_sip_destroy_work(), the work won't
+ * actually get destroyed until the end of this function
+ */
+ ao2_ref(work, +1);
while (ast_taskprocessor_execute(work->queue));
+ ao2_cleanup(work);
return 0;
}
@@ -403,9 +409,15 @@
.shutdown = work_queue_shutdown,
};
+static void work_destroy(void *obj)
+{
+ struct ast_sip_work *work = obj;
+ ast_taskprocessor_unreference(work->queue);
+}
+
struct ast_sip_work *ast_sip_create_work(void)
{
- struct ast_sip_work *work = ast_calloc(1, sizeof(*work));
+ struct ast_sip_work *work = ao2_alloc(sizeof(*work), work_destroy);
struct ast_uuid *uuid;
struct ast_taskprocessor_listener *listener;
char queue_name[AST_UUID_STR_LEN];
@@ -418,7 +430,7 @@
*/
uuid = ast_uuid_generate();
if (!uuid) {
- ast_free(work);
+ ao2_cleanup(work);
return NULL;
}
ast_uuid_to_str(uuid, queue_name, sizeof(queue_name));
@@ -427,7 +439,7 @@
work->queue = ast_taskprocessor_create_with_listener(queue_name, listener);
ao2_cleanup(listener);
if (!work->queue) {
- ast_free(work);
+ ao2_cleanup(work);
return NULL;
}
return work;
@@ -435,8 +447,7 @@
void ast_sip_destroy_work(struct ast_sip_work *work)
{
- ast_taskprocessor_unreference(work->queue);
- ast_free(work);
+ ao2_cleanup(work);
}
int ast_sip_push_task(struct ast_sip_work *work, int (*sip_task)(void *), void *task_data)
More information about the asterisk-commits
mailing list