Index: channel.c =================================================================== --- channel.c (revision 21096) +++ channel.c (working copy) @@ -313,9 +313,9 @@ static int ast_check_hangup_locked(struct ast_channel *chan) { int res; - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); res = ast_check_hangup(chan); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return res; } @@ -682,13 +682,13 @@ ast_log(LOG_WARNING, "Unable to duplicate frame\n"); return -1; } - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); prev = NULL; for (cur = chan->readq; cur; cur = cur->next) { if ((cur->frametype == AST_FRAME_CONTROL) && (cur->subclass == AST_CONTROL_HANGUP)) { /* Don't bother actually queueing anything after a hangup */ ast_frfree(f); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return 0; } prev = cur; @@ -702,7 +702,7 @@ } else { ast_log(LOG_DEBUG, "Dropping voice to exceptionally long queue on %s\n", chan->name); ast_frfree(f); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return 0; } } @@ -721,7 +721,7 @@ } else if (ast_test_flag(chan, AST_FLAG_BLOCKING)) { pthread_kill(chan->blocker, SIGURG); } - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return 0; } @@ -730,9 +730,9 @@ { struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_HANGUP }; /* Yeah, let's not change a lock-critical value without locking */ - if (!ast_mutex_trylock(&chan->lock)) { + if (!ast_channel_trylock(chan)) { chan->_softhangup |= AST_SOFTHANGUP_DEV; - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); } return ast_queue_frame(chan, &f); } @@ -821,7 +821,8 @@ break; } /* exit if chan not found or mutex acquired successfully */ - done = c == NULL || ast_mutex_trylock(&c->lock) == 0; + /* this is slightly unsafe, as we _should_ hold the lock to access c->name */ + done = c == NULL || ast_channel_trylock(c) == 0; if (!done) ast_log(LOG_DEBUG, "Avoiding %s for channel '%p'\n", msg, c); AST_LIST_UNLOCK(&channels); @@ -926,8 +927,8 @@ AST_LIST_REMOVE(&channels, chan, chan_list); /* Lock and unlock the channel just to be sure nobody has it locked still */ - ast_mutex_lock(&chan->lock); - ast_mutex_unlock(&chan->lock); + ast_channel_lock(chan); + ast_channel_unlock(chan); if (chan->tech_pvt) { ast_log(LOG_WARNING, "Channel '%s' may not have been hung up properly\n", chan->name); free(chan->tech_pvt); @@ -1241,9 +1242,9 @@ int ast_softhangup(struct ast_channel *chan, int cause) { int res; - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); res = ast_softhangup_nolock(chan, cause); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return res; } @@ -1474,7 +1475,7 @@ ast_channel_lock(chan); /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return -1; } switch(chan->_state) { @@ -1497,7 +1498,7 @@ void ast_deactivate_generator(struct ast_channel *chan) { - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); if (chan->generatordata) { if (chan->generator && chan->generator->release) chan->generator->release(chan, chan->generatordata); @@ -1507,7 +1508,7 @@ ast_clear_flag(chan, AST_FLAG_WRITE_INT); ast_settimeout(chan, 0, NULL, NULL); } - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); } static int generator_force(void *data) @@ -2057,7 +2058,7 @@ chan->fin++; done: - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return f; } @@ -2083,15 +2084,15 @@ { int res = -1; - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); /* Stop if we're a zombie or need a soft hangup */ if (ast_test_flag(chan, AST_FLAG_ZOMBIE) || ast_check_hangup(chan)) { - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return -1; } if (chan->tech->indicate) res = chan->tech->indicate(chan, condition); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); if (!chan->tech->indicate || res) { /* * Device does not support (that) indication, lets fake @@ -2631,11 +2632,11 @@ return anyway. */ int res = -1; /* Stop if we're a zombie or need a soft hangup */ - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) if (chan->tech->call) res = chan->tech->call(chan, addr, timeout); - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return res; } @@ -2651,7 +2652,7 @@ int res = -1; /* Stop if we're a zombie or need a soft hangup */ - ast_mutex_lock(&chan->lock); + ast_channel_lock(chan); if (!ast_test_flag(chan, AST_FLAG_ZOMBIE) && !ast_check_hangup(chan)) { if (chan->tech->transfer) { res = chan->tech->transfer(chan, dest); @@ -2660,7 +2661,7 @@ } else res = 0; } - ast_mutex_unlock(&chan->lock); + ast_channel_unlock(chan); return res; } @@ -2792,11 +2793,11 @@ ast_log(LOG_WARNING, "Can't masquerade channel '%s' into itself!\n", original->name); return -1; } - ast_mutex_lock(&original->lock); - while(ast_mutex_trylock(&clone->lock)) { - ast_mutex_unlock(&original->lock); + ast_channel_lock(original); + while(ast_channel_trylock(clone)) { + ast_channel_unlock(original); usleep(1); - ast_mutex_lock(&original->lock); + ast_channel_lock(original); } ast_log(LOG_DEBUG, "Planning to masquerade channel %s into the structure of %s\n", clone->name, original->name); @@ -2814,8 +2815,8 @@ ast_log(LOG_DEBUG, "Done planning to masquerade channel %s into the structure of %s\n", clone->name, original->name); res = 0; } - ast_mutex_unlock(&clone->lock); - ast_mutex_unlock(&original->lock); + ast_channel_unlock(clone); + ast_channel_unlock(original); return res; }