blob: 05fdaaf50e4209ad62ea216a6c1e39ab86f0fdb6 [file] [log] [blame]
aliguorie5d355d2009-04-24 18:03:15 +00001#ifndef __QEMU_THREAD_H
2#define __QEMU_THREAD_H 1
aliguorie5d355d2009-04-24 18:03:15 +00003
Alon Levy65097422011-03-15 00:18:02 +02004#include <inttypes.h>
Andreas Färber2d797b62012-05-02 17:21:31 +02005#include <stdbool.h>
Alon Levy65097422011-03-15 00:18:02 +02006
aliguorie5d355d2009-04-24 18:03:15 +00007typedef struct QemuMutex QemuMutex;
8typedef struct QemuCond QemuCond;
9typedef struct QemuThread QemuThread;
10
Paolo Bonzini9257d462011-03-12 17:43:52 +010011#ifdef _WIN32
12#include "qemu-thread-win32.h"
13#else
14#include "qemu-thread-posix.h"
15#endif
16
Jan Kiszkacf218712011-12-12 17:21:31 +010017#define QEMU_THREAD_JOINABLE 0
18#define QEMU_THREAD_DETACHED 1
19
aliguorie5d355d2009-04-24 18:03:15 +000020void qemu_mutex_init(QemuMutex *mutex);
Corentin Chary313b1d62010-07-07 20:58:01 +020021void qemu_mutex_destroy(QemuMutex *mutex);
aliguorie5d355d2009-04-24 18:03:15 +000022void qemu_mutex_lock(QemuMutex *mutex);
23int qemu_mutex_trylock(QemuMutex *mutex);
aliguorie5d355d2009-04-24 18:03:15 +000024void qemu_mutex_unlock(QemuMutex *mutex);
25
Harsh Prateek Bora5f7d05e2011-10-25 12:10:40 +053026#define rcu_read_lock() do { } while (0)
27#define rcu_read_unlock() do { } while (0)
28
aliguorie5d355d2009-04-24 18:03:15 +000029void qemu_cond_init(QemuCond *cond);
Corentin Chary313b1d62010-07-07 20:58:01 +020030void qemu_cond_destroy(QemuCond *cond);
Paolo Bonzini9257d462011-03-12 17:43:52 +010031
32/*
33 * IMPORTANT: The implementation does not guarantee that pthread_cond_signal
34 * and pthread_cond_broadcast can be called except while the same mutex is
35 * held as in the corresponding pthread_cond_wait calls!
36 */
aliguorie5d355d2009-04-24 18:03:15 +000037void qemu_cond_signal(QemuCond *cond);
38void qemu_cond_broadcast(QemuCond *cond);
39void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex);
aliguorie5d355d2009-04-24 18:03:15 +000040
41void qemu_thread_create(QemuThread *thread,
Jan Kiszkacf218712011-12-12 17:21:31 +010042 void *(*start_routine)(void *),
43 void *arg, int mode);
44void *qemu_thread_join(QemuThread *thread);
Jan Kiszkab7680cb2011-03-12 17:43:51 +010045void qemu_thread_get_self(QemuThread *thread);
Andreas Färber2d797b62012-05-02 17:21:31 +020046bool qemu_thread_is_self(QemuThread *thread);
Corentin Chary313b1d62010-07-07 20:58:01 +020047void qemu_thread_exit(void *retval);
48
aliguorie5d355d2009-04-24 18:03:15 +000049#endif