From ba3a04eb10a0eb27bcbef5fee5392b1760afa1d7 Mon Sep 17 00:00:00 2001
From: Ivan Prisyazhnyy <john.koepi@gmail.com>
Date: Wed, 31 Jul 2024 14:46:25 +0200
Subject: [PATCH] macos: fix gu_cond usage for darwin after 09848b6

the patch 09848b6 by Jan from 2021-11-11 14:22:24 +0200 that swapped the
order of the arguments to gu_mutex_init_SYS. so now its
`gu_mutex_init_SYS(const wsrep_mutex_key_t* key, gu_mutex_t_SYS *mutex)`
so that for keyless mutexes its using (NULL, &mutex).

the patch replaced `#define gu_mutex_init_SYS pthread_mutex_init`
with its own impl that has different args (key, mutex)

Signed-off-by: Ivan Prisyazhnyy <john.koepi@gmail.com>
---
 galerautils/src/gu_threads.c | 8 ++++----
 galerautils/src/gu_threads.h | 4 ++--
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/galerautils/src/gu_threads.c b/galerautils/src/gu_threads.c
index e30af5bc1..1f1012a54 100644
--- a/galerautils/src/gu_threads.c
+++ b/galerautils/src/gu_threads.c
@@ -248,11 +248,11 @@ int gu_barrier_init_SYS (gu_barrier_t_SYS *barrier,
         errno = EINVAL;
         return -1;
     }
-    if(gu_mutex_init_SYS (&barrier->mutex, 0) < 0)
+    if(gu_mutex_init_SYS (NULL, &barrier->mutex) < 0)
     {
         return -1;
     }
-    if(gu_cond_init_SYS (&barrier->cond, 0) < 0)
+    if(gu_cond_init_SYS (NULL, &barrier->cond) < 0)
     {
         gu_mutex_destroy_SYS (&barrier->mutex);
         return -1;
@@ -279,13 +279,13 @@ int gu_barrier_wait_SYS (gu_barrier_t_SYS *barrier)
         barrier->count = 0;
         gu_cond_broadcast_SYS (&barrier->cond);
         gu_mutex_unlock_SYS (&barrier->mutex);
-        return GU_BARRIER_THREAD_SYS;
+        return GU_BARRIER_SERIAL_THREAD_SYS;
     }
     else
     {
         gu_cond_wait_SYS (&barrier->cond, &(barrier->mutex));
         gu_mutex_unlock_SYS (&barrier->mutex);
-        return !GU_BARRIER_THREAD_SYS;
+        return !GU_BARRIER_SERIAL_THREAD_SYS;
     }
 }
 
diff --git a/galerautils/src/gu_threads.h b/galerautils/src/gu_threads.h
index f55e059bb..993fb0906 100644
--- a/galerautils/src/gu_threads.h
+++ b/galerautils/src/gu_threads.h
@@ -11,7 +11,7 @@
 
 #include "gu_types.h" // bool
 
-#if __unix__
+#if defined(__unix__) || defined(__APPLE__)
 
 #include <pthread.h>
 #include <assert.h>
@@ -318,7 +318,7 @@ typedef pthread_barrier_t      gu_barrier_t_SYS;
 
 #endif /* native POSIX barriers */
 
-#endif /* __unix__ */
+#endif /* defined(__unix__) || defined(__APPLE__) */
 
 /**
  *  Depending on compile-time flags application will either use