[Asterisk-code-review] RFC: Use same thread if AST OUTGOING WAIT COMPLETE specified (asterisk[13])
Sean Bright
asteriskteam at digium.com
Wed Apr 19 15:36:47 CDT 2017
Sean Bright has uploaded a new change for review. ( https://gerrit.asterisk.org/5506 )
Change subject: RFC: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified
......................................................................
RFC: Use same thread if AST_OUTGOING_WAIT_COMPLETE specified
Change-Id: I512735d243f0a9da2bcc128f7a96dece71f2d913
---
M main/pbx.c
1 file changed, 28 insertions(+), 30 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/06/5506/1
diff --git a/main/pbx.c b/main/pbx.c
index df99940..b1eabbc 100644
--- a/main/pbx.c
+++ b/main/pbx.c
@@ -7457,8 +7457,6 @@
int dial_res;
/*! \brief Set when dialing is completed */
unsigned int dialed:1;
- /*! \brief Set when execution is completed */
- unsigned int executed:1;
};
/*! \brief Destructor for outgoing structure */
@@ -7526,12 +7524,6 @@
ast_dial_answered_steal(outgoing->dial);
}
}
-
- /* Notify anyone else again that may be interested that execution is complete */
- ao2_lock(outgoing);
- outgoing->executed = 1;
- ast_cond_signal(&outgoing->cond);
- ao2_unlock(outgoing);
return NULL;
}
@@ -7712,34 +7704,40 @@
}
}
+ /* This extra reference is dereferenced by pbx_outgoing_exec */
ao2_ref(outgoing, +1);
- if (ast_pthread_create_detached(&thread, NULL, pbx_outgoing_exec, outgoing)) {
- ast_log(LOG_WARNING, "Unable to spawn dialing thread for '%s/%s'\n", type, addr);
- ao2_ref(outgoing, -1);
- if (locked_channel) {
- if (!synchronous) {
- ast_channel_unlock(dialed);
+
+ if (synchronous == AST_OUTGOING_WAIT_COMPLETE) {
+ /*
+ * Because we are waiting until this is complete anyway, there is no
+ * sense in creating another thread that we will just need to wait
+ * for, so instead we commandeer the current thread.
+ */
+ pbx_outgoing_exec(outgoing);
+ } else {
+ if (ast_pthread_create_detached(&thread, NULL, pbx_outgoing_exec, outgoing)) {
+ ast_log(LOG_WARNING, "Unable to spawn dialing thread for '%s/%s'\n", type, addr);
+ ao2_ref(outgoing, -1);
+ if (locked_channel) {
+ if (!synchronous) {
+ ast_channel_unlock(dialed);
+ }
+ ast_channel_unref(dialed);
}
- ast_channel_unref(dialed);
+ return -1;
}
- return -1;
+
+ if (synchronous) {
+ ao2_lock(outgoing);
+ /* Wait for dialing to complete */
+ while (!outgoing->dialed) {
+ ast_cond_wait(&outgoing->cond, ao2_object_get_lockaddr(outgoing));
+ }
+ ao2_unlock(outgoing);
+ }
}
if (synchronous) {
- ao2_lock(outgoing);
- /* Wait for dialing to complete */
- while (!outgoing->dialed) {
- ast_cond_wait(&outgoing->cond, ao2_object_get_lockaddr(outgoing));
- }
- if (1 < synchronous
- && outgoing->dial_res == AST_DIAL_RESULT_ANSWERED) {
- /* Wait for execution to complete */
- while (!outgoing->executed) {
- ast_cond_wait(&outgoing->cond, ao2_object_get_lockaddr(outgoing));
- }
- }
- ao2_unlock(outgoing);
-
/* Determine the outcome of the dialing attempt up to it being answered. */
if (reason) {
*reason = pbx_dial_reason(outgoing->dial_res,
--
To view, visit https://gerrit.asterisk.org/5506
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I512735d243f0a9da2bcc128f7a96dece71f2d913
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Sean Bright <sean.bright at gmail.com>
More information about the asterisk-code-review
mailing list