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>
Showing
- include/qemu/thread-posix.h 8 additions, 0 deletionsinclude/qemu/thread-posix.h
- include/qemu/thread-win32.h 4 additions, 0 deletionsinclude/qemu/thread-win32.h
- include/qemu/thread.h 7 additions, 0 deletionsinclude/qemu/thread.h
- util/qemu-thread-posix.c 116 additions, 0 deletionsutil/qemu-thread-posix.c
- util/qemu-thread-win32.c 26 additions, 0 deletionsutil/qemu-thread-win32.c
Please register or sign in to comment