All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael W. Bombardieri" <mb@ii.net>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH]: Fix conditional compilation for OpenBSD
Date: Sun, 31 Mar 2013 20:46:57 +0800	[thread overview]
Message-ID: <20130331124656.GA565@bom.nom.co> (raw)
In-Reply-To: <CAFEAcA-FqoZZ47CORw_WWd+CwXtTp_7dkZS2thV_iLya6FO+BA@mail.gmail.com>

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) {

  reply	other threads:[~2013-03-31 12:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-31  0:32 [Qemu-devel] [PATCH]: Fix conditional compilation for OpenBSD Michael W. Bombardieri
2013-03-31  0:48 ` Peter Maydell
2013-03-31 12:46   ` Michael W. Bombardieri [this message]
2013-03-31 13:36     ` Peter Maydell

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=20130331124656.GA565@bom.nom.co \
    --to=mb@ii.net \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@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.