[asterisk-commits] kmoore: branch kmoore/stasis-mwi r382507 - /team/kmoore/stasis-mwi/tests/

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


Author: kmoore
Date: Wed Mar  6 11:01:12 2013
New Revision: 382507

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382507
Log:
Cleanups in test_stasis

Modified:
    team/kmoore/stasis-mwi/tests/test_stasis.c

Modified: team/kmoore/stasis-mwi/tests/test_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-mwi/tests/test_stasis.c?view=diff&rev=382507&r1=382506&r2=382507
==============================================================================
--- team/kmoore/stasis-mwi/tests/test_stasis.c (original)
+++ team/kmoore/stasis-mwi/tests/test_stasis.c Wed Mar  6 11:01:12 2013
@@ -166,27 +166,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)




More information about the asterisk-commits mailing list