[svn-commits] dlee: branch dlee/cache-ref-counting r394393 - /team/dlee/cache-ref-counting/...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Jul 15 15:29:44 CDT 2013


Author: dlee
Date: Mon Jul 15 15:29:42 2013
New Revision: 394393

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394393
Log:
Clean up refcounting with caching.

Modified:
    team/dlee/cache-ref-counting/main/stasis_cache.c

Modified: team/dlee/cache-ref-counting/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/cache-ref-counting/main/stasis_cache.c?view=diff&rev=394393&r1=394392&r2=394393
==============================================================================
--- team/dlee/cache-ref-counting/main/stasis_cache.c (original)
+++ team/dlee/cache-ref-counting/main/stasis_cache.c Mon Jul 15 15:29:42 2013
@@ -76,6 +76,18 @@
 struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
 {
 	if (caching_topic) {
+		RAII_VAR(struct stasis_caching_topic *, hold_ref, NULL,
+			ao2_cleanup);
+
+		/* Dispatching cache updates directly from the publisher thread
+		 * has an interesting side effect.
+		 *
+		 * The subscription may hold the last reference to this caching
+		 * topic. We want to make sure the destructor doesn't run
+		 * until after the unsubscribe finishes. */
+		ao2_ref(caching_topic, +1);
+		hold_ref = caching_topic;
+
 		if (stasis_subscription_is_subscribed(caching_topic->sub)) {
 			/* Increment the reference to hold on to it past the
 			 * unsubscribe */
@@ -389,6 +401,7 @@
 	struct stasis_caching_topic *caching_topic = data;
 	const char *id = NULL;
 
+	ast_assert(caching_topic != NULL);
 	ast_assert(caching_topic->topic != NULL);
 	ast_assert(caching_topic->id_fn != NULL);
 
@@ -451,10 +464,6 @@
 
 		stasis_publish(caching_topic->topic, update);
 	}
-
-	if (stasis_subscription_final_message(sub, message)) {
-		ao2_cleanup(caching_topic);
-	}
 }
 
 struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, snapshot_get_id id_fn)
@@ -499,7 +508,7 @@
 	ao2_ref(caching_topic, +1);
 	caching_topic->sub = sub;
 
-	ao2_ref(caching_topic, +1);
+	/* The subscription holds the reference, so no additional ref bump. */
 	return caching_topic;
 }
 




More information about the svn-commits mailing list