aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authorfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-18 17:15:49 +0000
committerfile <file@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-18 17:15:49 +0000
commit08416b58928a05020a098ed613bc172c67ddc775 (patch)
tree42dcc1c485f7df64a570559c787d4e6dd7e987d6 /channels
parente74ed3f29510975dc03ce7f54edc2f06ec87caeb (diff)
Put thread into proper list if we abort handling due to an error, and also hold the lock while putting it back into the proper idle list so we don't prematurely get a signal. (issue #8604 reported by arkadia)
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@48564 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_iax2.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 755dc6d93..3c2f80406 100644
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -830,6 +830,21 @@ static const struct ast_channel_tech iax2_tech = {
.fixup = iax2_fixup,
};
+static void insert_idle_thread(struct iax2_thread *thread)
+{
+ if (thread->type == IAX_TYPE_DYNAMIC) {
+ AST_LIST_LOCK(&dynamic_list);
+ AST_LIST_INSERT_TAIL(&dynamic_list, thread, list);
+ AST_LIST_UNLOCK(&dynamic_list);
+ } else {
+ AST_LIST_LOCK(&idle_list);
+ AST_LIST_INSERT_TAIL(&idle_list, thread, list);
+ AST_LIST_UNLOCK(&idle_list);
+ }
+
+ return;
+}
+
static struct iax2_thread *find_idle_thread(void)
{
struct iax2_thread *thread = NULL;
@@ -6182,15 +6197,11 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
if (errno != ECONNREFUSED && errno != EAGAIN)
ast_log(LOG_WARNING, "Error: %s\n", strerror(errno));
handle_error();
- AST_LIST_LOCK(&idle_list);
- AST_LIST_INSERT_TAIL(&idle_list, thread, list);
- AST_LIST_UNLOCK(&idle_list);
+ insert_idle_thread(thread);
return 1;
}
if (test_losspct && ((100.0 * ast_random() / (RAND_MAX + 1.0)) < test_losspct)) { /* simulate random loss condition */
- AST_LIST_LOCK(&idle_list);
- AST_LIST_INSERT_TAIL(&idle_list, thread, list);
- AST_LIST_UNLOCK(&idle_list);
+ insert_idle_thread(thread);
return 1;
}
/* Mark as ready and send on its way */
@@ -7569,10 +7580,16 @@ static void *iax2_process_thread(void *data)
struct iax2_thread *thread = data;
struct timeval tv;
struct timespec ts;
+ int put_into_idle = 0;
for(;;) {
/* Wait for something to signal us to be awake */
ast_mutex_lock(&thread->lock);
+
+ /* Put into idle list if applicable */
+ if (put_into_idle)
+ insert_idle_thread(thread);
+
if (thread->type == IAX_TYPE_DYNAMIC) {
/* Wait to be signalled or time out */
tv = ast_tvadd(ast_tvnow(), ast_samp2tv(30000, 1000));
@@ -7628,15 +7645,7 @@ static void *iax2_process_thread(void *data)
AST_LIST_UNLOCK(&active_list);
/* Go back into our respective list */
- if (thread->type == IAX_TYPE_DYNAMIC) {
- AST_LIST_LOCK(&dynamic_list);
- AST_LIST_INSERT_TAIL(&dynamic_list, thread, list);
- AST_LIST_UNLOCK(&dynamic_list);
- } else {
- AST_LIST_LOCK(&idle_list);
- AST_LIST_INSERT_TAIL(&idle_list, thread, list);
- AST_LIST_UNLOCK(&idle_list);
- }
+ put_into_idle = 1;
}
/* Free our own memory */