[svn-commits] kmoore: branch kmoore/stasis-http_sounds r390393 - /team/kmoore/stasis-http_s...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jun 4 09:17:21 CDT 2013


Author: kmoore
Date: Tue Jun  4 09:17:19 2013
New Revision: 390393

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390393
Log:
Prevent multiple reloads from occurring simultaneously and handle media index failures better

Modified:
    team/kmoore/stasis-http_sounds/main/sounds_index.c

Modified: team/kmoore/stasis-http_sounds/main/sounds_index.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-http_sounds/main/sounds_index.c?view=diff&rev=390393&r1=390392&r2=390393
==============================================================================
--- team/kmoore/stasis-http_sounds/main/sounds_index.c (original)
+++ team/kmoore/stasis-http_sounds/main/sounds_index.c Tue Jun  4 09:17:19 2013
@@ -103,16 +103,26 @@
 	struct ast_media_index *index = arg;
 
 	if (ast_media_index_update(index, lang)) {
-		return CMP_STOP;
-	}
-	return 0;
-}
+		return CMP_MATCH;
+	}
+	return 0;
+}
+
+AST_MUTEX_DEFINE_STATIC(reload_lock);
 
 int ast_sounds_reindex(void)
 {
-	RAII_VAR(struct ao2_container *, languages, get_languages(), ao2_cleanup);
-	struct ast_media_index *new_index, *old_index = sounds_index;
-	RAII_VAR(struct ast_str *, sounds_dir, ast_str_create(64), ast_free);
+	RAII_VAR(struct ast_str *, sounds_dir, NULL, ast_free);
+	RAII_VAR(struct ao2_container *, languages, NULL, ao2_cleanup);
+	RAII_VAR(char *, failed_index, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_media_index *, new_index, NULL, ao2_cleanup);
+	struct ast_media_index *old_index;
+
+	SCOPED_MUTEX(lock, &reload_lock);
+
+	old_index = sounds_index;
+	languages = get_languages();
+	sounds_dir = ast_str_create(64);
 
 	if (!languages || !sounds_dir) {
 		return -1;
@@ -124,7 +134,12 @@
 		return -1;
 	}
 
-	ao2_callback(languages, OBJ_NODATA, update_index_cb, new_index);
+	failed_index = ao2_callback(languages, 0, update_index_cb, new_index);
+	if (failed_index) {
+		return -1;
+	}
+
+	ao2_ref(new_index, +1);
 	sounds_index = new_index;
 	ao2_cleanup(old_index);
 	return 0;




More information about the svn-commits mailing list