From: Mike Bradeen Date: Wed, 10 Jul 2024 18:58:44 +0000 (-0600) Subject: res_stasis: fix intermittent delays on adding channel to bridge X-Git-Tag: 21.5.0-rc1~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=40fbf916cd7e48aa788ce87ce477c7348a448766;p=thirdparty%2Fasterisk.git res_stasis: fix intermittent delays on adding channel to bridge Previously, on command execution, the control thread was awoken by sending a SIGURG. It was found that this still resulted in some instances where the thread was not immediately awoken. This change instead sends a null frame to awaken the control thread, which awakens the thread more consistently. Resolves: #801 (cherry picked from commit bdee743cd40901a1a082be749ccb23541e720a49) --- diff --git a/res/res_stasis.c b/res/res_stasis.c index 6b4c30d894..84244c2a13 100644 --- a/res/res_stasis.c +++ b/res/res_stasis.c @@ -1548,11 +1548,7 @@ int stasis_app_exec(struct ast_channel *chan, const char *app_name, int argc, continue; } - /* Set this thread's id as the control thread id so that any - new commands can signal out of this wait */ - control_set_thread(control, pthread_self()); r = ast_waitfor(chan, MAX_WAIT_MS); - control_set_thread(control, AST_PTHREADT_NULL); if (r < 0) { ast_debug(3, "%s: Poll error\n", diff --git a/res/stasis/control.c b/res/stasis/control.c index 4ed0e2af1c..dfbc007399 100644 --- a/res/stasis/control.c +++ b/res/stasis/control.c @@ -94,10 +94,6 @@ struct stasis_app_control { * The name of the next Stasis application to move to. */ char *next_app; - /*! - * The thread currently blocking on the channel. - */ - pthread_t control_thread; /*! * The list of arguments to pass to StasisStart when moving to another app. */ @@ -162,8 +158,6 @@ struct stasis_app_control *control_create(struct ast_channel *channel, struct st control->next_app = NULL; AST_VECTOR_INIT(&control->next_app_args, 0); - control_set_thread(control, AST_PTHREADT_NULL); - return control; } @@ -193,13 +187,6 @@ static void app_control_unregister_rule( ao2_unlock(control->command_queue); } -void control_set_thread(struct stasis_app_control *control, pthread_t threadid) -{ - ao2_lock(control->command_queue); - control->control_thread = threadid; - ao2_unlock(control->command_queue); -} - /*! * \internal * \brief Checks to make sure each rule in the given list passes. @@ -309,10 +296,10 @@ static struct stasis_app_command *exec_command_on_condition( ao2_link_flags(control->command_queue, command, OBJ_NOLOCK); ast_cond_signal(&control->wait_cond); - if (control->control_thread != AST_PTHREADT_NULL) { - /* if the control thread is waiting on the channel, send the SIGURG - to let it know there is a new command */ - pthread_kill(control->control_thread, SIGURG); + if (control->channel) { + /* Queue a null frame so that if and when the channel is waited on, + return immediately to process the new command */ + ast_queue_frame(control->channel, &ast_null_frame); } ao2_unlock(control->command_queue); diff --git a/res/stasis/control.h b/res/stasis/control.h index 3593f8a40f..137ac81557 100644 --- a/res/stasis/control.h +++ b/res/stasis/control.h @@ -48,15 +48,6 @@ struct stasis_app_control *control_create(struct ast_channel *channel, struct st */ void control_flush_queue(struct stasis_app_control *control); -/*! - * \brief set the control's thread id - * \since 18 - * - * \param control Control object on which to set the thread id. - * \param threadid id to set - */ -void control_set_thread(struct stasis_app_control *control, pthread_t threadid); - /*! * \brief Dispatch all commands enqueued to this control. *