[asterisk-commits] mmichelson: branch mmichelson/threadpool r376411 - /team/mmichelson/threadpoo...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Nov 17 15:49:04 CST 2012


Author: mmichelson
Date: Sat Nov 17 15:48:59 2012
New Revision: 376411

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=376411
Log:
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.


Modified:
    team/mmichelson/threadpool/tests/test_taskprocessor.c

Modified: team/mmichelson/threadpool/tests/test_taskprocessor.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/threadpool/tests/test_taskprocessor.c?view=diff&rev=376411&r1=376410&r2=376411
==============================================================================
--- team/mmichelson/threadpool/tests/test_taskprocessor.c (original)
+++ team/mmichelson/threadpool/tests/test_taskprocessor.c Sat Nov 17 15:48:59 2012
@@ -46,7 +46,7 @@
 {
 	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 @@
 {
 	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 @@
 		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_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) {




More information about the asterisk-commits mailing list