1 #ifndef __QEMU_THREAD_H 2 #define __QEMU_THREAD_H 1 3 4 5 typedef struct QemuMutex QemuMutex; 6 typedef struct QemuCond QemuCond; 7 typedef struct QemuSemaphore QemuSemaphore; 8 typedef struct QemuEvent QemuEvent; 9 typedef struct QemuThread QemuThread; 10 11 #ifdef _WIN32 12 #include "qemu/thread-win32.h" 13 #else 14 #include "qemu/thread-posix.h" 15 #endif 16 17 #define QEMU_THREAD_JOINABLE 0 18 #define QEMU_THREAD_DETACHED 1 19 20 void qemu_mutex_init(QemuMutex *mutex); 21 void qemu_mutex_destroy(QemuMutex *mutex); 22 void qemu_mutex_lock(QemuMutex *mutex); 23 int qemu_mutex_trylock(QemuMutex *mutex); 24 void qemu_mutex_unlock(QemuMutex *mutex); 25 26 void qemu_cond_init(QemuCond *cond); 27 void qemu_cond_destroy(QemuCond *cond); 28 29 /* 30 * IMPORTANT: The implementation does not guarantee that pthread_cond_signal 31 * and pthread_cond_broadcast can be called except while the same mutex is 32 * held as in the corresponding pthread_cond_wait calls! 33 */ 34 void qemu_cond_signal(QemuCond *cond); 35 void qemu_cond_broadcast(QemuCond *cond); 36 void qemu_cond_wait(QemuCond *cond, QemuMutex *mutex); 37 38 void qemu_sem_init(QemuSemaphore *sem, int init); 39 void qemu_sem_post(QemuSemaphore *sem); 40 void qemu_sem_wait(QemuSemaphore *sem); 41 int qemu_sem_timedwait(QemuSemaphore *sem, int ms); 42 void qemu_sem_destroy(QemuSemaphore *sem); 43 44 void qemu_event_init(QemuEvent *ev, bool init); 45 void qemu_event_set(QemuEvent *ev); 46 void qemu_event_reset(QemuEvent *ev); 47 void qemu_event_wait(QemuEvent *ev); 48 void qemu_event_destroy(QemuEvent *ev); 49 50 void qemu_thread_create(QemuThread *thread, const char *name, 51 void *(*start_routine)(void *), 52 void *arg, int mode); 53 void *qemu_thread_join(QemuThread *thread); 54 void qemu_thread_get_self(QemuThread *thread); 55 bool qemu_thread_is_self(QemuThread *thread); 56 void qemu_thread_exit(void *retval); 57 void qemu_thread_naming(bool enable); 58 59 struct Notifier; 60 void qemu_thread_atexit_add(struct Notifier *notifier); 61 void qemu_thread_atexit_remove(struct Notifier *notifier); 62 63 #endif 64