thread-posix: optimize qemu_sem_timedwait with zero timeout
PATCH 1/1 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.
Based-on: <[email protected]>
--- util/qemu-thread-posix.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
util/qemu-thread-posix.c +6 -2
@@ -282,8 +282,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 ; }
Signature · 1 line
2.34.1
Quoted 41 lines
-----Original Message-----
From: Paolo Bonzini [mailto:[email protected]] On Behalf Of Paolo Bonzini
Sent: Wednesday, February 23, 2022 4:36 PM
To: [email protected]
Cc: Longpeng (Mike, Cloud Infrastructure Service Product Dept.) <[email protected]>
Subject: [PATCH] thread-posix: optimizeqemu_sem_timedwaitwith zero timeoutIn 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.Based-on: <[email protected]>
Cc "Longpeng(Mike)" <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-thread-posix.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)util/qemu-thread-posix.c +6
-3@@ -282,8 +282,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 ; } --
Quoted 1 line
2.34.1
Thanks.
Quoted 5 lines · Paolo Bonzini
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.Based-on: <[email protected]>
^ Please remove when applying.
Quoted 5 lines
Cc "Longpeng(Mike)" <[email protected]>Signed-off-by Paolo Bonzini <[email protected]>--- util/qemu-thread-posix.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)