summaryrefslogtreecommitdiffstats
path: root/include/qemu/thread-posix.h
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2013-09-25 14:20:59 +0800
committerPaolo Bonzini <pbonzini@redhat.com>2013-10-17 17:30:55 +0200
commitc7c4d063f50f0de980d99f02e055722227d703bc (patch)
tree8ddfd7aa65bfb93a1c77d1edfa0f4c5576cad52e /include/qemu/thread-posix.h
parentcb365646a942ed58aae053064b2048a415337ba2 (diff)
downloadhqemu-c7c4d063f50f0de980d99f02e055722227d703bc.zip
hqemu-c7c4d063f50f0de980d99f02e055722227d703bc.tar.gz
qemu-thread: add QemuEvent
This emulates Win32 manual-reset events using futexes or conditional variables. Typical ways to use them are with multi-producer, single-consumer data structures, to test for a complex condition whose elements come from different threads: for (;;) { qemu_event_reset(ev); ... test complex condition ... if (condition is true) { break; } qemu_event_wait(ev); } Or more efficiently (but with some duplication): ... evaluate condition ... while (!condition) { qemu_event_reset(ev); ... evaluate condition ... if (!condition) { qemu_event_wait(ev); ... evaluate condition ... } } QemuEvent provides a very fast userspace path in the common case when no other thread is waiting, or the event is not changing state. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'include/qemu/thread-posix.h')
-rw-r--r--include/qemu/thread-posix.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h
index 361566a..eb5c7a1 100644
--- a/include/qemu/thread-posix.h
+++ b/include/qemu/thread-posix.h
@@ -21,6 +21,14 @@ struct QemuSemaphore {
#endif
};
+struct QemuEvent {
+#ifndef __linux__
+ pthread_mutex_t lock;
+ pthread_cond_t cond;
+#endif
+ unsigned value;
+};
+
struct QemuThread {
pthread_t thread;
};
OpenPOWER on IntegriCloud