401bc051d7
In qemu-thread-posix.c we have two implementations of the various qemu_sem_* functions, one of which uses native POSIX sem_* and the other of which emulates them with pthread conditions. This is necessary because not all our host OSes support sem_timedwait(). Instead of a hard-coded list of OSes which don't implement sem_timedwait(), which gets out of date, make configure test for the presence of the function and set a new CONFIG_HAVE_SEM_TIMEDWAIT appropriately. In particular, newer NetBSDs have sem_timedwait(), so this commit will switch them over to using it. OSX still does not have an implementation. Signed-off-by: Peter Maydell <peter.maydell@linaro.org> Reviewed-by: Kamil Rytarowski <n54@gmx.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
48 lines
844 B
C
48 lines
844 B
C
#ifndef QEMU_THREAD_POSIX_H
|
|
#define QEMU_THREAD_POSIX_H
|
|
|
|
#include <pthread.h>
|
|
#include <semaphore.h>
|
|
|
|
typedef QemuMutex QemuRecMutex;
|
|
#define qemu_rec_mutex_destroy qemu_mutex_destroy
|
|
#define qemu_rec_mutex_lock qemu_mutex_lock
|
|
#define qemu_rec_mutex_try_lock qemu_mutex_try_lock
|
|
#define qemu_rec_mutex_unlock qemu_mutex_unlock
|
|
|
|
struct QemuMutex {
|
|
pthread_mutex_t lock;
|
|
bool initialized;
|
|
};
|
|
|
|
struct QemuCond {
|
|
pthread_cond_t cond;
|
|
bool initialized;
|
|
};
|
|
|
|
struct QemuSemaphore {
|
|
#ifndef CONFIG_SEM_TIMEDWAIT
|
|
pthread_mutex_t lock;
|
|
pthread_cond_t cond;
|
|
unsigned int count;
|
|
#else
|
|
sem_t sem;
|
|
#endif
|
|
bool initialized;
|
|
};
|
|
|
|
struct QemuEvent {
|
|
#ifndef __linux__
|
|
pthread_mutex_t lock;
|
|
pthread_cond_t cond;
|
|
#endif
|
|
unsigned value;
|
|
bool initialized;
|
|
};
|
|
|
|
struct QemuThread {
|
|
pthread_t thread;
|
|
};
|
|
|
|
#endif
|