All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Tokarev <mjt@tls.msk.ru>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	qemu-trivial@nongnu.org, Michael Tokarev <mjt@tls.msk.ru>
Subject: [Qemu-devel] [PULL 18/31] util/qemu-thread-posix.c: Replace OS ifdefs with CONFIG_HAVE_SEM_TIMEDWAIT
Date: Mon, 25 Sep 2017 00:22:36 +0300	[thread overview]
Message-ID: <f958231f3371e17ca98440cf42d405a5365f67d6.1506288070.git.mjt@msgid.tls.msk.ru> (raw)
In-Reply-To: <cover.1506288070.git.mjt@msgid.tls.msk.ru>
In-Reply-To: <cover.1506288070.git.mjt@msgid.tls.msk.ru>

From: Peter Maydell <peter.maydell@linaro.org>

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>
---
 configure                   | 15 +++++++++++++++
 include/qemu/thread-posix.h |  2 +-
 util/qemu-thread-posix.c    | 10 +++++-----
 3 files changed, 21 insertions(+), 6 deletions(-)

diff --git a/configure b/configure
index 12d4e4ebfa..1f7b4f03ce 100755
--- a/configure
+++ b/configure
@@ -4425,6 +4425,18 @@ if compile_prog "" "" ; then
 fi
 
 ##########################################
+# check if we have sem_timedwait
+
+sem_timedwait=no
+cat > $TMPC << EOF
+#include <semaphore.h>
+int main(void) { return sem_timedwait(0, 0); }
+EOF
+if compile_prog "" "" ; then
+    sem_timedwait=yes
+fi
+
+##########################################
 # check if trace backend exists
 
 $python "$source_path/scripts/tracetool.py" "--backends=$trace_backends" --check-backends  > /dev/null 2> /dev/null
@@ -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 e5e3a0ff97..f4296d31c4 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 4e95d272dc..7306475899 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);
-- 
2.11.0

  parent reply	other threads:[~2017-09-24 22:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-24 21:22 [Qemu-devel] [PULL 00/31] Trivial patches for 2017-09-25 Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 01/31] configure: Remove unused code (found by shellcheck) Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 02/31] Replace round_page() with TARGET_PAGE_ALIGN() Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 03/31] MAINTAINERS: add missing ARM entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 04/31] MAINTAINERS: add missing STM32 entry Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 05/31] MAINTAINERS: add missing entry for vhost Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 06/31] MAINTAINERS: add missing VMWare entry Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 07/31] MAINTAINERS: add missing Guest Agent entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 08/31] MAINTAINERS: add missing qcow2 entry Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 09/31] MAINTAINERS: add missing PCI entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 10/31] MAINTAINERS: add missing SSI entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 11/31] MAINTAINERS: add missing entries for throttling infra Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 12/31] MAINTAINERS: add missing AIO entry Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 13/31] MAINTAINERS: add missing entry for Generic Loader Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 14/31] MAINTAINERS: add missing Cryptography entry Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 15/31] MAINTAINERS: update docs/devel/ entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 16/31] MAINTAINERS: update docs/interop/ entries Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 17/31] filter-mirror: segfault when specifying non existent device Michael Tokarev
2017-09-24 21:22 ` Michael Tokarev [this message]
2017-09-24 21:22 ` [Qemu-devel] [PULL 19/31] aux-to-i2c-bridge: don't allow user to create one Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 20/31] hw/display/xenfb.c: Add trace_xenfb_key_event Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 21/31] remove trailing whitespace from qemu-options.hx Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 22/31] chardev/baum: fix baum that releases brlapi twice Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 23/31] trivial: Add missing "-m" parameter in docs/memory-hotplug.txt Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 24/31] target/xtensa: Use the pre-defined MEMTXATTRS_UNSPECIFIED macro Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 25/31] osdep: Fix ROUND_UP(64-bit, 32-bit) Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 26/31] hw/display/virtio-gpu: Put the virtio-gpu-device into the display category Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 27/31] nbd-client: Use correct macro parenthesization Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 28/31] dma/i82374: avoid double creation of i82374 device Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 29/31] tests/boot-sector: Increase timeout to 600 seconds Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 30/31] Drop gld linker usage on SunOS Michael Tokarev
2017-09-24 21:22 ` [Qemu-devel] [PULL 31/31] hw/isa/pc87312: Mark the device with user_creatable = false Michael Tokarev
2017-09-25 23:22 ` [Qemu-devel] [PULL 00/31] Trivial patches for 2017-09-25 Peter Maydell
2017-09-26  5:57   ` Michael Tokarev
2017-09-26  7:48     ` Eduardo Otubo
     [not found]   ` <55782343-4bb4-d5ed-2c5d-4dd0fc5764dd@tls.msk.ru>
2017-09-26  6:00     ` Michael Tokarev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f958231f3371e17ca98440cf42d405a5365f67d6.1506288070.git.mjt@msgid.tls.msk.ru \
    --to=mjt@tls.msk.ru \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.