mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 02:37:28 +02:00
Merge pull request #7932 from barracuda156/dispatch
Fixes for earlier macOS
This commit is contained in:
@ -1100,7 +1100,11 @@ static int StopMonitor(wolfSSL_CRL_mfd_t mfd)
|
||||
struct kevent change;
|
||||
|
||||
/* trigger custom shutdown */
|
||||
#if defined(NOTE_TRIGGER)
|
||||
EV_SET(&change, CRL_CUSTOM_FD, EVFILT_USER, 0, NOTE_TRIGGER, 0, NULL);
|
||||
#elif defined(EV_TRIGGER)
|
||||
EV_SET(&change, CRL_CUSTOM_FD, EVFILT_USER, EV_TRIGGER, 0, 0, NULL);
|
||||
#endif
|
||||
if (kevent(mfd, &change, 1, NULL, 0, NULL) < 0) {
|
||||
WOLFSSL_MSG("kevent trigger customer event failed");
|
||||
return WOLFSSL_FATAL_ERROR;
|
||||
|
@ -24,6 +24,10 @@
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/types.h>
|
||||
#include <wolfssl/wolfcrypt/error-crypt.h>
|
||||
@ -3814,86 +3818,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
|
||||
}
|
||||
|
||||
#ifdef WOLFSSL_COND
|
||||
#ifndef __MACH__
|
||||
/* Generic POSIX conditional */
|
||||
int wolfSSL_CondInit(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_init(&cond->mutex, NULL) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
if (pthread_cond_init(&cond->cond, NULL) != 0) {
|
||||
/* Keep compilers happy that we are using the return code */
|
||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||
return MEMORY_E;
|
||||
return MEMORY_E;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondFree(COND_TYPE* cond)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||
ret = MEMORY_E;
|
||||
|
||||
if (pthread_cond_destroy(&cond->cond) != 0)
|
||||
ret = MEMORY_E;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wolfSSL_CondStart(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_lock(&cond->mutex) != 0)
|
||||
return BAD_MUTEX_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondSignal(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_cond_signal(&cond->cond) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondWait(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_cond_wait(&cond->cond, &cond->mutex) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondEnd(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_unlock(&cond->mutex) != 0)
|
||||
return BAD_MUTEX_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#else /* __MACH__ */
|
||||
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 \
|
||||
&& !defined(__ppc__)
|
||||
/* Apple style dispatch semaphore */
|
||||
int wolfSSL_CondInit(COND_TYPE* cond)
|
||||
{
|
||||
@ -3985,6 +3911,87 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#else /* Generic POSIX conditional */
|
||||
|
||||
int wolfSSL_CondInit(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_init(&cond->mutex, NULL) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
if (pthread_cond_init(&cond->cond, NULL) != 0) {
|
||||
/* Keep compilers happy that we are using the return code */
|
||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||
return MEMORY_E;
|
||||
return MEMORY_E;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondFree(COND_TYPE* cond)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_destroy(&cond->mutex) != 0)
|
||||
ret = MEMORY_E;
|
||||
|
||||
if (pthread_cond_destroy(&cond->cond) != 0)
|
||||
ret = MEMORY_E;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wolfSSL_CondStart(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_lock(&cond->mutex) != 0)
|
||||
return BAD_MUTEX_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondSignal(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_cond_signal(&cond->cond) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondWait(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_cond_wait(&cond->cond, &cond->mutex) != 0)
|
||||
return MEMORY_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int wolfSSL_CondEnd(COND_TYPE* cond)
|
||||
{
|
||||
if (cond == NULL)
|
||||
return BAD_FUNC_ARG;
|
||||
|
||||
if (pthread_mutex_unlock(&cond->mutex) != 0)
|
||||
return BAD_MUTEX_E;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#endif /* __MACH__ */
|
||||
#endif /* WOLFSSL_COND */
|
||||
|
||||
|
@ -34,6 +34,10 @@ decouple library dependencies with standard string, memory and so on.
|
||||
#include <wolfssl/wolfcrypt/settings.h>
|
||||
#include <wolfssl/wolfcrypt/wc_port.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#include <AvailabilityMacros.h>
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -1493,18 +1497,19 @@ typedef struct w64wrapper {
|
||||
typedef size_t THREAD_TYPE;
|
||||
#define WOLFSSL_THREAD
|
||||
#elif defined(WOLFSSL_PTHREADS)
|
||||
#ifndef __MACH__
|
||||
#include <pthread.h>
|
||||
typedef struct COND_TYPE {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} COND_TYPE;
|
||||
#else
|
||||
#if defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 \
|
||||
&& !defined(__ppc__)
|
||||
#include <dispatch/dispatch.h>
|
||||
typedef struct COND_TYPE {
|
||||
wolfSSL_Mutex mutex;
|
||||
dispatch_semaphore_t cond;
|
||||
} COND_TYPE;
|
||||
#else
|
||||
#include <pthread.h>
|
||||
typedef struct COND_TYPE {
|
||||
pthread_mutex_t mutex;
|
||||
pthread_cond_t cond;
|
||||
} COND_TYPE;
|
||||
#endif
|
||||
typedef void* THREAD_RETURN;
|
||||
typedef pthread_t THREAD_TYPE;
|
||||
|
Reference in New Issue
Block a user