[Asterisk-code-review] res_pjsip_refer: Move the progress dlg release to a serializer (asterisk[master])

George Joseph asteriskteam at digium.com
Fri Mar 5 08:19:23 CST 2021


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15535 )

Change subject: res_pjsip_refer: Move the progress dlg release to a serializer
......................................................................

res_pjsip_refer: Move the progress dlg release to a serializer

Although the dlg session count was incremented in a pjsip servant
thread, there's no guarantee that the last thread to unref this
progress object was one.  Before we decrement, we need to make
sure that this is either a servant thread or that we push the
decrement to a serializer that is one.

Because pjsip_dlg_dec_session requires the dialog lock, we don't
want to wait on the task to complete if we had to push it to a
serializer.

Change-Id: I8ff2d5d94be3ff04298394070434e22a7d3cbc41
---
M res/res_pjsip_refer.c
1 file changed, 20 insertions(+), 1 deletion(-)

Approvals:
  Benjamin Keith Ford: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/res/res_pjsip_refer.c b/res/res_pjsip_refer.c
index 07fe23d..8890d23 100644
--- a/res/res_pjsip_refer.c
+++ b/res/res_pjsip_refer.c
@@ -340,6 +340,11 @@
 	.on_evsub_state = refer_progress_on_evsub_state,
 };
 
+static int dlg_releaser_task(void *data) {
+	pjsip_dlg_dec_session((pjsip_dialog *)data, &refer_progress_module);
+	return 0;
+}
+
 /*! \brief Destructor for REFER progress sutrcture */
 static void refer_progress_destroy(void *obj)
 {
@@ -350,7 +355,21 @@
 	}
 
 	if (progress->dlg) {
-		pjsip_dlg_dec_session(progress->dlg, &refer_progress_module);
+		/*
+		 * Although the dlg session count was incremented in a pjsip servant
+		 * thread, there's no guarantee that the last thread to unref this progress
+		 * object was one.  Before we decrement, we need to make sure that this
+		 * is either a servant thread or that we push the decrement to a
+		 * serializer that is one.
+		 *
+		 * Because pjsip_dlg_dec_session requires the dialog lock, we don't want
+		 * to wait on the task to complete if we had to push it to a serializer.
+		 */
+		if (ast_sip_thread_is_servant()) {
+			pjsip_dlg_dec_session(progress->dlg, &refer_progress_module);
+		} else {
+			ast_sip_push_task(NULL, dlg_releaser_task, progress->dlg);
+		}
 	}
 
 	ao2_cleanup(progress->transfer_data);

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15535
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: I8ff2d5d94be3ff04298394070434e22a7d3cbc41
Gerrit-Change-Number: 15535
Gerrit-PatchSet: 3
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210305/0bdb4439/attachment.html>


More information about the asterisk-code-review mailing list