mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-21 20:56:39 +00:00
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
This commit is contained in:
@@ -46,7 +46,7 @@ static int task(void *data)
|
|||||||
{
|
{
|
||||||
struct task_data *task_data = data;
|
struct task_data *task_data = data;
|
||||||
SCOPED_MUTEX(lock, &task_data->lock);
|
SCOPED_MUTEX(lock, &task_data->lock);
|
||||||
task_data->task_complete = 1;
|
++task_data->task_complete;
|
||||||
ast_cond_signal(&task_data->cond);
|
ast_cond_signal(&task_data->cond);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -55,7 +55,10 @@ AST_TEST_DEFINE(default_taskprocessor)
|
|||||||
{
|
{
|
||||||
struct ast_taskprocessor *tps;
|
struct ast_taskprocessor *tps;
|
||||||
struct task_data task_data;
|
struct task_data task_data;
|
||||||
|
struct timeval start;
|
||||||
|
struct timespec ts;
|
||||||
enum ast_test_result_state res = AST_TEST_PASS;
|
enum ast_test_result_state res = AST_TEST_PASS;
|
||||||
|
int timedwait_res;
|
||||||
|
|
||||||
switch (cmd) {
|
switch (cmd) {
|
||||||
case TEST_INIT:
|
case TEST_INIT:
|
||||||
@@ -76,6 +79,11 @@ AST_TEST_DEFINE(default_taskprocessor)
|
|||||||
return AST_TEST_FAIL;
|
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_cond_init(&task_data.cond, NULL);
|
||||||
ast_mutex_init(&task_data.lock);
|
ast_mutex_init(&task_data.lock);
|
||||||
task_data.task_complete = 0;
|
task_data.task_complete = 0;
|
||||||
@@ -83,7 +91,10 @@ AST_TEST_DEFINE(default_taskprocessor)
|
|||||||
ast_taskprocessor_push(tps, task, &task_data);
|
ast_taskprocessor_push(tps, task, &task_data);
|
||||||
ast_mutex_lock(&task_data.lock);
|
ast_mutex_lock(&task_data.lock);
|
||||||
while (!task_data.task_complete) {
|
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) {
|
if (!task_data.task_complete) {
|
||||||
|
Reference in New Issue
Block a user