Skip to content
Snippets Groups Projects
Commit f209bc6f authored by Mark Michelson's avatar Mark Michelson
Browse files

Change the default taskprocessor test so it will never hang forever.

Changes the ast_cond_wait() to an ast_cond_timedwait() so that
if there is an issue, we'll never wait forever for the task to
finish execution.



git-svn-id: https://origsvn.digium.com/svn/asterisk/team/mmichelson/threadpool@376411 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent ec68a156
No related branches found
No related tags found
No related merge requests found
......@@ -46,7 +46,7 @@ static int task(void *data)
{
struct task_data *task_data = data;
SCOPED_MUTEX(lock, &task_data->lock);
task_data->task_complete = 1;
++task_data->task_complete;
ast_cond_signal(&task_data->cond);
return 0;
}
......@@ -55,7 +55,10 @@ AST_TEST_DEFINE(default_taskprocessor)
{
struct ast_taskprocessor *tps;
struct task_data task_data;
struct timeval start;
struct timespec ts;
enum ast_test_result_state res = AST_TEST_PASS;
int timedwait_res;
switch (cmd) {
case TEST_INIT:
......@@ -76,6 +79,11 @@ AST_TEST_DEFINE(default_taskprocessor)
return AST_TEST_FAIL;
}
start = ast_tvnow();
ts.tv_sec = start.tv_sec + 30;
ts.tv_nsec = start.tv_usec * 1000;
ast_cond_init(&task_data.cond, NULL);
ast_mutex_init(&task_data.lock);
task_data.task_complete = 0;
......@@ -83,7 +91,10 @@ AST_TEST_DEFINE(default_taskprocessor)
ast_taskprocessor_push(tps, task, &task_data);
ast_mutex_lock(&task_data.lock);
while (!task_data.task_complete) {
ast_cond_wait(&task_data.cond, &task_data.lock);
timedwait_res = ast_cond_timedwait(&task_data.cond, &task_data.lock, &ts);
if (timedwait_res == ETIMEDOUT) {
break;
}
}
if (!task_data.task_complete) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment