[tip:tools/kvm] kvm tools: check condition before wait

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  1625b7c680fe5132657eeb5ddb9fb704ad74d6bb
Gitweb:     http://git.kernel.org/tip/1625b7c680fe5132657eeb5ddb9fb704ad74d6bb
Author:     Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
AuthorDate: Mon, 12 Dec 2011 15:15:45 +0800
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Mon, 12 Dec 2011 23:35:34 +0200

kvm tools: check condition before wait

We should check the condition before wait it,
otherewise we may get deadlock.

Signed-off-by: Lai Jiangshan <laijs@xxxxxxxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/threadpool.c |    7 +++----
 1 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/kvm/threadpool.c b/tools/kvm/threadpool.c
index fdc5fa7..2e59e62 100644
--- a/tools/kvm/threadpool.c
+++ b/tools/kvm/threadpool.c
@@ -80,12 +80,11 @@ static void *thread_pool__threadfunc(void *param)
 		struct thread_pool__job *curjob;
 
 		mutex_lock(&job_mutex);
-		pthread_cond_wait(&job_cond, &job_mutex);
-		curjob = thread_pool__job_pop();
+		while ((curjob = thread_pool__job_pop()) == NULL)
+			pthread_cond_wait(&job_cond, &job_mutex);
 		mutex_unlock(&job_mutex);
 
-		if (curjob)
-			thread_pool__handle_job(curjob);
+		thread_pool__handle_job(curjob);
 	}
 
 	pthread_cleanup_pop(0);
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux