Skip to content

Commit 27feb9b

Browse files
committed
Simplify mac cond type
1 parent c7b6fa2 commit 27feb9b

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

wolfcrypt/src/wc_port.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3746,7 +3746,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37463746
}
37473747
return BAD_MUTEX_E;
37483748
}
3749-
#else
3749+
#else /* __MACH__ */
37503750
/* Apple style dispatch semaphore */
37513751
int wolfSSL_CondInit(COND_TYPE* cond)
37523752
{
@@ -3758,8 +3758,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37583758
* dispatch_semaphore_create(). work around this by initing
37593759
* with 0, then incrementing it afterwards.
37603760
*/
3761-
cond->sem = dispatch_semaphore_create(0);
3762-
if (cond->sem == NULL)
3761+
*cond = dispatch_semaphore_create(0);
3762+
if (*cond == NULL)
37633763
return MEMORY_E;
37643764
return 0;
37653765
}
@@ -3769,8 +3769,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37693769
if (cond == NULL)
37703770
return BAD_FUNC_ARG;
37713771

3772-
dispatch_release(cond->sem);
3773-
cond->sem = NULL;
3772+
dispatch_release(*cond);
3773+
*cond = NULL;
37743774
return 0;
37753775
}
37763776

@@ -3779,7 +3779,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37793779
if (cond == NULL)
37803780
return BAD_FUNC_ARG;
37813781

3782-
dispatch_semaphore_signal(cond->sem);
3782+
dispatch_semaphore_signal(*cond);
37833783
return 0;
37843784
}
37853785

@@ -3788,7 +3788,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37883788
if (cond == NULL)
37893789
return BAD_FUNC_ARG;
37903790

3791-
dispatch_semaphore_wait(cond->sem, DISPATCH_TIME_FOREVER);
3791+
dispatch_semaphore_wait(*cond, DISPATCH_TIME_FOREVER);
37923792
return 0;
37933793
}
37943794
#endif /* __MACH__ */

wolfssl/wolfcrypt/types.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,17 +1380,15 @@ typedef struct w64wrapper {
13801380
#define WOLFSSL_THREAD
13811381
#elif (defined(_POSIX_THREADS) || defined(HAVE_PTHREAD)) && \
13821382
!defined(__MINGW32__)
1383-
#ifdef __MACH__
1384-
#include <dispatch/dispatch.h>
1385-
typedef struct COND_TYPE {
1386-
dispatch_semaphore_t sem;
1387-
} COND_TYPE;
1388-
#else
1383+
#ifndef __MACH__
13891384
#include <pthread.h>
13901385
typedef struct COND_TYPE {
13911386
pthread_mutex_t mutex;
13921387
pthread_cond_t cond;
13931388
} COND_TYPE;
1389+
#else
1390+
#include <dispatch/dispatch.h>
1391+
typedef dispatch_semaphore_t COND_TYPE;
13941392
#endif
13951393
typedef void* THREAD_RETURN;
13961394
typedef pthread_t THREAD_TYPE;

0 commit comments

Comments
 (0)