From patchwork Sun Mar 31 12:46:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael W. Bombardieri" X-Patchwork-Id: 232607 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A0D052C00F1 for ; Sun, 31 Mar 2013 23:49:42 +1100 (EST) Received: from localhost ([::1]:53886 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMHhc-0002tc-NE for incoming@patchwork.ozlabs.org; Sun, 31 Mar 2013 08:49:40 -0400 Received: from eggs.gnu.org ([208.118.235.92]:33079) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMHhI-0002tJ-GZ for qemu-devel@nongnu.org; Sun, 31 Mar 2013 08:49:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UMHhD-0000uE-Vd for qemu-devel@nongnu.org; Sun, 31 Mar 2013 08:49:20 -0400 Received: from [203.217.0.115] (port=1857 helo=bom.nom.co) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UMHhD-0000u1-9u for qemu-devel@nongnu.org; Sun, 31 Mar 2013 08:49:15 -0400 Received: from bom.nom.co (mwb@localhost [127.0.0.1]) by bom.nom.co (8.14.5/8.14.3) with ESMTP id r2VCkwpd010238; Sun, 31 Mar 2013 20:47:00 +0800 (WST) Received: (from mwb@localhost) by bom.nom.co (8.14.5/8.14.3/Submit) id r2VCkvpU007578; Sun, 31 Mar 2013 20:46:57 +0800 (WST) Date: Sun, 31 Mar 2013 20:46:57 +0800 From: "Michael W. Bombardieri" To: Peter Maydell Message-ID: <20130331124656.GA565@bom.nom.co> References: <20130331003229.GA9097@bom.nom.co> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: OpenBSD 4.x-5.x X-Received-From: 203.217.0.115 Cc: qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH]: Fix conditional compilation for OpenBSD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Sun, Mar 31, 2013 at 12:48:04AM +0000, Peter Maydell wrote: > > Hi Michael; thanks for the patch. However I think we should > fix this by having a configure check for sem_timedwait [or > whatever the functions we need are], rather than by piling > up another OS ifdef check. > > (If you want to have a go at that it would probably be > useful to read the wiki.qemu.org page on submitting > patches; in particular without a Signed-off-by: line > we can't apply a patch at all.) > > -- PMM What about this? Re-use the exting the pthread checker code in 'configure', define HAS_PTHREAD and use this instead of OS specific #if checks. I have built this on 1. Ubuntu 10.04.3 LTS (Linux 2.6.32-36-generic i686) 2. OpenBSD 5.1 (OpenBSD 5.1 GENERIC.MP#188 i386) 3. OpenBSD 5.1 (OpenBSD 5.1 GENERIC#243 amd64) - Michael diff --git a/configure b/configure index f2af714..2e521e2 100755 --- a/configure +++ b/configure @@ -2296,6 +2296,10 @@ else done fi +if [ $pthread = 'yes' ]; then + QEMU_CFLAGS="-DHAS_PTHREAD $QEMU_CFLAGS" +fi + if test "$mingw32" != yes -a "$pthread" = no; then echo echo "Error: pthread check failed" diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h index 0f30dcc..f547f29 100644 --- a/include/qemu/thread-posix.h +++ b/include/qemu/thread-posix.h @@ -12,7 +12,7 @@ struct QemuCond { }; struct QemuSemaphore { -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD pthread_mutex_t lock; pthread_cond_t cond; int count; diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c index 4489abf..edf4715 100644 --- a/util/qemu-thread-posix.c +++ b/util/qemu-thread-posix.c @@ -122,7 +122,7 @@ void qemu_sem_init(QemuSemaphore *sem, int init) { int rc; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD rc = pthread_mutex_init(&sem->lock, NULL); if (rc != 0) { error_exit(rc, __func__); @@ -147,7 +147,7 @@ void qemu_sem_destroy(QemuSemaphore *sem) { int rc; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD rc = pthread_cond_destroy(&sem->cond); if (rc < 0) { error_exit(rc, __func__); @@ -168,7 +168,7 @@ void qemu_sem_post(QemuSemaphore *sem) { int rc; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD pthread_mutex_lock(&sem->lock); if (sem->count == INT_MAX) { rc = EINVAL; @@ -206,7 +206,7 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms) int rc; struct timespec ts; -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD compute_abs_deadline(&ts, ms); pthread_mutex_lock(&sem->lock); --sem->count; @@ -249,7 +249,7 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms) void qemu_sem_wait(QemuSemaphore *sem) { -#if defined(__APPLE__) || defined(__NetBSD__) +#ifdef HAS_PTHREAD pthread_mutex_lock(&sem->lock); --sem->count; while (sem->count < 0) {