[svn-commits] dlee: branch dlee/clean-shutdown r388720 - in /team/dlee/clean-shutdown: incl...
SVN commits to the Digium repositories
svn-commits at lists.digium.com
Tue May 14 15:16:05 CDT 2013
Author: dlee
Date: Tue May 14 15:16:04 2013
New Revision: 388720
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388720
Log:
Clean shutdown for routers
Modified:
team/dlee/clean-shutdown/include/asterisk/stasis.h
team/dlee/clean-shutdown/include/asterisk/stasis_message_router.h
team/dlee/clean-shutdown/main/endpoints.c
team/dlee/clean-shutdown/main/manager_channels.c
team/dlee/clean-shutdown/main/stasis.c
team/dlee/clean-shutdown/main/stasis_message_router.c
team/dlee/clean-shutdown/res/res_chan_stats.c
team/dlee/clean-shutdown/res/res_stasis.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=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/include/asterisk/stasis.h (original)
+++ team/dlee/clean-shutdown/include/asterisk/stasis.h Tue May 14 15:16:04 2013
@@ -312,10 +312,28 @@
/*!
* \brief Block until the last message is processed on a subscription.
*
+ * This function will not return until the \a subscription's callback for the
+ * stasis_subscription_final_message() completes. This allows cleanup routines
+ * to run before unblocking the joining thread.
+ *
* \param subscription Subscription to block on.
* \since 12
*/
void stasis_subscription_join(struct stasis_subscription *subscription);
+
+/*!
+ * \brief Returns whether \a subscription has received its final message.
+ *
+ * Note that a subscription is considered done even while the
+ * stasis_subscription_final_message() is being processed. This allows cleanup
+ * routines to check the status of the subscription.
+ *
+ * \param subscription Subscription.
+ * \return True (non-zero) if stasis_subscription_final_message() has been
+ * received.
+ * \return False (zero) if waiting for the end.
+ */
+int stasis_subscription_is_done(struct stasis_subscription *subscription);
/*!
* \brief Cancel a subscription, blocking until the last message is processed.
Modified: team/dlee/clean-shutdown/include/asterisk/stasis_message_router.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/include/asterisk/stasis_message_router.h?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/include/asterisk/stasis_message_router.h (original)
+++ team/dlee/clean-shutdown/include/asterisk/stasis_message_router.h Tue May 14 15:16:04 2013
@@ -57,10 +57,34 @@
/*!
* \brief Unsubscribe the router from the upstream topic.
+ *
* \param router Router to unsubscribe.
* \since 12
*/
void stasis_message_router_unsubscribe(struct stasis_message_router *router);
+
+/*!
+ * \brief Unsubscribe the router from the upstream topic, blocking until the
+ * final messages has been processed.
+ *
+ * See stasis_unsubscribe_and_join() for info on when to use this
+ * vs. stasis_message_router_unsubscribe().
+ *
+ * \param router Router to unsubscribe.
+ * \since 12
+ */
+void stasis_message_router_unsubscribe_and_join(
+ struct stasis_message_router *router);
+
+/*!
+ * \brief Returns whether \a router has received its final message.
+ *
+ * \param router Router.
+ * \return True (non-zero) if stasis_subscription_final_message() has been
+ * received.
+ * \return False (zero) if waiting for the end.
+ */
+int stasis_message_router_is_done(struct stasis_message_router *router);
/*!
* \brief Add a route to a message router.
Modified: team/dlee/clean-shutdown/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/endpoints.c?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/main/endpoints.c (original)
+++ team/dlee/clean-shutdown/main/endpoints.c Tue May 14 15:16:04 2013
@@ -106,7 +106,9 @@
struct ast_endpoint *endpoint = obj;
/* The router should be shut down already */
- ast_assert(endpoint->router == NULL);
+ ast_assert(stasis_message_router_is_done(endpoint->router));
+ ao2_cleanup(endpoint->router);
+ endpoint->router = NULL;
stasis_unsubscribe(endpoint->forward);
endpoint->forward = NULL;
@@ -258,8 +260,9 @@
stasis_publish(endpoint->topic, message);
}
+ /* Bump refcount to hold on to the router */
+ ao2_ref(endpoint->router, +1);
stasis_message_router_unsubscribe(endpoint->router);
- endpoint->router = NULL;
}
const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
Modified: team/dlee/clean-shutdown/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/manager_channels.c?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/main/manager_channels.c (original)
+++ team/dlee/clean-shutdown/main/manager_channels.c Tue May 14 15:16:04 2013
@@ -805,7 +805,7 @@
static void manager_channels_shutdown(void)
{
- stasis_message_router_unsubscribe(channel_state_router);
+ stasis_message_router_unsubscribe_and_join(channel_state_router);
channel_state_router = NULL;
}
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=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/main/stasis.c (original)
+++ team/dlee/clean-shutdown/main/stasis.c Tue May 14 15:16:04 2013
@@ -122,6 +122,9 @@
/*! Flag set when final message for sub has been received.
* Be sure join_lock is held before reading/setting. */
int final_message_rxed;
+ /*! Flag set when final message for sub has been processed.
+ * Be sure join_lock is held before reading/setting. */
+ int final_message_processed;
};
static void subscription_dtor(void *obj)
@@ -146,16 +149,20 @@
struct stasis_topic *topic,
struct stasis_message *message)
{
- /* Since sub is mostly immutable, no need to lock sub */
- sub->callback(sub->data,
- sub,
- topic,
- message);
-
- /* The final message flag, though, needs a lock */
+ /* Notify that the final message has been received */
if (stasis_subscription_final_message(sub, message)) {
SCOPED_MUTEX(lock, &sub->join_lock);
sub->final_message_rxed = 1;
+ ast_cond_signal(&sub->join_cond);
+ }
+
+ /* Since sub is mostly immutable, no need to lock sub */
+ sub->callback(sub->data, sub, topic, message);
+
+ /* Notify that the final message has been processed */
+ if (stasis_subscription_final_message(sub, message)) {
+ SCOPED_MUTEX(lock, &sub->join_lock);
+ sub->final_message_processed = 1;
ast_cond_signal(&sub->join_cond);
}
}
@@ -240,11 +247,23 @@
{
if (subscription) {
SCOPED_MUTEX(lock, &subscription->join_lock);
- while (!subscription->final_message_rxed) {
+ /* Wait until the processed flag has been set */
+ while (!subscription->final_message_processed) {
ast_cond_wait(&subscription->join_cond,
&subscription->join_lock);
}
}
+}
+
+int stasis_subscription_is_done(struct stasis_subscription *subscription)
+{
+ if (subscription) {
+ SCOPED_MUTEX(lock, &subscription->join_lock);
+ return subscription->final_message_rxed;
+ }
+
+ /* Null subscription is about as done as you can get */
+ return 1;
}
struct stasis_subscription *stasis_unsubscribe_and_join(
Modified: team/dlee/clean-shutdown/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/main/stasis_message_router.c?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/main/stasis_message_router.c (original)
+++ team/dlee/clean-shutdown/main/stasis_message_router.c Tue May 14 15:16:04 2013
@@ -165,6 +165,26 @@
stasis_unsubscribe(router->subscription);
}
+void stasis_message_router_unsubscribe_and_join(
+ struct stasis_message_router *router)
+{
+ if (!router) {
+ return;
+ }
+ stasis_unsubscribe_and_join(router->subscription);
+}
+
+int stasis_message_router_is_done(struct stasis_message_router *router)
+{
+ if (!router) {
+ /* Null router is about as done as you can get */
+ return 1;
+ }
+
+ return stasis_subscription_is_done(router->subscription);
+}
+
+
static struct stasis_message_route *route_create(
struct stasis_message_type *message_type,
stasis_subscription_cb callback,
Modified: team/dlee/clean-shutdown/res/res_chan_stats.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/res/res_chan_stats.c?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/res/res_chan_stats.c (original)
+++ team/dlee/clean-shutdown/res/res_chan_stats.c Tue May 14 15:16:04 2013
@@ -174,7 +174,7 @@
{
stasis_unsubscribe_and_join(sub);
sub = NULL;
- stasis_message_router_unsubscribe(router);
+ stasis_message_router_unsubscribe_and_join(router);
router = NULL;
return 0;
}
Modified: team/dlee/clean-shutdown/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/clean-shutdown/res/res_stasis.c?view=diff&rev=388720&r1=388719&r2=388720
==============================================================================
--- team/dlee/clean-shutdown/res/res_stasis.c (original)
+++ team/dlee/clean-shutdown/res/res_stasis.c Tue May 14 15:16:04 2013
@@ -990,7 +990,7 @@
{
int r = 0;
- stasis_message_router_unsubscribe(channel_router);
+ stasis_message_router_unsubscribe_and_join(channel_router);
channel_router = NULL;
ao2_cleanup(__apps_registry);
More information about the svn-commits
mailing list