]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
sounds_index: Avoid repeatedly reindexing.
authorCorey Farrell <git@cfware.com>
Wed, 6 Dec 2017 20:49:32 +0000 (15:49 -0500)
committerCorey Farrell <git@cfware.com>
Thu, 7 Dec 2017 05:39:02 +0000 (00:39 -0500)
The sounds index is rebuilt each time a format is registered or
unregistered.  This causes the index to be repeatedly rebuilt during
startup and shutdown.

This patch significantly reduces the work done by delaying sound index
initialization until after modules are loaded.  This way a reindex only
occurs if a format module is loaded after startup.  We also skip
reindexing when format modules are unloaded during shutdown.

Change-Id: I585fd6ee04200612ab1490dc804f76805f89cf0a

main/asterisk.c
main/sounds_index.c

index 0abb3600db326f5613f50159b0df9ed991c3b553..3807b0af762b04baa05249cee4b555dd65b56f82 100644 (file)
@@ -4701,9 +4701,14 @@ static void asterisk_daemon(int isroot, const char *runuser, const char *rungrou
        check_init(init_manager(), "Asterisk Manager Interface");
        check_init(ast_enum_init(), "ENUM Support");
        check_init(ast_cc_init(), "Call Completion Supplementary Services");
-       check_init(ast_sounds_index_init(), "Sounds Indexer");
        check_init(load_modules(0), "Module");
 
+       /*
+        * This is initialized after the dynamic modules load to avoid repeatedly
+        * reindexing sounds for every format module load.
+        */
+       check_init(ast_sounds_index_init(), "Sounds Indexer");
+
        /* loads the cli_permissoins.conf file needed to implement cli restrictions. */
        ast_cli_perms_init(0);
 
index c7f9f4dd950ec28c577d4e4fb6f74609b2b571dc..c792c1bbd296a9aea80428eea6658e369b56eb41 100644 (file)
@@ -285,13 +285,15 @@ static void sounds_cleanup(void)
 static void format_update_cb(void *data, struct stasis_subscription *sub,
        struct stasis_message *message)
 {
-       ast_sounds_reindex();
+       /* Reindexing during shutdown is pointless. */
+       if (!ast_shutting_down()) {
+               ast_sounds_reindex();
+       }
 }
 
 int ast_sounds_index_init(void)
 {
        int res = 0;
-       sounds_index = NULL;
        if (ast_sounds_reindex()) {
                return -1;
        }
@@ -328,6 +330,5 @@ int ast_sounds_index_init(void)
 
 struct ast_media_index *ast_sounds_get_index(void)
 {
-       ao2_ref(sounds_index, +1);
-       return sounds_index;
+       return ao2_bump(sounds_index);
 }