Skip to content

Commit

Permalink
Merge pull request wolfSSL#7015 from lealem47/zd17088
Browse files Browse the repository at this point in the history
Reworking MinGW mutex/threading
  • Loading branch information
JacobBarthelmeh authored Dec 1, 2023
2 parents a1e74d9 + e1ac56f commit abab390
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/benchmark/tls_bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -1203,7 +1203,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN client_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_server.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_server.cond));

WOLFSSL_RETURN_FROM_THREAD(NULL);
WOLFSSL_RETURN_FROM_THREAD(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_CLIENT */
Expand Down Expand Up @@ -1663,7 +1663,7 @@ static THREAD_RETURN WOLFSSL_THREAD_NO_JOIN server_thread(void* args)
THREAD_CHECK_RET(wolfSSL_CondSignal(&info->to_client.cond));
THREAD_CHECK_RET(wolfSSL_CondEnd(&info->to_client.cond));

WOLFSSL_RETURN_FROM_THREAD(NULL);
WOLFSSL_RETURN_FROM_THREAD(0);
}
#endif /* !SINGLE_THREADED */
#endif /* !NO_WOLFSSL_SERVER */
Expand Down
6 changes: 4 additions & 2 deletions wolfcrypt/src/wc_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -1489,7 +1489,7 @@ int wolfSSL_CryptHwMutexUnLock(void)
return 0;
}

#elif defined(USE_WINDOWS_API)
#elif defined(USE_WINDOWS_API) && !defined(WOLFSSL_PTHREADS)

int wc_InitMutex(wolfSSL_Mutex* m)
{
Expand Down Expand Up @@ -3426,7 +3426,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)

#ifndef SINGLE_THREADED

#ifdef _MSC_VER
#if defined(USE_WINDOWS_API) && !defined(WOLFSSL_PTHREADS)
int wolfSSL_NewThread(THREAD_TYPE* thread,
THREAD_CB cb, void* arg)
{
Expand All @@ -3450,6 +3450,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
return 0;
}

#ifdef WOLFSSL_THREAD_NO_JOIN
int wolfSSL_NewThreadNoJoin(THREAD_CB_NOJOIN cb, void* arg)
{
THREAD_TYPE thread;
Expand All @@ -3464,6 +3465,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)

return 0;
}
#endif

int wolfSSL_JoinThread(THREAD_TYPE thread)
{
Expand Down
8 changes: 5 additions & 3 deletions wolfssl/wolfcrypt/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ typedef struct w64wrapper {
typedef unsigned int THREAD_RETURN;
typedef size_t THREAD_TYPE;
#define WOLFSSL_THREAD
#elif (defined(_POSIX_THREADS) || defined(HAVE_PTHREAD))
#elif defined(WOLFSSL_PTHREADS)
#ifndef __MACH__
#include <pthread.h>
typedef struct COND_TYPE {
Expand All @@ -1402,7 +1402,7 @@ typedef struct w64wrapper {
typedef unsigned int THREAD_RETURN;
typedef TaskHandle_t THREAD_TYPE;
#define WOLFSSL_THREAD
#elif defined(_MSC_VER)
#elif defined(USE_WINDOWS_API)
typedef unsigned THREAD_RETURN;
typedef uintptr_t THREAD_TYPE;
typedef struct COND_TYPE {
Expand All @@ -1412,7 +1412,9 @@ typedef struct w64wrapper {
#define WOLFSSL_COND
#define INVALID_THREAD_VAL ((THREAD_TYPE)(INVALID_HANDLE_VALUE))
#define WOLFSSL_THREAD __stdcall
#define WOLFSSL_THREAD_NO_JOIN __cdecl
#if !defined(__MINGW32__)
#define WOLFSSL_THREAD_NO_JOIN __cdecl
#endif
#else
typedef unsigned int THREAD_RETURN;
typedef size_t THREAD_TYPE;
Expand Down
5 changes: 2 additions & 3 deletions wolfssl/wolfcrypt/wc_port.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@

/* THREADING/MUTEX SECTION */
#ifdef USE_WINDOWS_API
#if defined(__MINGW32__) && !defined(SINGLE_THREADED)
#define WOLFSSL_PTHREADS
#if defined(WOLFSSL_PTHREADS)
#include <pthread.h>
#endif
#ifdef WOLFSSL_GAME_BUILD
Expand Down Expand Up @@ -231,7 +230,7 @@
signed char mutexBuffer[portQUEUE_OVERHEAD_BYTES];
xSemaphoreHandle mutex;
} wolfSSL_Mutex;
#elif defined(USE_WINDOWS_API)
#elif defined(USE_WINDOWS_API) && !defined(WOLFSSL_PTHREADS)
typedef CRITICAL_SECTION wolfSSL_Mutex;
#elif defined(MAXQ10XX_MUTEX)
#include <sys/mman.h>
Expand Down

0 comments on commit abab390

Please sign in to comment.