summaryrefslogtreecommitdiff
path: root/channels/chan_pjsip.c
diff options
context:
space:
mode:
authorRichard Mudgett <rmudgett@digium.com>2014-10-03 17:39:50 +0000
committerRichard Mudgett <rmudgett@digium.com>2014-10-03 17:39:50 +0000
commit6a844be566478d6fed1ec93c0836fbf5d5d46ff3 (patch)
treeca7a344f77695f1ecdeaf68cb5c9a6b899562b96 /channels/chan_pjsip.c
parentb67094624d33b6586177435017cd4f6fdedd3f3f (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 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@424472 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels/chan_pjsip.c')
-rw-r--r--channels/chan_pjsip.c52
1 files changed, 27 insertions, 25 deletions
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 015cd6448..ea55df799 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -701,40 +701,24 @@ static int chan_pjsip_write(struct ast_channel *ast, struct ast_frame *frame)
return res;
}
-struct fixup_data {
- struct ast_sip_session *session;
- struct ast_channel *chan;
-};
-
-static int fixup(void *data)
-{
- struct fixup_data *fix_data = data;
- struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(fix_data->chan);
- struct chan_pjsip_pvt *pvt = channel->pvt;
-
- channel->session->channel = fix_data->chan;
- set_channel_on_rtp_instance(pvt, ast_channel_uniqueid(fix_data->chan));
-
- return 0;
-}
-
/*! \brief Function called by core to change the underlying owner channel */
static int chan_pjsip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan)
{
struct ast_sip_channel_pvt *channel = ast_channel_tech_pvt(newchan);
- struct fixup_data fix_data;
-
- fix_data.session = channel->session;
- fix_data.chan = newchan;
+ struct chan_pjsip_pvt *pvt = channel->pvt;
if (channel->session->channel != oldchan) {
return -1;
}
- if (ast_sip_push_task_synchronous(channel->session->serializer, fixup, &fix_data)) {
- ast_log(LOG_WARNING, "Unable to perform channel fixup\n");
- return -1;
- }
+ /*
+ * The masquerade has suspended the channel's session
+ * serializer so we can safely change it outside of
+ * the serializer thread.
+ */
+ channel->session->channel = newchan;
+
+ set_channel_on_rtp_instance(pvt, ast_channel_uniqueid(newchan));
return 0;
}
@@ -1211,6 +1195,24 @@ static int chan_pjsip_indicate(struct ast_channel *ast, int condition, const voi
case AST_CONTROL_PVT_CAUSE_CODE:
res = -1;
break;
+ case AST_CONTROL_MASQUERADE_NOTIFY:
+ ast_assert(datalen == sizeof(int));
+ if (*(int *) data) {
+ /*
+ * Masquerade is beginning:
+ * Wait for session serializer to get suspended.
+ */
+ ast_channel_unlock(ast);
+ ast_sip_session_suspend(channel->session);
+ ast_channel_lock(ast);
+ } else {
+ /*
+ * Masquerade is complete:
+ * Unsuspend the session serializer.
+ */
+ ast_sip_session_unsuspend(channel->session);
+ }
+ break;
case AST_CONTROL_HOLD:
chan_pjsip_add_hold(ast_channel_uniqueid(ast));
device_buf_size = strlen(ast_channel_name(ast)) + 1;