aboutsummaryrefslogtreecommitdiffstats
path: root/res/res_musiconhold.c
diff options
context:
space:
mode:
Diffstat (limited to 'res/res_musiconhold.c')
-rw-r--r--res/res_musiconhold.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index f0c8a27a5..8af2b76b8 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -329,7 +329,15 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in
state->sample_queue += samples;
while (state->sample_queue > 0) {
+ ast_channel_lock(chan);
if ((f = moh_files_readframe(chan))) {
+ /* We need to be sure that we unlock
+ * the channel prior to calling
+ * ast_write. Otherwise, the recursive locking
+ * that occurs can cause deadlocks when using
+ * indirect channels, like local channels
+ */
+ ast_channel_unlock(chan);
state->samples += f->samples;
state->sample_queue -= f->samples;
res = ast_write(chan, f);
@@ -338,8 +346,10 @@ static int moh_files_generator(struct ast_channel *chan, void *data, int len, in
ast_log(LOG_WARNING, "Failed to write frame to '%s': %s\n", chan->name, strerror(errno));
return -1;
}
- } else
+ } else {
+ ast_channel_unlock(chan);
return -1;
+ }
}
return res;
}
@@ -1432,11 +1442,11 @@ static int local_ast_moh_start(struct ast_channel *chan, const char *mclass, con
static void local_ast_moh_stop(struct ast_channel *chan)
{
- struct moh_files_state *state = chan->music_state;
ast_clear_flag(chan, AST_FLAG_MOH);
ast_deactivate_generator(chan);
- if (state) {
+ ast_channel_lock(chan);
+ if (chan->music_state) {
if (chan->stream) {
ast_closestream(chan->stream);
chan->stream = NULL;
@@ -1448,6 +1458,7 @@ static void local_ast_moh_stop(struct ast_channel *chan)
"Channel: %s\r\n"
"UniqueID: %s\r\n",
chan->name, chan->uniqueid);
+ ast_channel_unlock(chan);
}
static void moh_class_destructor(void *obj)