[asterisk-commits] devicestate: Cleanup engine thread during graceful shutdown. (asterisk[11])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 11 14:35:07 CST 2016


Joshua Colp has submitted this change and it was merged.

Change subject: devicestate: Cleanup engine thread during graceful shutdown.
......................................................................


devicestate: Cleanup engine thread during graceful shutdown.

ASTERISK-25681 #close

Change-Id: I64337c70f0ebd8c77f70792042684607c950c8f1
---
M main/devicestate.c
1 file changed, 15 insertions(+), 1 deletion(-)

Approvals:
  Kevin Harwell: Looks good to me, but someone else must approve
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, approved



diff --git a/main/devicestate.c b/main/devicestate.c
index 48d2d5c..6ae1963 100644
--- a/main/devicestate.c
+++ b/main/devicestate.c
@@ -187,6 +187,7 @@
 
 /*! \brief Flag for the queue */
 static ast_cond_t change_pending;
+static volatile int shuttingdown;
 
 struct devstate_change {
 	AST_LIST_ENTRY(devstate_change) entry;
@@ -551,7 +552,7 @@
 {
 	struct state_change *next, *current;
 
-	for (;;) {
+	while (!shuttingdown) {
 		/* This basically pops off any state change entries, resets the list back to NULL, unlocks, and processes each state change */
 		AST_LIST_LOCK(&state_changes);
 		if (AST_LIST_EMPTY(&state_changes))
@@ -752,6 +753,18 @@
 	ast_mutex_unlock(&devstate_collector.lock);
 }
 
+static void device_state_engine_cleanup(void)
+{
+	shuttingdown = 1;
+	AST_LIST_LOCK(&state_changes);
+	ast_cond_signal(&change_pending);
+	AST_LIST_UNLOCK(&state_changes);
+
+	if (change_thread != AST_PTHREADT_NULL) {
+		pthread_join(change_thread, NULL);
+	}
+}
+
 /*! \brief Initialize the device state engine in separate thread */
 int ast_device_state_engine_init(void)
 {
@@ -760,6 +773,7 @@
 		ast_log(LOG_ERROR, "Unable to start device state change thread.\n");
 		return -1;
 	}
+	ast_register_cleanup(device_state_engine_cleanup);
 
 	return 0;
 }

-- 
To view, visit https://gerrit.asterisk.org/1985
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I64337c70f0ebd8c77f70792042684607c950c8f1
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 11
Gerrit-Owner: Corey Farrell <git at cfware.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list