diff options
author | Richard Mudgett <rmudgett@digium.com> | 2014-10-03 17:47:42 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2014-10-03 17:47:42 +0000 |
commit | 0165c5f95aa058b0884f8dec8695237cb0bef186 (patch) | |
tree | 9ca5505d80e72b574d9dad288351c760764fa8fb /main/taskprocessor.c | |
parent | 4967478d180f2a512cfb6ff83fa115aac43978c6 (diff) |
chan_pjsip: Fix deadlock when masquerading PJSIP channels.
Performing a directed call pickup resulted in a deadlock when PJSIP
channels were involved.
A masquerade needs to hold onto the channel locks while it swaps channel
information between the two channels involved in the masquerade. With
PJSIP channels, the fixup routine needed to push a fixup task onto the
PJSIP channel's serializer. Unfortunately, if the serializer was also
processing a task that needed to lock the channel, you get deadlock.
* Added a new control frame that is used to notify the channels that a
masquerade is about to start and when it has completed.
* Added the ability to query taskprocessors if the current thread is the
taskprocessor thread.
* Added the ability to suspend/unsuspend the PJSIP serializer thread so a
masquerade could fixup the PJSIP channel without using the serializer.
ASTERISK-24356 #close
Reported by: rmudgett
Review: https://reviewboard.asterisk.org/r/4034/
........
Merged revisions 424471 from http://svn.asterisk.org/svn/asterisk/branches/12
........
Merged revisions 424472 from http://svn.asterisk.org/svn/asterisk/branches/13
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424473 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/taskprocessor.c')
-rw-r--r-- | main/taskprocessor.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/main/taskprocessor.c b/main/taskprocessor.c index 0582f76fa..5fbbca571 100644 --- a/main/taskprocessor.c +++ b/main/taskprocessor.c @@ -78,9 +78,9 @@ struct ast_taskprocessor { long tps_queue_size; /*! \brief Taskprocessor queue */ AST_LIST_HEAD_NOLOCK(tps_queue, tps_task) tps_queue; - /*! \brief Taskprocessor singleton list entry */ - AST_LIST_ENTRY(ast_taskprocessor) list; struct ast_taskprocessor_listener *listener; + /*! Current thread executing the tasks */ + pthread_t thread; /*! Indicates if the taskprocessor is currently executing a task */ unsigned int executing:1; }; @@ -600,6 +600,8 @@ static struct ast_taskprocessor *__allocate_taskprocessor(const char *name, stru ao2_ref(listener, +1); p->listener = listener; + p->thread = AST_PTHREADT_NULL; + ao2_ref(p, +1); listener->tps = p; @@ -752,6 +754,7 @@ int ast_taskprocessor_execute(struct ast_taskprocessor *tps) return 0; } + tps->thread = pthread_self(); tps->executing = 1; if (t->wants_local) { @@ -768,6 +771,7 @@ int ast_taskprocessor_execute(struct ast_taskprocessor *tps) tps_task_free(t); ao2_lock(tps); + tps->thread = AST_PTHREADT_NULL; /* We need to check size in the same critical section where we reset the * executing bit. Avoids a race condition where a task is pushed right * after we pop an empty stack. @@ -789,3 +793,13 @@ int ast_taskprocessor_execute(struct ast_taskprocessor *tps) } return size > 0; } + +int ast_taskprocessor_is_task(struct ast_taskprocessor *tps) +{ + int is_task; + + ao2_lock(tps); + is_task = pthread_equal(tps->thread, pthread_self()); + ao2_unlock(tps); + return is_task; +} |