[svn-commits] mmichelson: branch group/manager2 r104041 - /team/group/manager2/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Feb 22 17:23:54 CST 2008


Author: mmichelson
Date: Fri Feb 22 17:23:54 2008
New Revision: 104041

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104041
Log:
Add code to handle cleanup on module unload


Modified:
    team/group/manager2/res/res_manager2.c

Modified: team/group/manager2/res/res_manager2.c
URL: http://svn.digium.com/view/asterisk/team/group/manager2/res/res_manager2.c?view=diff&rev=104041&r1=104040&r2=104041
==============================================================================
--- team/group/manager2/res/res_manager2.c (original)
+++ team/group/manager2/res/res_manager2.c Fri Feb 22 17:23:54 2008
@@ -29,6 +29,7 @@
 };
 
 static struct {
+	unsigned int stop:1;
 	pthread_t thread;
 	ast_cond_t cond;
 	ast_mutex_t lock;
@@ -75,16 +76,24 @@
  */
 static void *event_spitter(void *thisvariableissoimportantiamafraidtoactuallyuseit)
 {
-	for (;;) {
+	struct info_event *event = NULL;
+	
+	while(!info_thread.stop) {
 		struct ast_event_iterator iter;
 		int res = 0;
-		struct info_event *event = NULL;
 		ast_mutex_lock(&info_thread.lock);
 		if (!(event = AST_LIST_REMOVE_HEAD(&info_thread.info_events, list))) {
 			ast_cond_wait(&info_thread.cond, &info_thread.lock);
 			event = AST_LIST_REMOVE_HEAD(&info_thread.info_events, list);
 		}
 		ast_mutex_unlock(&info_thread.lock);
+
+		/* break if it's time to stop this thread's execution */
+		if (info_thread.stop)
+			break;
+
+		if (!event)
+			continue;
 
 		ast_log(LOG_DEBUG, "NEW EVENT: %s\n", queue_map[ast_event_get_type(event->event) - QUEUE_EVENT_BEGIN].name);
 
@@ -97,11 +106,19 @@
 			else if (info_map[ie_type].pltype == AST_EVENT_IE_PLTYPE_UINT)
 				ast_log(LOG_DEBUG, "%s: %u\r\n", info_map[ie_type].name, ast_event_iterator_get_ie_uint(&iter));
 		}
-		printf("\r\n");
-		fflush(stdout);
 		ast_event_destroy(event->event);
 		ast_free(event);
 		event = NULL;
+	}
+
+	if (event) {
+		ast_event_destroy(event->event);
+		ast_free(event);
+	}
+
+	while (!(event = AST_LIST_REMOVE_HEAD(&info_thread.info_events, list))) {
+		ast_event_destroy(event->event);
+		ast_free(event);
 	}
 
 	return NULL;
@@ -112,6 +129,14 @@
 	int i;
 	for (i = 0; manager_sub[i]; i++)
 		ast_event_unsubscribe(manager_sub[i]);
+	if (info_thread.thread != AST_PTHREADT_NULL) {
+		info_thread.stop = 1;
+		ast_mutex_lock(&info_thread.lock);
+		ast_cond_signal(&info_thread.cond);
+		ast_mutex_unlock(&info_thread.lock);
+		pthread_join(info_thread.thread, NULL);
+	}
+	ast_mutex_destroy(&info_thread.lock);
 	return 0;
 }
 




More information about the svn-commits mailing list