mirror of
https://gitlab.com/qemu-project/qemu
synced 2024-10-15 07:22:46 +00:00
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>
This commit is contained in:
parent
a0d45db854
commit
8ab3026489
|
@ -284,8 +284,12 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
|
||||||
compute_abs_deadline(&ts, ms);
|
compute_abs_deadline(&ts, ms);
|
||||||
qemu_mutex_lock(&sem->mutex);
|
qemu_mutex_lock(&sem->mutex);
|
||||||
while (sem->count == 0) {
|
while (sem->count == 0) {
|
||||||
rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
|
if (ms == 0) {
|
||||||
__FILE__, __LINE__);
|
rc = false;
|
||||||
|
} else {
|
||||||
|
rc = qemu_cond_timedwait_ts(&sem->cond, &sem->mutex, &ts,
|
||||||
|
__FILE__, __LINE__);
|
||||||
|
}
|
||||||
if (!rc) { /* timeout */
|
if (!rc) { /* timeout */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue