aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 1 | #ifndef __QEMU_THREAD_H |
| 2 | #define __QEMU_THREAD_H 1 |
aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 3 | |
| 4 | typedef struct QemuMutex QemuMutex; |
| 5 | typedef struct QemuCond QemuCond; |
| 6 | typedef struct QemuThread QemuThread; |
| 7 | |
Paolo Bonzini | 9257d46 | 2011-03-12 17:43:52 +0100 | [diff] [blame] | 8 | #ifdef _WIN32 |
| 9 | #include "qemu-thread-win32.h" |
| 10 | #else |
| 11 | #include "qemu-thread-posix.h" |
| 12 | #endif |
| 13 | |
aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 14 | void qemu_mutex_init(QemuMutex *mutex); |
Corentin Chary | 313b1d6 | 2010-07-07 20:58:01 +0200 | [diff] [blame] | 15 | void qemu_mutex_destroy(QemuMutex *mutex); |
aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 16 | void qemu_mutex_lock(QemuMutex *mutex); |
| 17 | int qemu_mutex_trylock(QemuMutex *mutex); |
| 18 | int qemu_mutex_timedlock(QemuMutex *mutex, uint64_t msecs); |
| 19 | void qemu_mutex_unlock(QemuMutex *mutex); |
| 20 | |
| 21 | void qemu_cond_init(QemuCond *cond); |
Corentin Chary | 313b1d6 | 2010-07-07 20:58:01 +0200 | [diff] [blame] | 22 | void qemu_cond_destroy(QemuCond *cond); |
Paolo Bonzini | 9257d46 | 2011-03-12 17:43:52 +0100 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * IMPORTANT: The implementation does not guarantee that pthread_cond_signal |
| 26 | * and pthread_cond_broadcast can be called except while the same mutex is |
| 27 | * held as in the corresponding pthread_cond_wait calls! |
| 28 | */ |
aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 29 | void qemu_cond_signal(QemuCond *cond); |
| 30 | void qemu_cond_broadcast(QemuCond *cond); |
| 31 | void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); |
| 32 | int qemu_cond_timedwait(QemuCond *cond, QemuMutex *mutex, uint64_t msecs); |
| 33 | |
| 34 | void qemu_thread_create(QemuThread *thread, |
| 35 | void *(*start_routine)(void*), |
| 36 | void *arg); |
Jan Kiszka | b7680cb | 2011-03-12 17:43:51 +0100 | [diff] [blame] | 37 | void qemu_thread_get_self(QemuThread *thread); |
| 38 | int qemu_thread_is_self(QemuThread *thread); |
Corentin Chary | 313b1d6 | 2010-07-07 20:58:01 +0200 | [diff] [blame] | 39 | void qemu_thread_exit(void *retval); |
| 40 | |
aliguori | e5d355d | 2009-04-24 18:03:15 +0000 | [diff] [blame] | 41 | #endif |