[svn-commits] dlee: branch dlee/performance r399392 - /team/dlee/performance/main/stasis.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Sep 18 12:46:54 CDT 2013


Author: dlee
Date: Wed Sep 18 12:46:52 2013
New Revision: 399392

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399392
Log:
Change dispatch to a regular allocation. It has a confined lifecycle, so AO2
bought us nothing.

Modified:
    team/dlee/performance/main/stasis.c

Modified: team/dlee/performance/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/performance/main/stasis.c?view=diff&rev=399392&r1=399391&r2=399392
==============================================================================
--- team/dlee/performance/main/stasis.c (original)
+++ team/dlee/performance/main/stasis.c Wed Sep 18 12:46:52 2013
@@ -34,7 +34,6 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis_internal.h"
 #include "asterisk/stasis.h"
-#include "asterisk/threadpool.h"
 #include "asterisk/taskprocessor.h"
 #include "asterisk/utils.h"
 #include "asterisk/uuid.h"
@@ -465,23 +464,24 @@
 	struct stasis_subscription *sub;
 };
 
-static void dispatch_dtor(void *data)
-{
-	struct dispatch *dispatch = data;
+static void dispatch_dtor(struct dispatch *dispatch)
+{
 	ao2_cleanup(dispatch->topic);
 	ao2_cleanup(dispatch->message);
 	ao2_cleanup(dispatch->sub);
+
+	ast_free(dispatch);
 }
 
 static struct dispatch *dispatch_create(struct stasis_topic *topic, struct stasis_message *message, struct stasis_subscription *sub)
 {
-	RAII_VAR(struct dispatch *, dispatch, NULL, ao2_cleanup);
+	struct dispatch *dispatch;
 
 	ast_assert(topic != NULL);
 	ast_assert(message != NULL);
 	ast_assert(sub != NULL);
 
-	dispatch = ao2_alloc(sizeof(*dispatch), dispatch_dtor);
+	dispatch = ast_malloc(sizeof(*dispatch));
 	if (!dispatch) {
 		return NULL;
 	}
@@ -495,7 +495,6 @@
 	dispatch->sub = sub;
 	ao2_ref(sub, +1);
 
-	ao2_ref(dispatch, +1);
 	return dispatch;
 }
 
@@ -506,9 +505,10 @@
  */
 static int dispatch_exec(void *data)
 {
-	RAII_VAR(struct dispatch *, dispatch, data, ao2_cleanup);
+	struct dispatch *dispatch = data;
 
 	subscription_invoke(dispatch->sub, dispatch->topic, dispatch->message);
+	dispatch_dtor(data);
 
 	return 0;
 }
@@ -532,7 +532,7 @@
 		ast_assert(sub != NULL);
 
 		if (sub->mailbox) {
-			RAII_VAR(struct dispatch *, dispatch, NULL, ao2_cleanup);
+			struct dispatch *dispatch;
 
 			dispatch = dispatch_create(publisher_topic, message, sub);
 			if (!dispatch) {
@@ -540,12 +540,11 @@
 				break;
 			}
 
-			if (ast_taskprocessor_push(sub->mailbox, dispatch_exec, dispatch) == 0) {
-				/* Ownership transferred to mailbox.
-				 * Don't increment ref, b/c the task processor
-				 * may have already gotten rid of the object.
+			if (ast_taskprocessor_push(sub->mailbox, dispatch_exec, dispatch) != 0) {
+				/* Push failed; just delete the dispatch.
 				 */
-				dispatch = NULL;
+				ast_log(LOG_DEBUG, "Dropping dispatch\n");
+				dispatch_dtor(dispatch);
 			}
 		} else {
 			/* Dispatch directly */




More information about the svn-commits mailing list