From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Longpeng\(Mike\)" <longpeng2@huawei.com>
Subject: [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout
Date: Wed, 23 Feb 2022 09:36:28 +0100 [thread overview]
Message-ID: <20220223083628.231589-1-pbonzini@redhat.com> (raw)
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: <20220222090507.2028-1-longpeng2@huawei.com>
Cc: "Longpeng(Mike)" <longpeng2@huawei.com>
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 f2ce47d36b..89c23f1d64 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -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;
}
--
2.34.1
next reply other threads:[~2022-02-23 8:41 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 8:36 Paolo Bonzini [this message]
2022-02-23 10:27 ` [PATCH] thread-posix: optimize qemu_sem_timedwait with zero timeout longpeng2--- via
2022-02-23 10:44 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220223083628.231589-1-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=longpeng2@huawei.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).