summaryrefslogtreecommitdiff
path: root/main/threadpool.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2012-12-04 23:45:39 +0000
committerMark Michelson <mmichelson@digium.com>2012-12-04 23:45:39 +0000
commitcc63d2c380906e3f85a6c6c2a58f44caee2d19cb (patch)
tree50b1b419ca3819ff5f29068b1908247bd3dcc0b8 /main/threadpool.c
parent4acb2070f21883d1da40322df6b5d18fd727f5a6 (diff)
Add better listener support.
Add some parameters to listener callbacks. Add alloc and destroy callbacks for listeners. Add public function for allocating a listener. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@377226 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/threadpool.c')
-rw-r--r--main/threadpool.c34
1 files changed, 26 insertions, 8 deletions
diff --git a/main/threadpool.c b/main/threadpool.c
index 1f1812a64..8662c3a39 100644
--- a/main/threadpool.c
+++ b/main/threadpool.c
@@ -123,7 +123,7 @@ static void threadpool_send_state_changed(struct ast_threadpool *pool)
int active_size = ao2_container_count(pool->active_threads);
int idle_size = ao2_container_count(pool->idle_threads);
- pool->listener->callbacks->state_changed(pool->listener, active_size, idle_size);
+ pool->listener->callbacks->state_changed(pool, pool->listener, active_size, idle_size);
}
/*!
@@ -232,11 +232,6 @@ static int threadpool_execute(struct ast_threadpool *pool)
static void threadpool_destructor(void *obj)
{
struct ast_threadpool *pool = obj;
- /* XXX Probably should let the listener know we're being destroyed? */
-
- /* Threads should all be shut down by now, so this should be a painless
- * operation
- */
ao2_cleanup(pool->listener);
}
@@ -342,7 +337,7 @@ static int handle_task_pushed(void *data)
struct ast_threadpool *pool = tpd->pool;
int was_empty = tpd->was_empty;
- pool->listener->callbacks->tps_task_pushed(pool->listener, was_empty);
+ pool->listener->callbacks->task_pushed(pool, pool->listener, was_empty);
ao2_callback(pool->idle_threads, OBJ_UNLINK | OBJ_NOLOCK | OBJ_NODATA | OBJ_MULTIPLE,
activate_threads, pool);
ao2_ref(tpd, -1);
@@ -382,7 +377,7 @@ static int handle_emptied(void *data)
{
struct ast_threadpool *pool = data;
- pool->listener->callbacks->emptied(pool->listener);
+ pool->listener->callbacks->emptied(pool, pool->listener);
return 0;
}
@@ -587,6 +582,29 @@ void ast_threadpool_set_size(struct ast_threadpool *pool, unsigned int size)
ast_taskprocessor_push(pool->control_tps, queued_set_size, ssd);
}
+static void listener_destructor(void *obj)
+{
+ struct ast_threadpool_listener *listener = obj;
+
+ listener->callbacks->destroy(listener->private_data);
+}
+
+struct ast_threadpool_listener *ast_threadpool_listener_alloc(
+ const struct ast_threadpool_listener_callbacks *callbacks)
+{
+ struct ast_threadpool_listener *listener = ao2_alloc(sizeof(*listener), listener_destructor);
+ if (!listener) {
+ return NULL;
+ }
+ listener->callbacks = callbacks;
+ listener->private_data = listener->callbacks->alloc(listener);
+ if (!listener->private_data) {
+ ao2_ref(listener, -1);
+ return NULL;
+ }
+ return listener;
+}
+
struct ast_threadpool *ast_threadpool_create(struct ast_threadpool_listener *listener, int initial_size)
{
struct ast_threadpool *pool;