FS-6402 mod_rayo/mod_ssml: add mutex to hashes now that iteration is no longer thread-safe

This commit is contained in:
Chris Rienzo
2014-03-24 17:03:33 -04:00
parent 5ac9748827
commit 0b9e5c82a5
3 changed files with 41 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
/*
* mod_ssml for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
* Copyright (C) 2013, Grasshopper
* Copyright (C) 2013-2014, Grasshopper
*
* Version: MPL 1.1
*
@@ -64,8 +64,12 @@ static struct {
switch_hash_t *voice_cache;
/** Mapping of voice names */
switch_hash_t *say_voice_map;
/** Synchronizes access to say_voice_map */
switch_mutex_t *say_voice_map_mutex;
/** Mapping of voice names */
switch_hash_t *tts_voice_map;
/** Synchronizes access to tts_voice_map */
switch_mutex_t *tts_voice_map_mutex;
/** Mapping of interpret-as value to macro */
switch_hash_t *interpret_as_map;
/** Mapping of ISO language code to say-module */
@@ -339,7 +343,7 @@ static struct voice *find_voice(struct ssml_node *cur_node, switch_hash_t *map,
}
/* find best language, name, gender match */
for (hi = switch_core_hash_first( map); hi; hi = switch_core_hash_next(hi)) {
for (hi = switch_core_hash_first(map); hi; hi = switch_core_hash_next(hi)) {
const void *key;
void *val;
struct voice *candidate;
@@ -371,7 +375,11 @@ done:
*/
static struct voice *find_tts_voice(struct ssml_node *cur_node)
{
return find_voice(cur_node, globals.tts_voice_map, "tts", 0);
struct voice *v;
switch_mutex_lock(globals.tts_voice_map_mutex);
v = find_voice(cur_node, globals.tts_voice_map, "tts", 0);
switch_mutex_unlock(globals.tts_voice_map_mutex);
return v;
}
/**
@@ -381,7 +389,11 @@ static struct voice *find_tts_voice(struct ssml_node *cur_node)
*/
static struct voice *find_say_voice(struct ssml_node *cur_node)
{
return find_voice(cur_node, globals.say_voice_map, "say", 1);
struct voice *v;
switch_mutex_lock(globals.say_voice_map_mutex);
v = find_voice(cur_node, globals.say_voice_map, "say", 1);
switch_mutex_unlock(globals.say_voice_map_mutex);
return v;
}
/**
@@ -1112,7 +1124,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_ssml_load)
globals.pool = pool;
switch_core_hash_init(&globals.voice_cache);
switch_core_hash_init(&globals.tts_voice_map);
switch_mutex_init(&globals.tts_voice_map_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.say_voice_map);
switch_mutex_init(&globals.say_voice_map_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.interpret_as_map);
switch_core_hash_init(&globals.language_map);
switch_core_hash_init(&globals.tag_defs);