[asterisk-commits] coreyfarrell: branch 11 r415464 - in /branches/11: ./ main/autoservice.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun Jun 8 22:47:16 CDT 2014


Author: coreyfarrell
Date: Sun Jun  8 22:47:11 2014
New Revision: 415464

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=415464
Log:
autoservice: stop thread on graceful shutdown

This change adds thread shutdown to autoservice for graceful shutdowns only.
ast_register_cleanup is backported to 1.8 to allow this.  The logger callid
is also released on shutdown in 11+.

ASTERISK-23827 #close
Reported by: Corey Farrell
Review: https://reviewboard.asterisk.org/r/3594/
........

Merged revisions 415463 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/11/   (props changed)
    branches/11/main/autoservice.c

Propchange: branches/11/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: branches/11/main/autoservice.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/autoservice.c?view=diff&rev=415464&r1=415463&r2=415464
==============================================================================
--- branches/11/main/autoservice.c (original)
+++ branches/11/main/autoservice.c Sun Jun  8 22:47:11 2014
@@ -72,6 +72,7 @@
 static ast_cond_t as_cond;
 
 static pthread_t asthread = AST_PTHREADT_NULL;
+static volatile int asexit = 0;
 
 static int as_chan_list_state;
 
@@ -83,7 +84,7 @@
 		.subclass.integer = AST_CONTROL_HANGUP,
 	};
 
-	for (;;) {
+	while (!asexit) {
 		struct ast_channel *mons[MAX_AUTOMONS];
 		struct asent *ents[MAX_AUTOMONS];
 		struct ast_channel *chan;
@@ -177,6 +178,7 @@
 		}
 	}
 
+	ast_callid_threadassoc_change(NULL);
 	asthread = AST_PTHREADT_NULL;
 
 	return NULL;
@@ -337,7 +339,19 @@
 	return res;
 }
 
+static void autoservice_shutdown(void)
+{
+	pthread_t th = asthread;
+	asexit = 1;
+	if (th != AST_PTHREADT_NULL) {
+		ast_cond_signal(&as_cond);
+		pthread_kill(th, SIGURG);
+		pthread_join(th, NULL);
+	}
+}
+
 void ast_autoservice_init(void)
 {
+	ast_register_cleanup(autoservice_shutdown);
 	ast_cond_init(&as_cond, NULL);
 }




More information about the asterisk-commits mailing list