Commit 30525aff78e9ee2099b24a3dc7534317ee130383
1 parent
8653c015
Avoid infinite loop around timed condition variable
This can happen due to spurious wakeups git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6631 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
1 changed file
with
7 additions
and
6 deletions
posix-aio-compat.c
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | #include <pthread.h> |
15 | 15 | #include <unistd.h> |
16 | 16 | #include <errno.h> |
17 | -#include <sys/time.h> | |
17 | +#include <time.h> | |
18 | 18 | #include <string.h> |
19 | 19 | #include <stdlib.h> |
20 | 20 | #include <stdio.h> |
... | ... | @@ -86,16 +86,17 @@ static void *aio_thread(void *unused) |
86 | 86 | struct qemu_paiocb *aiocb; |
87 | 87 | size_t offset; |
88 | 88 | int ret = 0; |
89 | + qemu_timeval tv; | |
90 | + struct timespec ts; | |
91 | + | |
92 | + qemu_gettimeofday(&tv); | |
93 | + ts.tv_sec = tv.tv_sec + 10; | |
94 | + ts.tv_nsec = 0; | |
89 | 95 | |
90 | 96 | mutex_lock(&lock); |
91 | 97 | |
92 | 98 | while (TAILQ_EMPTY(&request_list) && |
93 | 99 | !(ret == ETIMEDOUT)) { |
94 | - struct timespec ts = { 0 }; | |
95 | - qemu_timeval tv; | |
96 | - | |
97 | - qemu_gettimeofday(&tv); | |
98 | - ts.tv_sec = tv.tv_sec + 10; | |
99 | 100 | ret = cond_timedwait(&cond, &lock, &ts); |
100 | 101 | } |
101 | 102 | ... | ... |