[asterisk-commits] dlee: branch dlee/clean-shutdown r388702 - in /team/dlee/clean-shutdown: incl...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 14 14:08:31 CDT 2013


Author: dlee
Date: Tue May 14 14:08:30 2013
New Revision: 388702

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388702
Log:
Shutdown cleanups for caching topics

Modified:
    team/dlee/clean-shutdown/include/asterisk/stasis.h
    team/dlee/clean-shutdown/main/app.c
    team/dlee/clean-shutdown/main/devicestate.c
    team/dlee/clean-shutdown/main/stasis.c
    team/dlee/clean-shutdown/main/stasis_cache.c
    team/dlee/clean-shutdown/main/stasis_channels.c
    team/dlee/clean-shutdown/main/stasis_endpoints.c

Modified: team/dlee/clean-shutdown/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/include/asterisk/stasis.h?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/include/asterisk/stasis.h (original)
+++ team/dlee/clean-shutdown/include/asterisk/stasis.h Tue May 14 14:08:30 2013
@@ -308,6 +308,14 @@
  */
 struct stasis_subscription *stasis_unsubscribe(
 	struct stasis_subscription *subscription);
+
+/*!
+ * \brief Block until the last message is processed on a subscription.
+ *
+ * \param subscription Subscription to block on.
+ * \since 12
+ */
+void stasis_subscription_join(struct stasis_subscription *subscription);
 
 /*!
  * \brief Cancel a subscription, blocking until the last message is processed.
@@ -513,12 +521,31 @@
 struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, snapshot_get_id id_fn);
 
 /*!
- * Unsubscribes a caching topic from its upstream topic.
+ * \brief Unsubscribes a caching topic from its upstream topic.
+ *
+ * This function returns immediately, so be sure to cleanup when
+ * stasis_subscription_final_message() is received.
+ *
  * \param caching_topic Caching topic to unsubscribe
  * \return \c NULL for convenience
  * \since 12
  */
-struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic);
+struct stasis_caching_topic *stasis_caching_unsubscribe(
+	struct stasis_caching_topic *caching_topic);
+
+/*!
+ * \brief Unsubscribes a caching topic from its upstream topic, blocking until
+ * all messages have been forwarded.
+ *
+ * See stasis_unsubscriben_and_join() for more info on when to use this as
+ * opposed to stasis_caching_unsubscribe().
+ *
+ * \param caching_topic Caching topic to unsubscribe
+ * \return \c NULL for convenience
+ * \since 12
+ */
+struct stasis_caching_topic *stasis_caching_unsubscribe_and_join(
+	struct stasis_caching_topic *caching_topic);
 
 /*!
  * \brief Returns the topic of cached events from a caching topics.

Modified: team/dlee/clean-shutdown/main/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/app.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/app.c (original)
+++ team/dlee/clean-shutdown/main/app.c Tue May 14 14:08:30 2013
@@ -2731,7 +2731,7 @@
 {
 	ao2_cleanup(mwi_topic_all);
 	mwi_topic_all = NULL;
-	mwi_topic_cached = stasis_caching_unsubscribe(mwi_topic_cached);
+	mwi_topic_cached = stasis_caching_unsubscribe_and_join(mwi_topic_cached);
 	ao2_cleanup(mwi_state_type);
 	mwi_state_type = NULL;
 	ao2_cleanup(mwi_topic_pool);

Modified: team/dlee/clean-shutdown/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/devicestate.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/devicestate.c (original)
+++ team/dlee/clean-shutdown/main/devicestate.c Tue May 14 14:08:30 2013
@@ -780,7 +780,7 @@
 {
 	ao2_cleanup(device_state_topic_all);
 	device_state_topic_all = NULL;
-	device_state_topic_cached = stasis_caching_unsubscribe(device_state_topic_cached);
+	device_state_topic_cached = stasis_caching_unsubscribe_and_join(device_state_topic_cached);
 	ao2_cleanup(device_state_message_type);
 	device_state_message_type = NULL;
 	ao2_cleanup(device_state_topic_pool);

Modified: team/dlee/clean-shutdown/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/stasis.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/stasis.c (original)
+++ team/dlee/clean-shutdown/main/stasis.c Tue May 14 14:08:30 2013
@@ -153,10 +153,11 @@
 		      message);
 
 	/* The final message flag, though, needs a lock */
-	ast_mutex_lock(&sub->join_lock);
-	sub->final_message_rxed = 1;
-	ast_cond_signal(&sub->join_cond);
-	ast_mutex_unlock(&sub->join_lock);
+	if (stasis_subscription_final_message(sub, message)) {
+		SCOPED_MUTEX(lock, &sub->join_lock);
+		sub->final_message_rxed = 1;
+		ast_cond_signal(&sub->join_cond);
+	}
 }
 
 static void send_subscription_change_message(struct stasis_topic *topic, char *uniqueid, char *description);
@@ -235,7 +236,7 @@
  *
  * \param subscription Subscription to wait on.
  */
-static void subscription_join(struct stasis_subscription *subscription)
+void stasis_subscription_join(struct stasis_subscription *subscription)
 {
 	if (subscription) {
 		SCOPED_MUTEX(lock, &subscription->join_lock);
@@ -249,8 +250,16 @@
 struct stasis_subscription *stasis_unsubscribe_and_join(
 	struct stasis_subscription *subscription)
 {
+	if (!subscription) {
+		return NULL;
+	}
+
+	/* Bump refcount to hold it past the unsubscribe */
+	ao2_ref(subscription, +1);
 	stasis_unsubscribe(subscription);
-	subscription_join(subscription);
+	stasis_subscription_join(subscription);
+	/* Now decrement the refcount back */
+	ao2_cleanup(subscription);
 	return NULL;
 }
 

Modified: team/dlee/clean-shutdown/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/stasis_cache.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/stasis_cache.c (original)
+++ team/dlee/clean-shutdown/main/stasis_cache.c Tue May 14 14:08:30 2013
@@ -53,6 +53,7 @@
 static void stasis_caching_topic_dtor(void *obj) {
 	struct stasis_caching_topic *caching_topic = obj;
 	ast_assert(!stasis_subscription_is_subscribed(caching_topic->sub));
+	ao2_cleanup(caching_topic->sub);
 	caching_topic->sub = NULL;
 	ao2_cleanup(caching_topic->cache);
 	caching_topic->cache = NULL;
@@ -69,11 +70,28 @@
 {
 	if (caching_topic) {
 		if (stasis_subscription_is_subscribed(caching_topic->sub)) {
+			/* Increment the reference to hold on to it past the
+			 * unsubscribe */
+			ao2_ref(caching_topic->sub, +1);
 			stasis_unsubscribe(caching_topic->sub);
 		} else {
 			ast_log(LOG_ERROR, "stasis_caching_topic unsubscribed multiple times\n");
 		}
 	}
+	return NULL;
+}
+
+struct stasis_caching_topic *stasis_caching_unsubscribe_and_join(struct stasis_caching_topic *caching_topic)
+{
+	if (!caching_topic) {
+		return NULL;
+	}
+
+	/* Hold a ref past the unsubscribe */
+	ao2_ref(caching_topic, +1);
+	stasis_caching_unsubscribe(caching_topic);
+	stasis_subscription_join(caching_topic->sub);
+	ao2_cleanup(caching_topic);
 	return NULL;
 }
 

Modified: team/dlee/clean-shutdown/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/stasis_channels.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/stasis_channels.c (original)
+++ team/dlee/clean-shutdown/main/stasis_channels.c Tue May 14 14:08:30 2013
@@ -481,6 +481,9 @@
 
 void ast_stasis_channels_shutdown(void)
 {
+	channel_topic_all_cached = stasis_caching_unsubscribe_and_join(channel_topic_all_cached);
+	ao2_cleanup(channel_topic_all);
+	channel_topic_all = NULL;
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_snapshot_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dial_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_varset_type);
@@ -488,9 +491,6 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_hangup_request_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_begin_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_dtmf_end_type);
-	ao2_cleanup(channel_topic_all);
-	channel_topic_all = NULL;
-	channel_topic_all_cached = stasis_caching_unsubscribe(channel_topic_all_cached);
 }
 
 void ast_stasis_channels_init(void)

Modified: team/dlee/clean-shutdown/main/stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/stasis_endpoints.c?view=diff&rev=388702&r1=388701&r2=388702
==============================================================================
--- team/dlee/clean-shutdown/main/stasis_endpoints.c (original)
+++ team/dlee/clean-shutdown/main/stasis_endpoints.c Tue May 14 14:08:30 2013
@@ -106,15 +106,6 @@
 }
 
 
-static void endpoints_stasis_shutdown(void)
-{
-	ao2_cleanup(endpoint_topic_all);
-	endpoint_topic_all = NULL;
-
-	stasis_caching_unsubscribe(endpoint_topic_all_cached);
-	endpoint_topic_all_cached = NULL;
-}
-
 struct ast_json *ast_endpoint_snapshot_to_json(
 	const struct ast_endpoint_snapshot *snapshot)
 {
@@ -154,6 +145,15 @@
 	return ast_json_ref(json);
 }
 
+static void endpoints_stasis_shutdown(void)
+{
+	stasis_caching_unsubscribe_and_join(endpoint_topic_all_cached);
+	endpoint_topic_all_cached = NULL;
+
+	ao2_cleanup(endpoint_topic_all);
+	endpoint_topic_all = NULL;
+}
+
 int ast_endpoint_stasis_init(void)
 {
 	ast_register_atexit(endpoints_stasis_shutdown);




More information about the asterisk-commits mailing list