2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 2012, Digium, Inc.
6 * Mark Michelson <mmmichelson@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 #ifndef _ASTERISK_THREADPOOL_H
21 #define _ASTERISK_THREADPOOL_H
23 struct ast_threadpool;
24 struct ast_taskprocessor;
25 struct ast_threadpool_listener;
27 struct ast_threadpool_listener_callbacks {
29 * \brief Indicates that the state of threads in the pool has changed
31 * \param listener The threadpool listener
32 * \param active_threads The number of active threads in the pool
33 * \param idle_threads The number of idle threads in the pool
34 * \param zombie_threads The number of zombie threads in the pool
36 void (*state_changed)(struct ast_threadpool_listener *listener,
41 * \brief Indicates that a task was pushed to the threadpool's taskprocessor
43 * \param listener The threadpool listener
44 * \param was_empty Indicates whether the taskprocessor was empty prior to adding the task
46 void (*tps_task_pushed)(struct ast_threadpool_listener *listener,
49 * \brief Indicates the threadpoo's taskprocessor has become empty
51 * \param listener The threadpool's listener
53 void (*emptied)(struct ast_threadpool_listener *listener);
57 * \brief listener for a threadpool
59 * The listener is notified of changes in a threadpool. It can
60 * react by doing things like increasing the number of threads
63 struct ast_threadpool_listener {
64 /*! Callbacks called by the threadpool */
65 struct ast_threadpool_listener_callbacks *callbacks;
66 /*! Handle to the threadpool */
67 struct ast_threadpool *threadpool;
68 /*! User data for the listener */
73 * \brief Create a new threadpool
75 * This function creates a threadpool and returns a taskprocessor. Tasks pushed
76 * to this taskprocessor will be handled by the threadpool and will be reported
77 * on the threadpool's listener.
79 * \param listener The listener the threadpool will notify of changes
80 * \retval NULL Failed to create the threadpool
81 * \retval non-NULL The associated taskprocessor
83 struct ast_threadpool *ast_threadpool_create(struct ast_threadpool_listener *listener);
86 * \brief Set the number of threads for the thread pool
88 * This number may be more or less than the current number of
89 * threads in the threadpool.
91 * \param threadpool The threadpool to adjust
92 * \param size The new desired size of the threadpool
94 void ast_threadpool_set_size(struct ast_threadpool *threadpool, unsigned int size);
96 #endif /* ASTERISK_THREADPOOL_H */