[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 43/53] thread-posix: optimize qemu_sem_timedwait with zero timeout
From: |
Paolo Bonzini |
Subject: |
[PULL 43/53] thread-posix: optimize qemu_sem_timedwait with zero timeout |
Date: |
Tue, 19 Apr 2022 07:50:59 +0200 |
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>
---
util/qemu-thread-posix.c | 8 ++++++--
1 file 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;
}
--
2.35.1
- [PULL 34/53] Move fcntl_setfl() to oslib-posix, (continued)
- [PULL 34/53] Move fcntl_setfl() to oslib-posix, Paolo Bonzini, 2022/04/19
- [PULL 35/53] qga: remove explicit environ argument from exec/spawn, Paolo Bonzini, 2022/04/19
- [PULL 28/53] include: move target page bits declaration to page-vary.h, Paolo Bonzini, 2022/04/19
- [PULL 29/53] include: move progress API to qemu-progress.h, Paolo Bonzini, 2022/04/19
- [PULL 45/53] hyperv: Add definitions for syndbg, Paolo Bonzini, 2022/04/19
- [PULL 46/53] hyperv: Add support to process syndbg commands, Paolo Bonzini, 2022/04/19
- [PULL 36/53] Remove qemu-common.h include from most units, Paolo Bonzini, 2022/04/19
- [PULL 48/53] s390x: follow qdev tree to detect SCSI device on a CCW bus, Paolo Bonzini, 2022/04/19
- [PULL 22/53] include: move qemu_write_full() declaration to osdep.h, Paolo Bonzini, 2022/04/19
- [PULL 18/53] error-report: replace deprecated g_get_current_time() with glib >= 2.62, Paolo Bonzini, 2022/04/19
- [PULL 43/53] thread-posix: optimize qemu_sem_timedwait with zero timeout,
Paolo Bonzini <=
- [PULL 50/53] virtio-ccw: move device type declarations to .c files, Paolo Bonzini, 2022/04/19
- [PULL 53/53] target/i386: Remove unused XMMReg, YMMReg types and CPUState fields, Paolo Bonzini, 2022/04/19
- [PULL 25/53] include: move dump_in_progress() to runstate.h, Paolo Bonzini, 2022/04/19
- [PULL 26/53] include: move C/util-related declarations to cutils.h, Paolo Bonzini, 2022/04/19
- [PULL 32/53] include: move page_size_init() to include/hw/core/cpu.h, Paolo Bonzini, 2022/04/19
- [PULL 42/53] thread-posix: implement Semaphore with QemuCond and QemuMutex, Paolo Bonzini, 2022/04/19
- [PULL 39/53] whpx: Added support for breakpoints and stepping, Paolo Bonzini, 2022/04/19
- [PULL 47/53] hw: hyperv: Initial commit for Synthetic Debugging device, Paolo Bonzini, 2022/04/19
- [PULL 49/53] virtio-ccw: move vhost_ccw_scsi to a separate file, Paolo Bonzini, 2022/04/19
- [PULL 51/53] virtio-ccw: do not include headers for all virtio devices, Paolo Bonzini, 2022/04/19