[svn-commits] rmudgett: branch 10 r377709 - in /branches/10: ./ main/event.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Mon Dec 10 19:00:06 CST 2012


Author: rmudgett
Date: Mon Dec 10 19:00:05 2012
New Revision: 377709

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377709
Log:
Cleanup event on exit.

* Cleanup CLI commands on exit.

* v10 only: Merged v1.8 -r374177 change to event.c missed in v10 -r374178.

(issue ASTERISK-20649)
Reported by: Corey Farrell
Patches:
      event_shutdown-10-only.patch (license #5909) patch uploaded by Corey Farrell
      event_shutdown-1_8-11-trunk.patch (license #5909) patch uploaded by Corey Farrell
........

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

Modified:
    branches/10/   (props changed)
    branches/10/main/event.c

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

Modified: branches/10/main/event.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/main/event.c?view=diff&rev=377709&r1=377708&r2=377709
==============================================================================
--- branches/10/main/event.c (original)
+++ branches/10/main/event.c Mon Dec 10 19:00:05 2012
@@ -1782,6 +1782,40 @@
 	AST_CLI_DEFINE(event_dump_cache, "Dump the internal event cache (for debugging)"),
 };
 
+/*! \internal \brief Clean up resources on Asterisk shutdown */
+static void event_shutdown(void)
+{
+	struct ast_event_sub *sub;
+	int i;
+
+	ast_cli_unregister_multiple(event_cli, ARRAY_LEN(event_cli));
+
+	if (event_dispatcher) {
+		event_dispatcher = ast_taskprocessor_unreference(event_dispatcher);
+	}
+
+	/* Remove any remaining subscriptions.  Note that we can't just call
+	 * unsubscribe, as it will attempt to lock the subscription list
+	 * as well */
+	for (i = 0; i < AST_EVENT_TOTAL; i++) {
+		AST_RWDLLIST_WRLOCK(&ast_event_subs[i]);
+		while ((sub = AST_RWDLLIST_REMOVE_HEAD(&ast_event_subs[i], entry))) {
+			ast_event_sub_destroy(sub);
+		}
+		AST_RWDLLIST_UNLOCK(&ast_event_subs[i]);
+		AST_RWDLLIST_HEAD_DESTROY(&ast_event_subs[i]);
+	}
+
+	for (i = 0; i < AST_EVENT_TOTAL; i++) {
+		if (!ast_event_cache[i].hash_fn) {
+			continue;
+		}
+		if (ast_event_cache[i].container) {
+			ao2_ref(ast_event_cache[i].container, -1);
+		}
+	}
+}
+
 int ast_event_init(void)
 {
 	int i;
@@ -1798,17 +1832,23 @@
 
 		if (!(ast_event_cache[i].container = ao2_container_alloc(NUM_CACHE_BUCKETS,
 				ast_event_hash, ast_event_cmp))) {
-			return -1;
+			goto event_init_cleanup;
 		}
 	}
 
 	if (!(event_dispatcher = ast_taskprocessor_get("core_event_dispatcher", 0))) {
-		return -1;
+		goto event_init_cleanup;
 	}
 
 	ast_cli_register_multiple(event_cli, ARRAY_LEN(event_cli));
 
+	ast_register_atexit(event_shutdown);
+
 	return 0;
+
+event_init_cleanup:
+	event_shutdown();
+	return -1;
 }
 
 size_t ast_event_minimum_length(void)




More information about the svn-commits mailing list