From patchwork Sun Sep 24 21:22:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Tokarev X-Patchwork-Id: 114155 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp1929384qgf; Sun, 24 Sep 2017 15:02:36 -0700 (PDT) X-Google-Smtp-Source: AOwi7QCA1L+p4z5pCAraDpeZ5mBjiYv3JRC7Mld3Ofk2pAoIYTg4qemPErfThURHneA5Byqtc0hh X-Received: by 10.55.73.213 with SMTP id w204mr8130948qka.215.1506290556790; Sun, 24 Sep 2017 15:02:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506290556; cv=none; d=google.com; s=arc-20160816; b=x3bjXgU6wer4AraUWY1lPQoYdoxZOYjAeD3FthRY0cD0w0E1LTr7+Tz55QapKAcYZy aZ/nP6yzAF/QYsA6hGcnWdApFBjcD2x4aCeP62pa/Atm4JKC03lme2nURJCqdktvIvjT 4hdzqyASfbNdEnDJkrBte09DOKRF8rAVuIjBKRkrvV5h8u+yhZYVN4OXotbCZ7lhgyGG VflE9cWdZQpggIltjOp2H+FsN/HIwSrnOls5DKPHnFlaIfUptIcIW24oTolBFREhM63q HSNaaYV04cIxAzR9qzL0CHUiDK0MZw/XvLdL7+PbYeWDryMEGIYn9aE5HHEk1f0fHZ6t t5+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :references:in-reply-to:message-id:date:to:from :arc-authentication-results; bh=1kIz+87dpQKQA3PbgKPXTPsxd+pWjExa+ZE/e+4TjbY=; b=ciYshhiIGjG+6+14WvnECFHTCjpD1urvU4vQNUTH7rGz0re49El/PLz2WABlWdm4Wj FWy2VuxvoQzIA7WPKiThUpjkXA5XPdbms3+H3CxmLkPUPFBwdPaUOY65MyRPFsbQrMNL ATEmBmZ1/Nx4f0s5zahrmSOlGFwALTHmvB5KSSn+Q2S9Z4AcWBPsgnGlnEAYOl4g4Wk1 bfJCusmXvnC+NTe3wE0Y3siVgLN40UYHrAuaiVa2MsFEQQNDjbkbL4f5ry5jJLZSTqFk FuTzzh5YHuFWSj/qtcDIytC9p5cbqyFhkAixoxYrRmSTRQ89+H+Wc55eRKfYLLXonZmk FDZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id z193si3168493qka.37.2017.09.24.15.02.36 for (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 24 Sep 2017 15:02:36 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:39618 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEyw-00006T-Lp for patch@linaro.org; Sun, 24 Sep 2017 18:02:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51805) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEyW-00005r-Up for qemu-devel@nongnu.org; Sun, 24 Sep 2017 18:02:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dwEyT-0006Ue-QX for qemu-devel@nongnu.org; Sun, 24 Sep 2017 18:02:08 -0400 Received: from isrv.corpit.ru ([86.62.121.231]:51549) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dwEyT-0006UJ-FS; Sun, 24 Sep 2017 18:02:05 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id A83B641C97; Mon, 25 Sep 2017 01:02:00 +0300 (MSK) Received: from tls.msk.ru (mjt.vpn.tls.msk.ru [192.168.177.99]) by tsrv.corpit.ru (Postfix) with SMTP id 4D483C41; Mon, 25 Sep 2017 00:22:57 +0300 (MSK) Received: (nullmailer pid 28276 invoked by uid 1000); Sun, 24 Sep 2017 21:22:52 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Date: Mon, 25 Sep 2017 00:22:36 +0300 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 86.62.121.231 Subject: [Qemu-devel] [PULL 18/31] util/qemu-thread-posix.c: Replace OS ifdefs with CONFIG_HAVE_SEM_TIMEDWAIT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-trivial@nongnu.org, Peter Maydell , Michael Tokarev Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Peter Maydell 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 Reviewed-by: Kamil Rytarowski Reviewed-by: Eric Blake Signed-off-by: Michael Tokarev --- configure | 15 +++++++++++++++ include/qemu/thread-posix.h | 2 +- util/qemu-thread-posix.c | 10 +++++----- 3 files changed, 21 insertions(+), 6 deletions(-) -- 2.11.0 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 +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);