Merge pull request #3071 from kojo1/user-mutex

User defined mutex
This commit is contained in:
David Garske
2020-06-28 21:45:30 -07:00
committed by GitHub
2 changed files with 19 additions and 3 deletions

View File

@ -664,7 +664,7 @@ int z_fs_close(XFILE file)
#endif /* !NO_FILESYSTEM && !WOLFSSL_ZEPHYR */ #endif /* !NO_FILESYSTEM && !WOLFSSL_ZEPHYR */
#if !defined(WOLFSSL_USER_MUTEX)
wolfSSL_Mutex* wc_InitAndAllocMutex(void) wolfSSL_Mutex* wc_InitAndAllocMutex(void)
{ {
wolfSSL_Mutex* m = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex), NULL, wolfSSL_Mutex* m = (wolfSSL_Mutex*) XMALLOC(sizeof(wolfSSL_Mutex), NULL,
@ -682,6 +682,7 @@ wolfSSL_Mutex* wc_InitAndAllocMutex(void)
return m; return m;
} }
#endif
#ifdef USE_WOLF_STRTOK #ifdef USE_WOLF_STRTOK
/* String token (delim) search. If str is null use nextp. */ /* String token (delim) search. If str is null use nextp. */
@ -1862,6 +1863,17 @@ int wolfSSL_CryptHwMutexUnLock(void) {
return 0; return 0;
} }
#elif defined(WOLFSSL_USER_MUTEX)
/* Use user own mutex */
/*
int wc_InitMutex(wolfSSL_Mutex* m) { ... }
int wc_FreeMutex(wolfSSL_Mutex *m) { ... }
int wc_LockMutex(wolfSSL_Mutex *m) { ... }
int wc_UnLockMutex(wolfSSL_Mutex *m) { ... }
*/
#else #else
#warning No mutex handling defined #warning No mutex handling defined

View File

@ -156,8 +156,10 @@
#else #else
#ifndef SINGLE_THREADED #ifndef SINGLE_THREADED
#define WOLFSSL_PTHREADS #ifndef WOLFSSL_USER_MUTEX
#include <pthread.h> #define WOLFSSL_PTHREADS
#include <pthread.h>
#endif
#endif #endif
#if (defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)) && \ #if (defined(OPENSSL_EXTRA) || defined(GOAHEAD_WS)) && \
!defined(NO_FILESYSTEM) !defined(NO_FILESYSTEM)
@ -238,6 +240,8 @@
typedef struct k_mutex wolfSSL_Mutex; typedef struct k_mutex wolfSSL_Mutex;
#elif defined(WOLFSSL_TELIT_M2MB) #elif defined(WOLFSSL_TELIT_M2MB)
typedef M2MB_OS_MTX_HANDLE wolfSSL_Mutex; typedef M2MB_OS_MTX_HANDLE wolfSSL_Mutex;
#elif defined(WOLFSSL_USER_MUTEX)
/* typedef User_Mutex wolfSSL_Mutex; */
#else #else
#error Need a mutex type in multithreaded mode #error Need a mutex type in multithreaded mode
#endif /* USE_WINDOWS_API */ #endif /* USE_WINDOWS_API */