diff --git a/configure b/configure index 12d4e4ebfae756b1761894f27cd8a7c3627fce5a..1f7b4f03ce23555210b262c5d3ad0d39eeb9fd35 100755 --- a/configure +++ b/configure @@ -4424,6 +4424,18 @@ if compile_prog "" "" ; then posix_syslog=yes fi +########################################## +# check if we have sem_timedwait + +sem_timedwait=no +cat > $TMPC << EOF +#include +int main(void) { return sem_timedwait(0, 0); } +EOF +if compile_prog "" "" ; then + sem_timedwait=yes +fi + ########################################## # check if trace backend exists @@ -5678,6 +5690,9 @@ fi if test "$inotify1" = "yes" ; then echo "CONFIG_INOTIFY1=y" >> $config_host_mak fi +if test "$sem_timedwait" = "yes" ; then + echo "CONFIG_SEM_TIMEDWAIT=y" >> $config_host_mak +fi if test "$byteswap_h" = "yes" ; then echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak fi diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index e5e3a0ff979fdef9a160b825cb39b22e55223786..f4296d31c46dc0990fd3f8e7b71bbd4560a0d3d8 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -21,7 +21,7 @@ struct QemuCond { }; struct QemuSemaphore { -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT pthread_mutex_t lock; pthread_cond_t cond; unsigned int count; diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 4e95d272dc25476b44867f9f7f2bec9d0c57ac75..73064758999f3bfd45819d92f4f682bf33718495 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -168,7 +168,7 @@ void qemu_sem_init(QemuSemaphore *sem, int init) { int rc; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT rc = pthread_mutex_init(&sem->lock, NULL); if (rc != 0) { error_exit(rc, __func__); @@ -196,7 +196,7 @@ void qemu_sem_destroy(QemuSemaphore *sem) assert(sem->initialized); sem->initialized = false; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT rc = pthread_cond_destroy(&sem->cond); if (rc < 0) { error_exit(rc, __func__); @@ -218,7 +218,7 @@ void qemu_sem_post(QemuSemaphore *sem) int rc; assert(sem->initialized); -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT pthread_mutex_lock(&sem->lock); if (sem->count == UINT_MAX) { rc = EINVAL; @@ -256,7 +256,7 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms) struct timespec ts; assert(sem->initialized); -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT rc = 0; compute_abs_deadline(&ts, ms); pthread_mutex_lock(&sem->lock); @@ -304,7 +304,7 @@ void qemu_sem_wait(QemuSemaphore *sem) int rc; assert(sem->initialized); -#if defined(__APPLE__) || defined(__NetBSD__) +#ifndef CONFIG_SEM_TIMEDWAIT pthread_mutex_lock(&sem->lock); while (sem->count == 0) { rc = pthread_cond_wait(&sem->cond, &sem->lock);