return AST_TEST_FAIL;
}
- ast_taskprocessor_push(tps, task, task_data);
+ if (ast_taskprocessor_push(tps, task, task_data)) {
+ ast_test_status_update(test, "Failed to queue task\n");
+ return AST_TEST_FAIL;
+ }
res = task_wait(task_data);
if (res != 0) {
for (i = 0; i < NUM_TASKS; ++i) {
rand_data[i] = ast_random();
- ast_taskprocessor_push(tps, load_task, &rand_data[i]);
+ if (ast_taskprocessor_push(tps, load_task, &rand_data[i])) {
+ ast_test_status_update(test, "Failed to queue task\n");
+ res = AST_TEST_FAIL;
+ goto test_end;
+ }
}
ast_mutex_lock(&load_task_results.lock);
goto test_exit;
}
- ast_taskprocessor_push(tps, listener_test_task, NULL);
+ if (ast_taskprocessor_push(tps, listener_test_task, NULL)) {
+ ast_test_status_update(test, "Failed to queue task\n");
+ res = AST_TEST_FAIL;
+ goto test_exit;
+ }
if (check_stats(test, pvt, 1, 0, 1) < 0) {
res = AST_TEST_FAIL;
goto test_exit;
}
- ast_taskprocessor_push(tps, listener_test_task, NULL);
+ if (ast_taskprocessor_push(tps, listener_test_task, NULL)) {
+ ast_test_status_update(test, "Failed to queue task\n");
+ res = AST_TEST_FAIL;
+ goto test_exit;
+ }
if (check_stats(test, pvt, 2, 0, 1) < 0) {
res = AST_TEST_FAIL;
local_data = 0;
ast_taskprocessor_set_local(tps, &local_data);
- ast_taskprocessor_push_local(tps, local_task_exe, task_data);
+ if (ast_taskprocessor_push_local(tps, local_task_exe, task_data)) {
+ ast_test_status_update(test, "Failed to queue task\n");
+ return AST_TEST_FAIL;
+ }
res = task_wait(task_data);
if (res != 0) {
return std;
}
+static void simple_task_data_free(struct simple_task_data *std)
+{
+ if (!std) {
+ return;
+ }
+
+ ast_mutex_destroy(&std->lock);
+ ast_cond_destroy(&std->cond);
+
+ ast_free(std);
+}
+
static int simple_task(void *data)
{
struct simple_task_data *std = data;
goto end;
}
- ast_threadpool_push(pool, simple_task, std);
+ if (ast_threadpool_push(pool, simple_task, std)) {
+ goto end;
+ }
wait_for_task_pushed(listener);
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std);
+ simple_task_data_free(std);
ast_free(tld);
return res;
}
}
ast_mutex_unlock(&tld->lock);
- ast_threadpool_push(pool, simple_task, std);
-
- res = wait_for_completion(test, std);
+ if (ast_threadpool_push(pool, simple_task, std)) {
+ res = AST_TEST_FAIL;
+ } else {
+ res = wait_for_completion(test, std);
+ }
- ast_free(std);
+ simple_task_data_free(std);
if (res == AST_TEST_FAIL) {
goto end;
goto end;
}
- ast_threadpool_push(pool, simple_task, std);
+ if (ast_threadpool_push(pool, simple_task, std)) {
+ goto end;
+ }
ast_threadpool_set_size(pool, 1);
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std);
+ simple_task_data_free(std);
ast_free(tld);
return res;
goto end;
}
- ast_threadpool_push(pool, simple_task, std);
+ if (ast_threadpool_push(pool, simple_task, std)) {
+ res = AST_TEST_FAIL;
+ goto end;
+ }
res = wait_for_completion(test, std);
if (res == AST_TEST_FAIL) {
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std);
+ simple_task_data_free(std);
ast_free(tld);
return res;
}
goto end;
}
- ast_threadpool_push(pool, simple_task, std1);
- ast_threadpool_push(pool, simple_task, std2);
- ast_threadpool_push(pool, simple_task, std3);
+ res = AST_TEST_FAIL;
+ if (ast_threadpool_push(pool, simple_task, std1)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, simple_task, std2)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, simple_task, std3)) {
+ goto end;
+ }
res = wait_for_completion(test, std1);
if (res == AST_TEST_FAIL) {
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std1);
- ast_free(std2);
- ast_free(std3);
+ simple_task_data_free(std1);
+ simple_task_data_free(std2);
+ simple_task_data_free(std3);
ast_free(tld);
return res;
}
goto end;
}
- ast_threadpool_push(pool, simple_task, std1);
+ if (ast_threadpool_push(pool, simple_task, std1)) {
+ goto end;
+ }
/* Pushing the task should result in the threadpool growing
* by three threads. This will allow the task to actually execute
/* Now push three tasks into the pool and ensure the pool does not
* grow.
*/
- ast_threadpool_push(pool, simple_task, std2);
- ast_threadpool_push(pool, simple_task, std3);
- ast_threadpool_push(pool, simple_task, std4);
+ res = AST_TEST_FAIL;
+
+ if (ast_threadpool_push(pool, simple_task, std2)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, simple_task, std3)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, simple_task, std4)) {
+ goto end;
+ }
res = wait_for_completion(test, std2);
if (res == AST_TEST_FAIL) {
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std1);
- ast_free(std2);
- ast_free(std3);
- ast_free(std4);
+ simple_task_data_free(std1);
+ simple_task_data_free(std2);
+ simple_task_data_free(std3);
+ simple_task_data_free(std4);
ast_free(tld);
return res;
}
goto end;
}
- ast_threadpool_push(pool, simple_task, std);
+ if (ast_threadpool_push(pool, simple_task, std)) {
+ goto end;
+ }
res = wait_for_completion(test, std);
if (res == AST_TEST_FAIL) {
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std);
+ simple_task_data_free(std);
ast_free(tld);
return res;
}
goto end;
}
- ast_threadpool_push(pool, simple_task, std1);
+ if (ast_threadpool_push(pool, simple_task, std1)) {
+ goto end;
+ }
ast_threadpool_set_size(pool, 1);
}
/* Now make sure the threadpool reactivates when we add a second task */
- ast_threadpool_push(pool, simple_task, std2);
+ if (ast_threadpool_push(pool, simple_task, std2)) {
+ res = AST_TEST_FAIL;
+ goto end;
+ }
res = wait_for_completion(test, std2);
if (res == AST_TEST_FAIL) {
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(std1);
- ast_free(std2);
+ simple_task_data_free(std1);
+ simple_task_data_free(std2);
ast_free(tld);
return res;
return ctd;
}
+static void complex_task_data_free(struct complex_task_data *ctd)
+{
+ if (!ctd) {
+ return;
+ }
+
+ ast_mutex_destroy(&ctd->lock);
+ ast_cond_destroy(&ctd->stall_cond);
+ ast_cond_destroy(&ctd->notify_cond);
+
+ ast_free(ctd);
+}
+
static int complex_task(void *data)
{
struct complex_task_data *ctd = data;
goto end;
}
- ast_threadpool_push(pool, complex_task, ctd1);
- ast_threadpool_push(pool, complex_task, ctd2);
+ if (ast_threadpool_push(pool, complex_task, ctd1)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, complex_task, ctd2)) {
+ goto end;
+ }
ast_threadpool_set_size(pool, 2);
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(ctd1);
- ast_free(ctd2);
+ complex_task_data_free(ctd1);
+ complex_task_data_free(ctd2);
ast_free(tld);
return res;
}
goto end;
}
- ast_threadpool_push(pool, complex_task, ctd1);
- ast_threadpool_push(pool, complex_task, ctd2);
+ if (ast_threadpool_push(pool, complex_task, ctd1)) {
+ goto end;
+ }
+
+ if (ast_threadpool_push(pool, complex_task, ctd2)) {
+ goto end;
+ }
ast_threadpool_set_size(pool, 4);
end:
ast_threadpool_shutdown(pool);
ao2_cleanup(listener);
- ast_free(ctd1);
- ast_free(ctd2);
+ complex_task_data_free(ctd1);
+ complex_task_data_free(ctd2);
ast_free(tld);
return res;
}
poke_worker(data3);
ast_taskprocessor_unreference(uut);
ast_threadpool_shutdown(pool);
- ast_free(data1);
- ast_free(data2);
- ast_free(data3);
+ complex_task_data_free(data1);
+ complex_task_data_free(data2);
+ complex_task_data_free(data3);
return res;
}