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