Patchwork Disable semaphores fallback code for OpenBSD

login
register
mail settings
Submitter Brad
Date Dec. 28, 2012, 6:38 a.m.
Message ID <20121228063808.GC27232@rox.home.comstyle.com>
Download mbox | patch
Permalink /patch/208416/
State New
Headers show

Comments

Brad - Dec. 28, 2012, 6:38 a.m.
Disable the semaphores fallback code for OpenBSD as modern OpenBSD
releases now have sem_timedwait().

Signed-off-by: Brad Smith <brad@comstyle.com>
Blue Swirl - Dec. 28, 2012, 8:09 p.m.
Thanks, applied.

On Fri, Dec 28, 2012 at 6:38 AM, Brad Smith <brad@comstyle.com> wrote:
> Disable the semaphores fallback code for OpenBSD as modern OpenBSD
> releases now have sem_timedwait().
>
> Signed-off-by: Brad Smith <brad@comstyle.com>
>
> diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h
> index 380bae2..0f30dcc 100644
> --- a/include/qemu/thread-posix.h
> +++ b/include/qemu/thread-posix.h
> @@ -12,7 +12,7 @@ struct QemuCond {
>  };
>
>  struct QemuSemaphore {
> -#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      pthread_mutex_t lock;
>      pthread_cond_t cond;
>      int count;
> diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
> index 7be292e..6374df3 100644
> --- a/qemu-thread-posix.c
> +++ b/qemu-thread-posix.c
> @@ -122,7 +122,7 @@ void qemu_sem_init(QemuSemaphore *sem, int init)
>  {
>      int rc;
>
> -#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      compute_abs_deadline(&ts, ms);
>      pthread_mutex_lock(&sem->lock);
>      --sem->count;
> @@ -248,7 +248,7 @@ int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
>
>  void qemu_sem_wait(QemuSemaphore *sem)
>  {
> -#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
> +#if defined(__APPLE__) || defined(__NetBSD__)
>      pthread_mutex_lock(&sem->lock);
>      --sem->count;
>      while (sem->count < 0) {
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
Peter Maydell - Dec. 28, 2012, 11:36 p.m.
On 28 December 2012 06:38, Brad Smith <brad@comstyle.com> wrote:
> Disable the semaphores fallback code for OpenBSD as modern OpenBSD
> releases now have sem_timedwait().

Maybe we should have a configure test for existence of sem_timedwait()
rather than os-guessing ifdeffery...

-- PMM
Blue Swirl - Dec. 29, 2012, 3:51 p.m.
On Fri, Dec 28, 2012 at 11:36 PM, Peter Maydell
<peter.maydell@linaro.org> wrote:
> On 28 December 2012 06:38, Brad Smith <brad@comstyle.com> wrote:
>> Disable the semaphores fallback code for OpenBSD as modern OpenBSD
>> releases now have sem_timedwait().
>
> Maybe we should have a configure test for existence of sem_timedwait()
> rather than os-guessing ifdeffery...

+1

>
> -- PMM
>

Patch

diff --git a/include/qemu/thread-posix.h b/include/qemu/thread-posix.h
index 380bae2..0f30dcc 100644
--- a/include/qemu/thread-posix.h
+++ b/include/qemu/thread-posix.h
@@ -12,7 +12,7 @@  struct QemuCond {
 };
 
 struct QemuSemaphore {
-#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     pthread_mutex_t lock;
     pthread_cond_t cond;
     int count;
diff --git a/qemu-thread-posix.c b/qemu-thread-posix.c
index 7be292e..6374df3 100644
--- a/qemu-thread-posix.c
+++ b/qemu-thread-posix.c
@@ -122,7 +122,7 @@  void qemu_sem_init(QemuSemaphore *sem, int init)
 {
     int rc;
 
-#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     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(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     compute_abs_deadline(&ts, ms);
     pthread_mutex_lock(&sem->lock);
     --sem->count;
@@ -248,7 +248,7 @@  int qemu_sem_timedwait(QemuSemaphore *sem, int ms)
 
 void qemu_sem_wait(QemuSemaphore *sem)
 {
-#if defined(__OpenBSD__) || defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__) || defined(__NetBSD__)
     pthread_mutex_lock(&sem->lock);
     --sem->count;
     while (sem->count < 0) {