aboutsummaryrefslogtreecommitdiff
path: root/qemu-thread-win32.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2011-08-08 14:36:41 +0200
committerPaolo Bonzini <pbonzini@redhat.com>2012-10-31 09:45:47 +0100
commit38b14db34e16bb0ae1f28b7ddccb6aa11a2a96a1 (patch)
tree13bfc5fc9a8c4f2a348a4ce61c57f1493f12c166 /qemu-thread-win32.c
parentc90caf25e2b6945ae13560476a5ecd7992e9f945 (diff)
qemu-thread: add QemuSemaphore
The new thread pool will use semaphores instead of condition variables, because QemuCond does not have qemu_cond_timedwait. (I also like it more this way). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'qemu-thread-win32.c')
-rw-r--r--qemu-thread-win32.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/qemu-thread-win32.c b/qemu-thread-win32.c
index 177b398cc4..4b3db60f5c 100644
--- a/qemu-thread-win32.c
+++ b/qemu-thread-win32.c
@@ -192,6 +192,41 @@ void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex)
qemu_mutex_lock(mutex);
}
+void qemu_sem_init(QemuSemaphore *sem, int init)
+{
+ /* Manual reset. */
+ sem->sema = CreateSemaphore(NULL, init, LONG_MAX, NULL);
+}
+
+void qemu_sem_destroy(QemuSemaphore *sem)
+{
+ CloseHandle(sem->sema);
+}
+
+void qemu_sem_post(QemuSemaphore *sem)
+{
+ ReleaseSemaphore(sem->sema, 1, NULL);
+}
+
+int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
+{
+ int rc = WaitForSingleObject(sem->sema, ms);
+ if (rc == WAIT_OBJECT_0) {
+ return 0;
+ }
+ if (rc != WAIT_TIMEOUT) {
+ error_exit(GetLastError(), __func__);
+ }
+ return -1;
+}
+
+void qemu_sem_wait(QemuSemaphore *sem)
+{
+ if (WaitForSingleObject(sem->sema, INFINITE) != WAIT_OBJECT_0) {
+ error_exit(GetLastError(), __func__);
+ }
+}
+
struct QemuThreadData {
/* Passed to win32_start_routine. */
void *(*start_routine)(void *);