]> git.ipfire.org Git - thirdparty/qemu.git/commitdiff
thread-posix: optimize qemu_sem_timedwait with zero timeout
authorPaolo Bonzini <pbonzini@redhat.com>
Mon, 21 Feb 2022 11:46:32 +0000 (12:46 +0100)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 6 Apr 2022 12:31:56 +0000 (14:31 +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

index 8505d8c60f073359dfadf60df1c2a81f224eaee4..ac1d56e673f37e45cb870ec5cc6c182d68ec24ea 100644 (file)
@@ -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;
         }