From: Jan Kiszka <jan.kiszka@web.de>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: Anthony Liguori <aliguori@us.ibm.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH v2 2/6] Introduce qemu_cond_timedwait for POSIX
Date: Tue, 20 Sep 2011 21:02:41 +0200 [thread overview]
Message-ID: <4E78E351.3070408@web.de> (raw)
In-Reply-To: <4E78DA03.3040809@redhat.com>
On 2011-09-20 20:22, Paolo Bonzini wrote:
> On 09/20/2011 06:53 PM, Jan Kiszka wrote:
>> First user will be posix compat aio.
>>
>> Signed-off-by: Jan Kiszka<jan.kiszka@siemens.com>
>
> I'm pretty sure the win32 version is not thread-safe,
Yeah, I would even say it's completely broken. Was a naive hack.
> but posix compat
> aio is currently POSIX only. Just leave it out.
>
-------8<-------
From: Jan Kiszka <jan.kiszka@siemens.com>
First user will be POSIX compat aio. Windows use cases aren't in sight,
so this remains a POSIX-only service for now.
Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
---
qemu-thread-posix.c | 22 ++++++++++++++++++++++
qemu-thread-posix.h | 2 ++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index f76427e..1d970fb 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -17,6 +17,7 @@
#include <signal.h>
#include <stdint.h>
#include <string.h>
+#include <sys/time.h>
#include "qemu-thread.h"
static void error_exit(int err, const char *msg)
@@ -115,6 +116,27 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex)
error_exit(err, __func__);
}
+int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex,
+ unsigned int timeout_ms)
+{
+ struct timespec ts;
+ struct timeval tv;
+ int err;
+
+ gettimeofday(&tv, NULL);
+ ts.tv_sec = tv.tv_sec + timeout_ms / 1000;
+ ts.tv_nsec = tv.tv_usec * 1000 + timeout_ms % 1000;
+ if (ts.tv_nsec > 1000000000) {
+ ts.tv_sec++;
+ ts.tv_nsec -= 1000000000;
+ }
+ err = pthread_cond_timedwait(&cond->cond, &mutex->lock, &ts);
+ if (err && err != ETIMEDOUT) {
+ error_exit(err, __func__);
+ }
+ return err == 0;
+}
+
void qemu_thread_create(QemuThread *thread,
void *(*start_routine)(void*),
void *arg, int mode)
diff --git a/qemu-thread-posix.h b/qemu-thread-posix.h
index 540fa0b..b4ae5ad 100644
--- a/qemu-thread-posix.h
+++ b/qemu-thread-posix.h
@@ -16,5 +16,7 @@ struct QemuThread {
/* only provided for posix so far */
void qemu_thread_join(QemuThread *thread);
+int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex,
+ unsigned int timeout_ms);
#endif
next prev parent reply other threads:[~2011-09-20 19:03 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-20 16:53 [Qemu-devel] [PATCH 0/6] Spread the use of QEMU threading & locking API Jan Kiszka
2011-09-20 16:53 ` [Qemu-devel] [PATCH 1/6] Enable joinable POSIX threads Jan Kiszka
2011-09-21 7:16 ` Paolo Bonzini
2011-09-21 13:40 ` Kevin Wolf
2011-09-21 13:38 ` Paolo Bonzini
2011-09-20 16:53 ` [Qemu-devel] [PATCH 2/6] Introduce qemu_cond_timedwait Jan Kiszka
2011-09-20 18:22 ` Paolo Bonzini
2011-09-20 19:02 ` Jan Kiszka [this message]
2011-09-20 16:53 ` [Qemu-devel] [PATCH 3/6] Switch POSIX compat AIO to QEMU abstractions Jan Kiszka
2011-09-21 13:57 ` Kevin Wolf
2011-09-21 14:02 ` Jan Kiszka
2011-09-21 14:11 ` Kevin Wolf
2011-09-20 16:53 ` [Qemu-devel] [PATCH 4/6] Switch compatfd to QEMU thread Jan Kiszka
2011-09-20 16:53 ` [Qemu-devel] [PATCH 5/6] audio: Use QEMU threads & synchronization Jan Kiszka
2011-09-20 16:53 ` [Qemu-devel] [PATCH 6/6] audio: Switch coreaudio to QemuMutex Jan Kiszka
2011-09-26 7:58 ` Andreas Färber
2011-09-26 8:06 ` Jan Kiszka
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=4E78E351.3070408@web.de \
--to=jan.kiszka@web.de \
--cc=aliguori@us.ibm.com \
--cc=pbonzini@redhat.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).