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