[asterisk-commits] kmoore: branch dlee/stasis-core r382509 - in /team/dlee/stasis-core: main/ te...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Mar 6 11:37:22 CST 2013


Author: kmoore
Date: Wed Mar  6 11:37:19 2013
New Revision: 382509

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382509
Log:
Various cleanup, lifetime management fixups, and a memory leak fix

Modified:
    team/dlee/stasis-core/main/channel.c
    team/dlee/stasis-core/main/stasis.c
    team/dlee/stasis-core/main/stasis_cache.c
    team/dlee/stasis-core/tests/test_stasis.c

Modified: team/dlee/stasis-core/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/channel.c?view=diff&rev=382509&r1=382508&r2=382509
==============================================================================
--- team/dlee/stasis-core/main/channel.c (original)
+++ team/dlee/stasis-core/main/channel.c Wed Mar  6 11:37:19 2013
@@ -153,13 +153,13 @@
 static struct ao2_container *channels;
 
 /*! \brief Message type for channel snapshot events */
-static struct stasis_message_type *__ast_channel_snapshot;
-
-static struct stasis_message_type *__ast_channel_varset_event;
-
-struct stasis_topic *__ast_channel_events_all;
-
-struct stasis_caching_topic *__ast_channel_events_all_cached;
+static struct stasis_message_type *__channel_snapshot;
+
+static struct stasis_message_type *__channel_varset_event;
+
+struct stasis_topic *__channel_events_all;
+
+struct stasis_caching_topic *__channel_events_all_cached;
 
 /*! \brief map AST_CAUSE's to readable string representations
  *
@@ -8629,12 +8629,12 @@
 
 static void channels_shutdown(void)
 {
-	ao2_cleanup(__ast_channel_snapshot);
-	__ast_channel_snapshot = NULL;
-	ao2_cleanup(__ast_channel_events_all);
-	__ast_channel_events_all = NULL;
-	stasis_caching_unsubscribe(__ast_channel_events_all_cached);
-	__ast_channel_events_all_cached = NULL;
+	ao2_cleanup(__channel_snapshot);
+	__channel_snapshot = NULL;
+	ao2_cleanup(__channel_events_all);
+	__channel_events_all = NULL;
+	stasis_caching_unsubscribe(__channel_events_all_cached);
+	__channel_events_all_cached = NULL;
 	ast_data_unregister(NULL);
 	ast_cli_unregister_multiple(cli_channel, ARRAY_LEN(cli_channel));
 	if (channels) {
@@ -8662,11 +8662,11 @@
 		ao2_container_register("channels", channels, prnt_channel_key);
 	}
 
-	__ast_channel_snapshot = stasis_message_type_create("ast_channel_snapshot");
-	__ast_channel_varset_event = stasis_message_type_create("ast_channel_varset_event");
-
-	__ast_channel_events_all = stasis_topic_create("ast_channel_events_all");
-	__ast_channel_events_all_cached = stasis_caching_topic_create(__ast_channel_events_all, channel_snapshot_get_id);
+	__channel_snapshot = stasis_message_type_create("ast_channel_snapshot");
+	__channel_varset_event = stasis_message_type_create("ast_channel_varset_event");
+
+	__channel_events_all = stasis_topic_create("ast_channel_events_all");
+	__channel_events_all_cached = stasis_caching_topic_create(__channel_events_all, channel_snapshot_get_id);
 
 	ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel));
 
@@ -11304,22 +11304,22 @@
 
 struct stasis_message_type *ast_channel_varset_event(void)
 {
-	return __ast_channel_varset_event;
+	return __channel_varset_event;
 }
 
 struct stasis_message_type *ast_channel_snapshot(void)
 {
-	return __ast_channel_snapshot;
+	return __channel_snapshot;
 }
 
 struct stasis_topic *ast_channel_events_all(void)
 {
-	return __ast_channel_events_all;
+	return __channel_events_all;
 }
 
 struct stasis_caching_topic *ast_channel_events_all_cached(void)
 {
-	return __ast_channel_events_all_cached;
+	return __channel_events_all_cached;
 }
 
 /* DO NOT PUT ADDITIONAL FUNCTIONS BELOW THIS BOUNDARY

Modified: team/dlee/stasis-core/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis.c?view=diff&rev=382509&r1=382508&r2=382509
==============================================================================
--- team/dlee/stasis-core/main/stasis.c (original)
+++ team/dlee/stasis-core/main/stasis.c Wed Mar  6 11:37:19 2013
@@ -124,6 +124,8 @@
 	sub->topic = NULL;
 	ast_taskprocessor_unreference(sub->mailbox);
 	sub->mailbox = NULL;
+	ast_free(sub->uniqueid);
+	sub->uniqueid = NULL;
 }
 
 static void send_subscription_change_message(struct stasis_topic *topic, char *uniqueid, char *description);

Modified: team/dlee/stasis-core/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/main/stasis_cache.c?view=diff&rev=382509&r1=382508&r2=382509
==============================================================================
--- team/dlee/stasis-core/main/stasis_cache.c (original)
+++ team/dlee/stasis-core/main/stasis_cache.c Wed Mar  6 11:37:19 2013
@@ -316,11 +316,16 @@
 
 static void caching_topic_exec(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
 {
+	RAII_VAR(struct stasis_caching_topic *, caching_topic_needs_unref, NULL, ao2_cleanup);
 	struct stasis_caching_topic *caching_topic = data;
 	const char *id = NULL;
 
 	ast_assert(caching_topic->topic != NULL);
 	ast_assert(caching_topic->id_fn != NULL);
+
+	if (stasis_subscription_final_message(sub, message)) {
+		caching_topic_needs_unref = caching_topic;
+	}
 
 	/* Handle cache clear event */
 	if (cache_clear_data() == stasis_message_type(message)) {
@@ -399,6 +404,8 @@
 	if (sub == NULL) {
 		return NULL;
 	}
+	/* This is for the reference contained in the subscription above */
+	ao2_ref(caching_topic, +1);
 	caching_topic->sub = sub;
 
 	ao2_ref(caching_topic, +1);

Modified: team/dlee/stasis-core/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-core/tests/test_stasis.c?view=diff&rev=382509&r1=382508&r2=382509
==============================================================================
--- team/dlee/stasis-core/tests/test_stasis.c (original)
+++ team/dlee/stasis-core/tests/test_stasis.c Wed Mar  6 11:37:19 2013
@@ -157,27 +157,24 @@
 static void consumer_exec(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *message)
 {
 	struct consumer *consumer = data;
+	RAII_VAR(struct consumer *, consumer_needs_cleanup, NULL, ao2_cleanup);
+	SCOPED_MUTEX(lock, &consumer->lock);
 
 	if (!consumer->ignore_subscriptions || stasis_message_type(message) != stasis_subscription_change()) {
-		SCOPED_MUTEX(lock, &consumer->lock);
 
 		++consumer->messages_rxed_len;
 		consumer->messages_rxed = ast_realloc(consumer->messages_rxed, sizeof(*consumer->messages_rxed) * consumer->messages_rxed_len);
 		ast_assert(consumer->messages_rxed != NULL);
 		consumer->messages_rxed[consumer->messages_rxed_len - 1] = message;
 		ao2_ref(message, +1);
-
-		ast_cond_signal(&consumer->out);
 	}
 
 	if (stasis_subscription_final_message(sub, message)) {
-		ast_mutex_lock(&consumer->lock);
 		consumer->complete = 1;
-		ast_cond_signal(&consumer->out);
-		ast_mutex_unlock(&consumer->lock);
-		ao2_cleanup(consumer);
-	}
-
+		consumer_needs_cleanup = consumer;
+	}
+
+	ast_cond_signal(&consumer->out);
 }
 
 static int consumer_wait_for(struct consumer *consumer, size_t expected_len)
@@ -220,7 +217,8 @@
 	return consumer->complete;
 }
 
-static int consumer_should_stay(struct consumer *consumer, size_t expected_len) {
+static int consumer_should_stay(struct consumer *consumer, size_t expected_len)
+{
 	struct timeval start = ast_tvnow();
 	struct timeval diff = {
 		.tv_sec = 0,




More information about the asterisk-commits mailing list