summaryrefslogtreecommitdiff
path: root/tests/test_taskprocessor.c
diff options
context:
space:
mode:
authorMark Michelson <mmichelson@digium.com>2013-01-15 18:40:36 +0000
committerMark Michelson <mmichelson@digium.com>2013-01-15 18:40:36 +0000
commit65c7d6e2c3d4fc3a161a31ff1e89d20256926fb1 (patch)
tree8076acfcfd024cdfa45aea20a5fa908e6af34651 /tests/test_taskprocessor.c
parentc80f86f007f6676f105a768be0ceedb3a8ec8298 (diff)
Remove alloc and destroy callbacks from the taskprocessor.
Now user data is allocated by the creator of the taskprocessor listener and that user data is passed into ast_taskprocessor_listener_alloc(). Similarly, freeing of the user data is left up to the user himself. He can free the data when the taskprocessor shuts down, or he can choose to hold onto it if it makes sense to do so. This, unsurprisingly, makes threadpool allocation a LOT cleaner now. git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@379120 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'tests/test_taskprocessor.c')
-rw-r--r--tests/test_taskprocessor.c41
1 files changed, 18 insertions, 23 deletions
diff --git a/tests/test_taskprocessor.c b/tests/test_taskprocessor.c
index 377a2b3e3..c04eeeb36 100644
--- a/tests/test_taskprocessor.c
+++ b/tests/test_taskprocessor.c
@@ -260,7 +260,7 @@ struct test_listener_pvt {
/*!
* \brief test taskprocessor listener's alloc callback
*/
-static void *test_alloc(struct ast_taskprocessor_listener *listener)
+static void *test_listener_pvt_alloc(void)
{
struct test_listener_pvt *pvt;
@@ -283,7 +283,7 @@ static int test_start(struct ast_taskprocessor_listener *listener)
*/
static void test_task_pushed(struct ast_taskprocessor_listener *listener, int was_empty)
{
- struct test_listener_pvt *pvt = listener->private_data;
+ struct test_listener_pvt *pvt = listener->user_data;
++pvt->num_pushed;
if (was_empty) {
++pvt->num_was_empty;
@@ -295,7 +295,7 @@ static void test_task_pushed(struct ast_taskprocessor_listener *listener, int wa
*/
static void test_emptied(struct ast_taskprocessor_listener *listener)
{
- struct test_listener_pvt *pvt = listener->private_data;
+ struct test_listener_pvt *pvt = listener->user_data;
++pvt->num_emptied;
}
@@ -304,26 +304,15 @@ static void test_emptied(struct ast_taskprocessor_listener *listener)
*/
static void test_shutdown(struct ast_taskprocessor_listener *listener)
{
- struct test_listener_pvt *pvt = listener->private_data;
+ struct test_listener_pvt *pvt = listener->user_data;
pvt->shutdown = 1;
}
-/*!
- * \brief test taskprocessor listener's destroy callback.
- */
-static void test_destroy(void *private_data)
-{
- struct test_listener_pvt *pvt = private_data;
- ast_free(pvt);
-}
-
static const struct ast_taskprocessor_listener_callbacks test_callbacks = {
- .alloc = test_alloc,
.start = test_start,
.task_pushed = test_task_pushed,
.emptied = test_emptied,
.shutdown = test_shutdown,
- .destroy = test_destroy,
};
/*!
@@ -381,9 +370,9 @@ static int check_stats(struct ast_test *test, const struct test_listener_pvt *pv
*/
AST_TEST_DEFINE(taskprocessor_listener)
{
- struct ast_taskprocessor *tps;
- struct ast_taskprocessor_listener *listener;
- struct test_listener_pvt *pvt;
+ struct ast_taskprocessor *tps = NULL;
+ struct ast_taskprocessor_listener *listener = NULL;
+ struct test_listener_pvt *pvt = NULL;
enum ast_test_result_state res = AST_TEST_PASS;
switch (cmd) {
@@ -398,10 +387,17 @@ AST_TEST_DEFINE(taskprocessor_listener)
break;
}
- listener = ast_taskprocessor_listener_alloc(&test_callbacks);
+ pvt = test_listener_pvt_alloc();
+ if (!pvt) {
+ ast_test_status_update(test, "Unable to allocate test taskprocessor listener user data\n");
+ return AST_TEST_FAIL;
+ }
+
+ listener = ast_taskprocessor_listener_alloc(&test_callbacks, pvt);
if (!listener) {
ast_test_status_update(test, "Unable to allocate test taskprocessor listener\n");
- return AST_TEST_FAIL;
+ res = AST_TEST_FAIL;
+ goto test_exit;
}
tps = ast_taskprocessor_create_with_listener("test_listener", listener);
@@ -411,8 +407,6 @@ AST_TEST_DEFINE(taskprocessor_listener)
goto test_exit;
}
- pvt = listener->private_data;
-
ast_taskprocessor_push(tps, listener_test_task, NULL);
if (check_stats(test, pvt, 1, 0, 1) < 0) {
@@ -449,9 +443,10 @@ AST_TEST_DEFINE(taskprocessor_listener)
}
test_exit:
- ao2_ref(listener, -1);
+ ao2_cleanup(listener);
/* This is safe even if tps is NULL */
ast_taskprocessor_unreference(tps);
+ ast_free(pvt);
return res;
}