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

@ -207,6 +207,8 @@ static struct {
char *mixer_conf_profile; char *mixer_conf_profile;
/** to URI prefixes mapped to gateways */ /** to URI prefixes mapped to gateways */
switch_hash_t *dial_gateways; switch_hash_t *dial_gateways;
/** synchronizes access to dial gateways */
switch_mutex_t *dial_gateways_mutex;
/** console command aliases */ /** console command aliases */
switch_hash_t *cmd_aliases; switch_hash_t *cmd_aliases;
/** global console */ /** global console */
@ -569,6 +571,7 @@ static struct dial_gateway *dial_gateway_find(const char *uri)
struct dial_gateway *gateway = (struct dial_gateway *)switch_core_hash_find(globals.dial_gateways, "default"); struct dial_gateway *gateway = (struct dial_gateway *)switch_core_hash_find(globals.dial_gateways, "default");
/* find longest prefix match */ /* find longest prefix match */
switch_mutex_lock(globals.dial_gateways_mutex);
for (hi = switch_core_hash_first(globals.dial_gateways); hi; hi = switch_core_hash_next(hi)) { for (hi = switch_core_hash_first(globals.dial_gateways); hi; hi = switch_core_hash_next(hi)) {
struct dial_gateway *candidate = NULL; struct dial_gateway *candidate = NULL;
const void *prefix; const void *prefix;
@ -584,6 +587,7 @@ static struct dial_gateway *dial_gateway_find(const char *uri)
gateway = candidate; gateway = candidate;
} }
} }
switch_mutex_unlock(globals.dial_gateways_mutex);
return gateway; return gateway;
} }
@ -2893,6 +2897,7 @@ static void rayo_client_command_recv(struct rayo_client *rclient, iks *iq)
static void broadcast_mixer_event(struct rayo_mixer *mixer, iks *rayo_event) static void broadcast_mixer_event(struct rayo_mixer *mixer, iks *rayo_event)
{ {
switch_hash_index_t *hi = NULL; switch_hash_index_t *hi = NULL;
switch_mutex_lock(RAYO_ACTOR(mixer)->mutex);
for (hi = switch_core_hash_first(mixer->subscribers); hi; hi = switch_core_hash_next(hi)) { for (hi = switch_core_hash_first(mixer->subscribers); hi; hi = switch_core_hash_next(hi)) {
const void *key; const void *key;
void *val; void *val;
@ -2903,6 +2908,7 @@ static void broadcast_mixer_event(struct rayo_mixer *mixer, iks *rayo_event)
iks_insert_attrib(rayo_event, "to", subscriber->jid); iks_insert_attrib(rayo_event, "to", subscriber->jid);
RAYO_SEND_MESSAGE_DUP(mixer, subscriber->jid, rayo_event); RAYO_SEND_MESSAGE_DUP(mixer, subscriber->jid, rayo_event);
} }
switch_mutex_unlock(RAYO_ACTOR(mixer)->mutex);
} }
/** /**
@ -4549,6 +4555,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_rayo_load)
switch_core_hash_init(&globals.actors_by_id); switch_core_hash_init(&globals.actors_by_id);
switch_mutex_init(&globals.actors_mutex, SWITCH_MUTEX_NESTED, pool); switch_mutex_init(&globals.actors_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.dial_gateways); switch_core_hash_init(&globals.dial_gateways);
switch_mutex_init(&globals.dial_gateways_mutex, SWITCH_MUTEX_NESTED, pool);
switch_core_hash_init(&globals.cmd_aliases); switch_core_hash_init(&globals.cmd_aliases);
switch_thread_rwlock_create(&globals.shutdown_rwlock, pool); switch_thread_rwlock_create(&globals.shutdown_rwlock, pool);
switch_queue_create(&globals.msg_queue, 25000, pool); switch_queue_create(&globals.msg_queue, 25000, pool);

View File

@ -31,6 +31,8 @@
static struct { static struct {
/** detectors supported by this module mapped by signal-type */ /** detectors supported by this module mapped by signal-type */
switch_hash_t *detectors; switch_hash_t *detectors;
/** synchronizes access to detectors */
switch_mutex_t *detectors_mutex;
} globals; } globals;
struct rayo_cpa_detector; struct rayo_cpa_detector;
@ -390,10 +392,12 @@ static switch_status_t rayo_cpa_detector_signal_types(const char *line, const ch
const void *vvar; const void *vvar;
switch_console_callback_match_t *my_matches = NULL; switch_console_callback_match_t *my_matches = NULL;
switch_mutex_lock(globals.detectors_mutex);
for (hi = switch_core_hash_first(globals.detectors); hi; hi = switch_core_hash_next(hi)) { for (hi = switch_core_hash_first(globals.detectors); hi; hi = switch_core_hash_next(hi)) {
switch_core_hash_this(hi, &vvar, NULL, &val); switch_core_hash_this(hi, &vvar, NULL, &val);
switch_console_push_match(&my_matches, (const char *) vvar); switch_console_push_match(&my_matches, (const char *) vvar);
} }
switch_mutex_unlock(globals.detectors_mutex);
if (my_matches) { if (my_matches) {
*matches = my_matches; *matches = my_matches;
@ -414,16 +418,19 @@ switch_status_t rayo_cpa_detector_load(switch_loadable_module_interface_t **modu
{ {
switch_api_interface_t *api_interface; switch_api_interface_t *api_interface;
switch_core_hash_init(&globals.detectors);
switch_mutex_init(&globals.detectors_mutex, SWITCH_MUTEX_NESTED, pool);
if (do_config(pool, config_file) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
SWITCH_ADD_API(api_interface, "rayo_cpa", "Query rayo status", rayo_cpa_detector_api, RAYO_CPA_DETECTOR_SYNTAX); SWITCH_ADD_API(api_interface, "rayo_cpa", "Query rayo status", rayo_cpa_detector_api, RAYO_CPA_DETECTOR_SYNTAX);
switch_console_set_complete("add rayo_cpa ::console::list_uuid ::rayo_cpa::list_signal_types start"); switch_console_set_complete("add rayo_cpa ::console::list_uuid ::rayo_cpa::list_signal_types start");
switch_console_set_complete("add rayo_cpa ::console::list_uuid ::rayo_cpa::list_signal_types stop"); switch_console_set_complete("add rayo_cpa ::console::list_uuid ::rayo_cpa::list_signal_types stop");
switch_console_add_complete_func("::rayo_cpa::list_signal_types", rayo_cpa_detector_signal_types); switch_console_add_complete_func("::rayo_cpa::list_signal_types", rayo_cpa_detector_signal_types);
switch_core_hash_init(&globals.detectors);
if (do_config(pool, config_file) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_TERM;
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -1,6 +1,6 @@
/* /*
* mod_ssml for FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application * 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 * Version: MPL 1.1
* *
@ -64,8 +64,12 @@ static struct {
switch_hash_t *voice_cache; switch_hash_t *voice_cache;
/** Mapping of voice names */ /** Mapping of voice names */
switch_hash_t *say_voice_map; switch_hash_t *say_voice_map;
/** Synchronizes access to say_voice_map */
switch_mutex_t *say_voice_map_mutex;
/** Mapping of voice names */ /** Mapping of voice names */
switch_hash_t *tts_voice_map; 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 */ /** Mapping of interpret-as value to macro */
switch_hash_t *interpret_as_map; switch_hash_t *interpret_as_map;
/** Mapping of ISO language code to say-module */ /** Mapping of ISO language code to say-module */
@ -371,7 +375,11 @@ done:
*/ */
static struct voice *find_tts_voice(struct ssml_node *cur_node) 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) 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; globals.pool = pool;
switch_core_hash_init(&globals.voice_cache); switch_core_hash_init(&globals.voice_cache);
switch_core_hash_init(&globals.tts_voice_map); 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_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.interpret_as_map);
switch_core_hash_init(&globals.language_map); switch_core_hash_init(&globals.language_map);
switch_core_hash_init(&globals.tag_defs); switch_core_hash_init(&globals.tag_defs);