@@ -2457,8 +2457,11 @@ static switch_status_t recog_channel_unload_grammar(speech_channel_t *schannel,
24572457 } else {
24582458 recognizer_data_t * r = (recognizer_data_t * ) schannel -> data ;
24592459 switch_log_printf (SWITCH_CHANNEL_UUID_LOG (schannel -> session_uuid ), SWITCH_LOG_DEBUG , "(%s) Unloading grammar %s\n" , schannel -> name , grammar_name );
2460+
2461+ switch_mutex_lock (schannel -> mutex );
24602462 switch_core_hash_delete (r -> enabled_grammars , grammar_name );
24612463 switch_core_hash_delete (r -> grammars , grammar_name );
2464+ switch_mutex_unlock (schannel -> mutex );
24622465 }
24632466
24642467 return status ;
@@ -2480,6 +2483,8 @@ static switch_status_t recog_channel_enable_grammar(speech_channel_t *schannel,
24802483 } else {
24812484 recognizer_data_t * r = (recognizer_data_t * ) schannel -> data ;
24822485 grammar_t * grammar ;
2486+
2487+ switch_mutex_lock (schannel -> mutex );
24832488 grammar = (grammar_t * ) switch_core_hash_find (r -> grammars , grammar_name );
24842489 if (grammar == NULL )
24852490 {
@@ -2490,6 +2495,7 @@ static switch_status_t recog_channel_enable_grammar(speech_channel_t *schannel,
24902495 switch_log_printf (SWITCH_CHANNEL_UUID_LOG (schannel -> session_uuid ), SWITCH_LOG_DEBUG , "(%s) Enabling grammar %s\n" , schannel -> name , grammar_name );
24912496 switch_core_hash_insert (r -> enabled_grammars , grammar_name , grammar );
24922497 }
2498+ switch_mutex_unlock (schannel -> mutex );
24932499 }
24942500
24952501 return status ;
@@ -2511,7 +2517,10 @@ static switch_status_t recog_channel_disable_grammar(speech_channel_t *schannel,
25112517 } else {
25122518 recognizer_data_t * r = (recognizer_data_t * ) schannel -> data ;
25132519 switch_log_printf (SWITCH_CHANNEL_UUID_LOG (schannel -> session_uuid ), SWITCH_LOG_DEBUG , "(%s) Disabling grammar %s\n" , schannel -> name , grammar_name );
2520+
2521+ switch_mutex_lock (schannel -> mutex );
25142522 switch_core_hash_delete (r -> enabled_grammars , grammar_name );
2523+ switch_mutex_unlock (schannel -> mutex );
25152524 }
25162525
25172526 return status ;
@@ -2529,8 +2538,11 @@ static switch_status_t recog_channel_disable_all_grammars(speech_channel_t *scha
25292538
25302539 recognizer_data_t * r = (recognizer_data_t * ) schannel -> data ;
25312540 switch_log_printf (SWITCH_CHANNEL_UUID_LOG (schannel -> session_uuid ), SWITCH_LOG_DEBUG , "(%s) Disabling all grammars\n" , schannel -> name );
2541+
2542+ switch_mutex_lock (schannel -> mutex );
25322543 switch_core_hash_destroy (& r -> enabled_grammars );
25332544 switch_core_hash_init (& r -> enabled_grammars );
2545+ switch_mutex_unlock (schannel -> mutex );
25342546
25352547 return status ;
25362548}
@@ -3410,9 +3422,9 @@ static switch_status_t recog_asr_close(switch_asr_handle_t *ah, switch_asr_flag_
34103422 if (schannel != NULL && !switch_test_flag (ah , SWITCH_ASR_FLAG_CLOSED )) {
34113423 r = (recognizer_data_t * ) schannel -> data ;
34123424 speech_channel_stop (schannel );
3425+ switch_mutex_lock (schannel -> mutex );
34133426 switch_core_hash_destroy (& r -> grammars );
34143427 switch_core_hash_destroy (& r -> enabled_grammars );
3415- switch_mutex_lock (schannel -> mutex );
34163428 if (r -> dtmf_generator ) {
34173429 r -> dtmf_generator_active = 0 ;
34183430 mpf_dtmf_generator_destroy (r -> dtmf_generator );
0 commit comments