sorcery: Move from threadpool to taskpool.

This change moves observer invocation from the use of
a threadpool to a taskpool. The taskpool options have also
been adjusted to ensure that at least one taskprocessor
remains available at all times.
This commit is contained in:
Joshua C. Colp
2025-09-23 19:54:35 -03:00
parent aa3ff4ec60
commit b1e410c4b5

View File

@@ -39,7 +39,7 @@
#include "asterisk/netsock2.h" #include "asterisk/netsock2.h"
#include "asterisk/module.h" #include "asterisk/module.h"
#include "asterisk/taskprocessor.h" #include "asterisk/taskprocessor.h"
#include "asterisk/threadpool.h" #include "asterisk/taskpool.h"
#include "asterisk/json.h" #include "asterisk/json.h"
#include "asterisk/vector.h" #include "asterisk/vector.h"
#include "asterisk/cli.h" #include "asterisk/cli.h"
@@ -83,8 +83,8 @@
#define NOTIFY_WIZARD_OBSERVERS(container, callback, ...) \ #define NOTIFY_WIZARD_OBSERVERS(container, callback, ...) \
NOTIFY_GENERIC_OBSERVERS(container, sorcery_wizard_observer, callback, __VA_ARGS__) NOTIFY_GENERIC_OBSERVERS(container, sorcery_wizard_observer, callback, __VA_ARGS__)
/*! \brief Thread pool for observers */ /*! \brief Taskpool for observers */
static struct ast_threadpool *threadpool; static struct ast_taskpool *taskpool;
/*! \brief Structure for an internal wizard instance */ /*! \brief Structure for an internal wizard instance */
struct ast_sorcery_internal_wizard { struct ast_sorcery_internal_wizard {
@@ -402,8 +402,8 @@ static struct ast_cli_entry cli_commands[] = {
static void sorcery_cleanup(void) static void sorcery_cleanup(void)
{ {
ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands)); ast_cli_unregister_multiple(cli_commands, ARRAY_LEN(cli_commands));
ast_threadpool_shutdown(threadpool); ast_taskpool_shutdown(taskpool);
threadpool = NULL; taskpool = NULL;
ao2_cleanup(wizards); ao2_cleanup(wizards);
wizards = NULL; wizards = NULL;
ao2_cleanup(observers); ao2_cleanup(observers);
@@ -443,19 +443,20 @@ static void parse_general_options(void)
int ast_sorcery_init(void) int ast_sorcery_init(void)
{ {
struct ast_threadpool_options options = { struct ast_taskpool_options options = {
.version = AST_THREADPOOL_OPTIONS_VERSION, .version = AST_TASKPOOL_OPTIONS_VERSION,
.auto_increment = 1, .auto_increment = 1,
.max_size = 0, .max_size = 0,
.idle_timeout = 60, .idle_timeout = 60,
.initial_size = 0, .initial_size = 1,
.minimum_size = 1,
}; };
ast_assert(wizards == NULL); ast_assert(wizards == NULL);
parse_general_options(); parse_general_options();
threadpool = ast_threadpool_create("sorcery", NULL, &options); taskpool = ast_taskpool_create("sorcery", &options);
if (!threadpool) { if (!taskpool) {
return -1; return -1;
} }
@@ -807,7 +808,7 @@ static struct ast_sorcery_object_type *sorcery_object_type_alloc(const char *typ
/* Create name with seq number appended. */ /* Create name with seq number appended. */
ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "sorcery/%s", type); ast_taskprocessor_build_name(tps_name, sizeof(tps_name), "sorcery/%s", type);
if (!(object_type->serializer = ast_threadpool_serializer(tps_name, threadpool))) { if (!(object_type->serializer = ast_taskpool_serializer(tps_name, taskpool))) {
ao2_ref(object_type, -1); ao2_ref(object_type, -1);
return NULL; return NULL;
} }