From 27feb9b9e972f447a6916f4c6ef87ca8e088b784 Mon Sep 17 00:00:00 2001 From: Juliusz Sosinowicz Date: Wed, 9 Aug 2023 14:18:32 +0200 Subject: [PATCH] Simplify mac cond type --- wolfcrypt/src/wc_port.c | 14 +++++++------- wolfssl/wolfcrypt/types.h | 10 ++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/wolfcrypt/src/wc_port.c b/wolfcrypt/src/wc_port.c index e39f6ad9e..29200ae90 100644 --- a/wolfcrypt/src/wc_port.c +++ b/wolfcrypt/src/wc_port.c @@ -3746,7 +3746,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) } return BAD_MUTEX_E; } - #else + #else /* __MACH__ */ /* Apple style dispatch semaphore */ int wolfSSL_CondInit(COND_TYPE* cond) { @@ -3758,8 +3758,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) * dispatch_semaphore_create(). work around this by initing * with 0, then incrementing it afterwards. */ - cond->sem = dispatch_semaphore_create(0); - if (cond->sem == NULL) + *cond = dispatch_semaphore_create(0); + if (*cond == NULL) return MEMORY_E; return 0; } @@ -3769,8 +3769,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - dispatch_release(cond->sem); - cond->sem = NULL; + dispatch_release(*cond); + *cond = NULL; return 0; } @@ -3779,7 +3779,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - dispatch_semaphore_signal(cond->sem); + dispatch_semaphore_signal(*cond); return 0; } @@ -3788,7 +3788,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n) if (cond == NULL) return BAD_FUNC_ARG; - dispatch_semaphore_wait(cond->sem, DISPATCH_TIME_FOREVER); + dispatch_semaphore_wait(*cond, DISPATCH_TIME_FOREVER); return 0; } #endif /* __MACH__ */ diff --git a/wolfssl/wolfcrypt/types.h b/wolfssl/wolfcrypt/types.h index 3c4294895..3a6b8a7af 100644 --- a/wolfssl/wolfcrypt/types.h +++ b/wolfssl/wolfcrypt/types.h @@ -1380,17 +1380,15 @@ typedef struct w64wrapper { #define WOLFSSL_THREAD #elif (defined(_POSIX_THREADS) || defined(HAVE_PTHREAD)) && \ !defined(__MINGW32__) - #ifdef __MACH__ - #include - typedef struct COND_TYPE { - dispatch_semaphore_t sem; - } COND_TYPE; - #else + #ifndef __MACH__ #include typedef struct COND_TYPE { pthread_mutex_t mutex; pthread_cond_t cond; } COND_TYPE; + #else + #include + typedef dispatch_semaphore_t COND_TYPE; #endif typedef void* THREAD_RETURN; typedef pthread_t THREAD_TYPE;