[asterisk-commits] dlee: branch dlee/stasis-config r393356 - in /team/dlee/stasis-config: config...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 1 16:00:02 CDT 2013


Author: dlee
Date: Mon Jul  1 16:00:00 2013
New Revision: 393356

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393356
Log:
Stasis threadpool configuration support

Added:
    team/dlee/stasis-config/configs/stasis.conf.sample
      - copied, changed from r393308, team/dlee/stasis-config/configs/stasis_core.conf.sample
    team/dlee/stasis-config/main/stasis_config.c   (with props)
Removed:
    team/dlee/stasis-config/configs/stasis_core.conf.sample
Modified:
    team/dlee/stasis-config/include/asterisk/stasis.h
    team/dlee/stasis-config/main/asterisk.c
    team/dlee/stasis-config/main/stasis.c

Copied: team/dlee/stasis-config/configs/stasis.conf.sample (from r393308, team/dlee/stasis-config/configs/stasis_core.conf.sample)
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-config/configs/stasis.conf.sample?view=diff&rev=393356&p1=team/dlee/stasis-config/configs/stasis_core.conf.sample&r1=393308&p2=team/dlee/stasis-config/configs/stasis.conf.sample&r2=393356
==============================================================================
--- team/dlee/stasis-config/configs/stasis_core.conf.sample (original)
+++ team/dlee/stasis-config/configs/stasis.conf.sample Mon Jul  1 16:00:00 2013
@@ -1,6 +1,8 @@
-[general]
+[threadpool]
+;initial_size = 0	; Initial size of the threadpool
 
-[threadpool]
-;initial_size = 0       ; Initial size of the threadpool
-;idle_timeout = 20      ; Number of seconds a thread should be idle before dying
+;idle_timeout_sec = 20	; Number of seconds a thread should be idle before dying
+;			; 0 means threads never time out
+
 ;max_size = 200         ; Maximum number of threads in the threadpool
+;			; 0 means no limit to the threads in the threadpool

Modified: team/dlee/stasis-config/include/asterisk/stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-config/include/asterisk/stasis.h?view=diff&rev=393356&r1=393355&r2=393356
==============================================================================
--- team/dlee/stasis-config/include/asterisk/stasis.h (original)
+++ team/dlee/stasis-config/include/asterisk/stasis.h Mon Jul  1 16:00:00 2013
@@ -809,15 +809,19 @@
 /*! @{ */
 
 /*!
- * \brief Initialize the Stasis subsystem
+ * \brief Initialize the Stasis subsystem.
  * \return 0 on success.
  * \return Non-zero on error.
  * \since 12
  */
 int stasis_init(void);
 
-/*!
- * \private
+/*! @} */
+
+/*! @{ */
+
+/*!
+ * \internal
  * \brief called by stasis_init() for cache initialization.
  * \return 0 on success.
  * \return Non-zero on error.
@@ -825,6 +829,25 @@
  */
 int stasis_cache_init(void);
 
+/*!
+ * \internal
+ * \brief called by stasis_init for config initialization.
+ * \return 0 on success.
+ * \return Non-zero on error.
+ * \since 12
+ */
+int stasis_config_init(void);
+
+struct ast_threadpool_options;
+
+/*!
+ * \internal
+ * \brief Retrieves the Stasis threadpool configuration.
+ * \param[out] threadpool_options Filled with Stasis threadpool options.
+ */
+void stasis_config_get_threadpool(
+	struct ast_threadpool_options *threadpool_options);
+
 /*! @} */
 
 /*!

Modified: team/dlee/stasis-config/main/asterisk.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-config/main/asterisk.c?view=diff&rev=393356&r1=393355&r2=393356
==============================================================================
--- team/dlee/stasis-config/main/asterisk.c (original)
+++ team/dlee/stasis-config/main/asterisk.c Mon Jul  1 16:00:00 2013
@@ -4202,6 +4202,13 @@
 		exit(1);
 	}
 
+#ifdef AST_XML_DOCS
+	/* Load XML documentation. */
+	ast_xmldoc_load_documentation();
+#endif
+
+	aco_init();
+
 	if (stasis_init()) {
 		printf("Stasis initialization failed.\n%s", term_quit());
 		exit(1);
@@ -4261,13 +4268,6 @@
 		exit(1);
 	}
 
-#ifdef AST_XML_DOCS
-	/* Load XML documentation. */
-	ast_xmldoc_load_documentation();
-#endif
-
-	aco_init();
-
 	if (app_init()) {
 		printf("App core initialization failed.\n%s", term_quit());
 		exit(1);

Modified: team/dlee/stasis-config/main/stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-config/main/stasis.c?view=diff&rev=393356&r1=393355&r2=393356
==============================================================================
--- team/dlee/stasis-config/main/stasis.c (original)
+++ team/dlee/stasis-config/main/stasis.c Mon Jul  1 16:00:00 2013
@@ -642,24 +642,25 @@
 {
 	int cache_init;
 
-	/* XXX Should this be configurable? */
-	struct ast_threadpool_options opts = {
-		.version = AST_THREADPOOL_OPTIONS_VERSION,
-		.idle_timeout = 20,
-		.auto_increment = 1,
-		.initial_size = 0,
-		.max_size = 200
-	};
+	struct ast_threadpool_options opts;
 
 	/* Be sure the types are cleaned up after the message bus */
 	ast_register_cleanup(stasis_cleanup);
 	ast_register_atexit(stasis_exit);
 
+	if (stasis_config_init() != 0) {
+		ast_log(LOG_ERROR, "Stasis configuration failed\n");
+		return -1;
+	}
+
 	if (pool) {
 		ast_log(LOG_ERROR, "Stasis double-initialized\n");
 		return -1;
 	}
 
+	stasis_config_get_threadpool(&opts);
+	ast_log(LOG_DEBUG, "Creating Stasis threadpool: initial_size = %d, max_size = %d, idle_timeout_secs = %d\n",
+		opts.initial_size, opts.max_size, opts.idle_timeout);
 	pool = ast_threadpool_create("stasis-core", NULL, &opts);
 	if (!pool) {
 		ast_log(LOG_ERROR, "Stasis threadpool allocation failed\n");

Added: team/dlee/stasis-config/main/stasis_config.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-config/main/stasis_config.c?view=auto&rev=393356
==============================================================================
--- team/dlee/stasis-config/main/stasis_config.c (added)
+++ team/dlee/stasis-config/main/stasis_config.c Mon Jul  1 16:00:00 2013
@@ -1,0 +1,194 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Stasis Message Bus configuration API.
+ *
+ * \author David M. Lee, II <dlee at digium.com>
+ */
+
+/*** MODULEINFO
+	<support_level>core</support_level>
+ ***/
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include "asterisk/config_options.h"
+#include "asterisk/stasis.h"
+#include "asterisk/threadpool.h"
+
+#include <limits.h>
+
+/*** DOCUMENTATION
+	<configInfo name="stasis" language="en_US">
+		<synopsis>Stasis message bus configuration.</synopsis>
+		<configFile name="stasis.conf">
+			<configObject name="threadpool">
+				<synopsis>Threadpool configuration.</synopsis>
+				<configOption name="initial_size" default="0">
+					<synopsis>Initial number of threads in the message bus threadpool.</synopsis>
+				</configOption>
+				<configOption name="idle_timeout_sec" default="20">
+					<synopsis>Number of seconds for an idle thread to be disposed of.</synopsis>
+				</configOption>
+				<configOption name="max_size" default="200">
+					<synopsis>Maximum number of threads in the threadpool.</synopsis>
+				</configOption>
+			</configObject>
+		</configFile>
+	</configInfo>
+ ***/
+
+/*! \brief Locking container for safe configuration access. */
+static AO2_GLOBAL_OBJ_STATIC(confs);
+
+struct stasis_threadpool_conf {
+	int initial_size;
+	int idle_timeout_sec;
+	int max_size;
+};
+
+struct stasis_conf {
+	struct stasis_threadpool_conf *threadpool;
+};
+
+/*! \brief Mapping of the stasis http conf struct's globals to the
+ *         threadpool context in the config file. */
+static struct aco_type threadpool_option = {
+        .type = ACO_GLOBAL,
+        .name = "threadpool",
+        .item_offset = offsetof(struct stasis_conf, threadpool),
+        .category = "^threadpool$",
+        .category_match = ACO_WHITELIST,
+};
+
+static struct aco_type *threadpool_options[] = ACO_TYPES(&threadpool_option);
+
+#define CONF_FILENAME "stasis.conf"
+
+/*! \brief The conf file that's processed for the module. */
+static struct aco_file conf_file = {
+        /*! The config file name. */
+        .filename = CONF_FILENAME,
+        /*! The mapping object types to be processed. */
+        .types = ACO_TYPES(&threadpool_option),
+};
+
+static void conf_dtor(void *obj)
+{
+	struct stasis_conf *conf = obj;
+
+	ao2_cleanup(conf->threadpool);
+	conf->threadpool = NULL;
+}
+
+static void *conf_alloc(void)
+{
+	RAII_VAR(struct stasis_conf *, conf, NULL, ao2_cleanup);
+
+	conf = ao2_alloc_options(sizeof(*conf), conf_dtor,
+		AO2_ALLOC_OPT_LOCK_NOLOCK);
+	if (!conf) {
+		return NULL;
+	}
+
+	conf->threadpool = ao2_alloc_options(sizeof(*conf->threadpool), NULL,
+		AO2_ALLOC_OPT_LOCK_NOLOCK);
+	if (!conf->threadpool) {
+		return NULL;
+	}
+
+	conf->threadpool->initial_size = 0;
+	conf->threadpool->idle_timeout_sec = 20;
+	conf->threadpool->max_size = 200;
+
+	ao2_ref(conf, +1);
+	return conf;
+}
+
+CONFIG_INFO_CORE("stasis", cfg_info, confs, conf_alloc,
+	.files = ACO_FILES(&conf_file));
+
+void stasis_config_get_threadpool(
+	struct ast_threadpool_options *threadpool_options)
+{
+	RAII_VAR(struct stasis_conf *, conf, NULL, ao2_cleanup);
+
+	conf = ao2_global_obj_ref(confs);
+
+	ast_assert(conf && conf->threadpool);
+
+	{
+		struct ast_threadpool_options newopts = {
+			.version = AST_THREADPOOL_OPTIONS_VERSION,
+			.initial_size = conf->threadpool->initial_size,
+			.auto_increment = 1,
+			.idle_timeout = conf->threadpool->idle_timeout_sec,
+			.max_size = conf->threadpool->max_size,
+		};
+
+		*threadpool_options = newopts;
+	}
+}
+
+/*! \brief Load (or reload) configuration. */
+static int process_config(int reload)
+{
+        switch (aco_process_config(&cfg_info, reload)) {
+        case ACO_PROCESS_ERROR:
+                return -1;
+        case ACO_PROCESS_OK:
+        case ACO_PROCESS_UNCHANGED:
+                break;
+        }
+
+	return 0;
+}
+
+static void config_exit(void)
+{
+	aco_info_destroy(&cfg_info);
+}
+
+int stasis_config_init(void)
+{
+	if (aco_info_init(&cfg_info)) {
+		aco_info_destroy(&cfg_info);
+		return -1;
+	}
+
+	ast_register_atexit(config_exit);
+
+	/* threadpool section */
+	aco_option_register(&cfg_info, "initial_size", ACO_EXACT,
+		threadpool_options, "0", OPT_INT_T, PARSE_IN_RANGE,
+		FLDSET(struct stasis_threadpool_conf, initial_size), 0,
+		INT_MAX);
+	aco_option_register(&cfg_info, "idle_timeout_sec", ACO_EXACT,
+		threadpool_options, "20", OPT_INT_T, PARSE_IN_RANGE,
+		FLDSET(struct stasis_threadpool_conf, idle_timeout_sec), 0,
+		INT_MAX);
+	aco_option_register(&cfg_info, "max_size", ACO_EXACT,
+		threadpool_options, "200", OPT_INT_T, PARSE_IN_RANGE,
+		FLDSET(struct stasis_threadpool_conf, max_size), 0, INT_MAX);
+
+	return process_config(0);
+}

Propchange: team/dlee/stasis-config/main/stasis_config.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/dlee/stasis-config/main/stasis_config.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/dlee/stasis-config/main/stasis_config.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list