mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-19 03:08:45 +00:00
access channel locks through ast_channel_lock/unlock/trylock and not
through ast_mutex primitives. To detect all occurrences, I have renamed the lock field in struct ast_channel so it is clear that it shouldn't be used directly. There are some uses in res/res_features.c (see details of the diff) that are error prone as they try and lock two channels without caring about the order (or without explaining why it is safe). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@89293 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -81,7 +81,7 @@ static int asyncgoto_exec(struct ast_channel *chan, void *data)
|
|||||||
|
|
||||||
res = ast_parseable_goto(chan2, args.label);
|
res = ast_parseable_goto(chan2, args.label);
|
||||||
|
|
||||||
ast_mutex_unlock(&chan2->lock);
|
ast_channel_unlock(chan2);
|
||||||
quit:
|
quit:
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
@@ -102,13 +102,13 @@ static int manager_play_dtmf(struct mansession *s, const struct message *m)
|
|||||||
}
|
}
|
||||||
if (!digit) {
|
if (!digit) {
|
||||||
astman_send_error(s, m, "No digit specified");
|
astman_send_error(s, m, "No digit specified");
|
||||||
ast_mutex_unlock(&chan->lock);
|
ast_channel_unlock(chan);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_senddigit(chan, *digit, 0);
|
ast_senddigit(chan, *digit, 0);
|
||||||
|
|
||||||
ast_mutex_unlock(&chan->lock);
|
ast_channel_unlock(chan);
|
||||||
astman_send_ack(s, m, "DTMF successfully queued");
|
astman_send_ack(s, m, "DTMF successfully queued");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -104,11 +104,11 @@ static int softhangup_exec(struct ast_channel *chan, void *data)
|
|||||||
ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
|
ast_log(LOG_WARNING, "Soft hanging %s up.\n", c->name);
|
||||||
ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
|
ast_softhangup(c, AST_SOFTHANGUP_EXPLICIT);
|
||||||
if (!ast_test_flag(&flags, OPTION_ALL)) {
|
if (!ast_test_flag(&flags, OPTION_ALL)) {
|
||||||
ast_mutex_unlock(&c->lock);
|
ast_channel_unlock(c);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(&c->lock);
|
ast_channel_unlock(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@@ -421,7 +421,7 @@ struct ast_channel {
|
|||||||
directly, use ast_softhangup() */
|
directly, use ast_softhangup() */
|
||||||
time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
|
time_t whentohangup; /*!< Non-zero, set to actual time when channel is to be hung up */
|
||||||
pthread_t blocker; /*!< If anyone is blocking, this is them */
|
pthread_t blocker; /*!< If anyone is blocking, this is them */
|
||||||
ast_mutex_t lock; /*!< Lock, can be used to lock a channel for some operations - see ast_channel_lock() */
|
ast_mutex_t lock_dont_use; /*!< Lock, can be used to lock a channel for some operations - see ast_channel_lock() */
|
||||||
const char *blockproc; /*!< Procedure causing blocking */
|
const char *blockproc; /*!< Procedure causing blocking */
|
||||||
|
|
||||||
const char *appl; /*!< Current application */
|
const char *appl; /*!< Current application */
|
||||||
|
@@ -1167,13 +1167,13 @@ AST_INLINE_API(int ast_atomic_dec_and_test(volatile int *p),
|
|||||||
#ifndef DEBUG_CHANNEL_LOCKS
|
#ifndef DEBUG_CHANNEL_LOCKS
|
||||||
/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
/*! \brief Lock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
||||||
in the Makefile, print relevant output for debugging */
|
in the Makefile, print relevant output for debugging */
|
||||||
#define ast_channel_lock(x) ast_mutex_lock(&x->lock)
|
#define ast_channel_lock(x) ast_mutex_lock(&x->lock_dont_use)
|
||||||
/*! \brief Unlock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
/*! \brief Unlock a channel. If DEBUG_CHANNEL_LOCKS is defined
|
||||||
in the Makefile, print relevant output for debugging */
|
in the Makefile, print relevant output for debugging */
|
||||||
#define ast_channel_unlock(x) ast_mutex_unlock(&x->lock)
|
#define ast_channel_unlock(x) ast_mutex_unlock(&x->lock_dont_use)
|
||||||
/*! \brief Try locking a channel. If DEBUG_CHANNEL_LOCKS is defined
|
/*! \brief Try locking a channel. If DEBUG_CHANNEL_LOCKS is defined
|
||||||
in the Makefile, print relevant output for debugging */
|
in the Makefile, print relevant output for debugging */
|
||||||
#define ast_channel_trylock(x) ast_mutex_trylock(&x->lock)
|
#define ast_channel_trylock(x) ast_mutex_trylock(&x->lock_dont_use)
|
||||||
#else
|
#else
|
||||||
|
|
||||||
struct ast_channel;
|
struct ast_channel;
|
||||||
|
@@ -778,7 +778,7 @@ struct ast_channel *ast_channel_alloc(int needqueue, int state, const char *cid_
|
|||||||
headp = &tmp->varshead;
|
headp = &tmp->varshead;
|
||||||
AST_LIST_HEAD_INIT_NOLOCK(headp);
|
AST_LIST_HEAD_INIT_NOLOCK(headp);
|
||||||
|
|
||||||
ast_mutex_init(&tmp->lock);
|
ast_mutex_init(&tmp->lock_dont_use);
|
||||||
|
|
||||||
AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
|
AST_LIST_HEAD_INIT_NOLOCK(&tmp->datastores);
|
||||||
|
|
||||||
@@ -1136,7 +1136,7 @@ void ast_channel_free(struct ast_channel *chan)
|
|||||||
if (chan->pbx)
|
if (chan->pbx)
|
||||||
ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
|
ast_log(LOG_WARNING, "PBX may not have been terminated properly on '%s'\n", chan->name);
|
||||||
free_cid(&chan->cid);
|
free_cid(&chan->cid);
|
||||||
ast_mutex_destroy(&chan->lock);
|
ast_mutex_destroy(&chan->lock_dont_use);
|
||||||
/* Close pipes if appropriate */
|
/* Close pipes if appropriate */
|
||||||
if ((fd = chan->alertpipe[0]) > -1)
|
if ((fd = chan->alertpipe[0]) > -1)
|
||||||
close(fd);
|
close(fd);
|
||||||
@@ -2883,13 +2883,13 @@ int ast_write(struct ast_channel *chan, struct ast_frame *fr)
|
|||||||
if (!chan->tech->get_base_channel || chan == chan->tech->get_base_channel(chan))
|
if (!chan->tech->get_base_channel || chan == chan->tech->get_base_channel(chan))
|
||||||
res = chan->tech->write(chan, f);
|
res = chan->tech->write(chan, f);
|
||||||
else {
|
else {
|
||||||
while (chan->tech->get_base_channel && (((base = chan->tech->get_base_channel(chan)) && ast_mutex_trylock(&base->lock)) || base == NULL)) {
|
while (chan->tech->get_base_channel && (((base = chan->tech->get_base_channel(chan)) && ast_channel_trylock(base)) || base == NULL)) {
|
||||||
ast_mutex_unlock(&chan->lock);
|
ast_channel_unlock(chan);
|
||||||
usleep(1);
|
usleep(1);
|
||||||
ast_mutex_lock(&chan->lock);
|
ast_channel_lock(chan);
|
||||||
}
|
}
|
||||||
res = base->tech->write(base, f);
|
res = base->tech->write(base, f);
|
||||||
ast_mutex_unlock(&base->lock);
|
ast_channel_unlock(base);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
res = 0;
|
res = 0;
|
||||||
@@ -3541,7 +3541,7 @@ int ast_do_masquerade(struct ast_channel *original)
|
|||||||
/* We need the clone's lock, too */
|
/* We need the clone's lock, too */
|
||||||
ast_channel_lock(clone);
|
ast_channel_lock(clone);
|
||||||
|
|
||||||
ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock);
|
ast_debug(2, "Got clone lock for masquerade on '%s' at %p\n", clone->name, &clone->lock_dont_use);
|
||||||
|
|
||||||
/* Having remembered the original read/write formats, we turn off any translation on either
|
/* Having remembered the original read/write formats, we turn off any translation on either
|
||||||
one */
|
one */
|
||||||
@@ -4670,12 +4670,12 @@ int ast_channel_unlock(struct ast_channel *chan)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
res = ast_mutex_unlock(&chan->lock);
|
res = ast_mutex_unlock(&chan->lock_dont_use);
|
||||||
|
|
||||||
if (option_debug > 2) {
|
if (option_debug > 2) {
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if ((count = chan->lock.reentrancy))
|
if ((count = chan->lock_dont_use.reentrancy))
|
||||||
ast_debug(3, ":::=== Still have %d locks (recursive)\n", count);
|
ast_debug(3, ":::=== Still have %d locks (recursive)\n", count);
|
||||||
#endif
|
#endif
|
||||||
if (!res)
|
if (!res)
|
||||||
@@ -4700,12 +4700,12 @@ int ast_channel_lock(struct ast_channel *chan)
|
|||||||
|
|
||||||
ast_debug(4, "====:::: Locking AST channel %s\n", chan->name);
|
ast_debug(4, "====:::: Locking AST channel %s\n", chan->name);
|
||||||
|
|
||||||
res = ast_mutex_lock(&chan->lock);
|
res = ast_mutex_lock(&chan->lock_dont_use);
|
||||||
|
|
||||||
if (option_debug > 3) {
|
if (option_debug > 3) {
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if ((count = chan->lock.reentrancy))
|
if ((count = chan->lock_dont_use.reentrancy))
|
||||||
ast_debug(4, ":::=== Now have %d locks (recursive)\n", count);
|
ast_debug(4, ":::=== Now have %d locks (recursive)\n", count);
|
||||||
#endif
|
#endif
|
||||||
if (!res)
|
if (!res)
|
||||||
@@ -4729,12 +4729,12 @@ int ast_channel_trylock(struct ast_channel *chan)
|
|||||||
|
|
||||||
ast_debug(3, "====:::: Trying to lock AST channel %s\n", chan->name);
|
ast_debug(3, "====:::: Trying to lock AST channel %s\n", chan->name);
|
||||||
|
|
||||||
res = ast_mutex_trylock(&chan->lock);
|
res = ast_mutex_trylock(&chan->lock_dont_use);
|
||||||
|
|
||||||
if (option_debug > 2) {
|
if (option_debug > 2) {
|
||||||
#ifdef DEBUG_THREADS
|
#ifdef DEBUG_THREADS
|
||||||
int count = 0;
|
int count = 0;
|
||||||
if ((count = chan->lock.reentrancy))
|
if ((count = chan->lock_dont_use.reentrancy))
|
||||||
ast_debug(3, ":::=== Now have %d locks (recursive)\n", count);
|
ast_debug(3, ":::=== Now have %d locks (recursive)\n", count);
|
||||||
#endif
|
#endif
|
||||||
if (!res)
|
if (!res)
|
||||||
|
@@ -1759,7 +1759,7 @@ static int action_sendtext(struct mansession *s, const struct message *m)
|
|||||||
}
|
}
|
||||||
|
|
||||||
res = ast_sendtext(c, textmsg);
|
res = ast_sendtext(c, textmsg);
|
||||||
ast_mutex_unlock(&c->lock);
|
ast_channel_unlock(c);
|
||||||
|
|
||||||
if (res > 0)
|
if (res > 0)
|
||||||
astman_send_ack(s, m, "Success");
|
astman_send_ack(s, m, "Success");
|
||||||
|
@@ -2449,17 +2449,17 @@ static char mandescr_bridge[] =
|
|||||||
static void do_bridge_masquerade(struct ast_channel *chan, struct ast_channel *tmpchan)
|
static void do_bridge_masquerade(struct ast_channel *chan, struct ast_channel *tmpchan)
|
||||||
{
|
{
|
||||||
ast_moh_stop(chan);
|
ast_moh_stop(chan);
|
||||||
ast_mutex_lock(&chan->lock);
|
ast_channel_lock(chan);
|
||||||
ast_setstate(tmpchan, chan->_state);
|
ast_setstate(tmpchan, chan->_state);
|
||||||
tmpchan->readformat = chan->readformat;
|
tmpchan->readformat = chan->readformat;
|
||||||
tmpchan->writeformat = chan->writeformat;
|
tmpchan->writeformat = chan->writeformat;
|
||||||
ast_channel_masquerade(tmpchan, chan);
|
ast_channel_masquerade(tmpchan, chan);
|
||||||
ast_mutex_lock(&tmpchan->lock);
|
ast_channel_lock(tmpchan);
|
||||||
ast_do_masquerade(tmpchan);
|
ast_do_masquerade(tmpchan);
|
||||||
/* when returning from bridge, the channel will continue at the next priority */
|
/* when returning from bridge, the channel will continue at the next priority */
|
||||||
ast_explicit_goto(tmpchan, chan->context, chan->exten, chan->priority + 1);
|
ast_explicit_goto(tmpchan, chan->context, chan->exten, chan->priority + 1);
|
||||||
ast_mutex_unlock(&tmpchan->lock);
|
ast_channel_unlock(tmpchan);
|
||||||
ast_mutex_unlock(&chan->lock);
|
ast_channel_unlock(chan);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@@ -2490,9 +2490,9 @@ static int action_bridge(struct mansession *s, const struct message *m)
|
|||||||
chana = ast_get_channel_by_name_prefix_locked(channela, strlen(channela));
|
chana = ast_get_channel_by_name_prefix_locked(channela, strlen(channela));
|
||||||
chanb = ast_get_channel_by_name_prefix_locked(channelb, strlen(channelb));
|
chanb = ast_get_channel_by_name_prefix_locked(channelb, strlen(channelb));
|
||||||
if (chana)
|
if (chana)
|
||||||
ast_mutex_unlock(&chana->lock);
|
ast_channel_unlock(chana);
|
||||||
if (chanb)
|
if (chanb)
|
||||||
ast_mutex_unlock(&chanb->lock);
|
ast_channel_unlock(chanb);
|
||||||
|
|
||||||
/* send errors if any of the channels could not be found/locked */
|
/* send errors if any of the channels could not be found/locked */
|
||||||
if (!chana) {
|
if (!chana) {
|
||||||
@@ -3186,7 +3186,7 @@ static int bridge_exec(struct ast_channel *chan, void *data)
|
|||||||
ast_module_user_remove(u);
|
ast_module_user_remove(u);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
ast_mutex_unlock(¤t_dest_chan->lock);
|
ast_channel_unlock(current_dest_chan);
|
||||||
|
|
||||||
/* answer the channel if needed */
|
/* answer the channel if needed */
|
||||||
if (current_dest_chan->_state != AST_STATE_UP)
|
if (current_dest_chan->_state != AST_STATE_UP)
|
||||||
|
Reference in New Issue
Block a user