diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2022-02-21 12:46:32 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2022-04-06 14:31:56 +0200 |
commit | 8ab3026489eafa9da07c09f1929593fe0db5e380 (patch) | |
tree | 8bfe3578de68aeea179e7a5878c71501d2ed298c /util | |
parent | a0d45db85496c195ab5f3f2ced742fc93d9709c2 (diff) |
thread-posix: optimize qemu_sem_timedwait with zero timeout
In this case there is no need to call pthread_cond_timedwait; the
function is just a trywait and waiting on the condition variable would
always time out.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'util')
-rw-r--r-- | util/qemu-thread-posix.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 8505d8c60f..ac1d56e673 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -284,8 +284,12 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms) compute_abs_deadline(&ts, ms); qemu_mutex_lock(&sem->mutex); while (sem->count == 0) { - rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts, - __FILE__, __LINE__); + if (ms == 0) { + rc = false; + } else { + rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts, + __FILE__, __LINE__); + } if (!rc) { /* timeout */ break; } |