Tentative: User defined mutex

This commit is contained in:
Takashi Kojo
2020-06-14 07:12:13 +09:00
parent f87f09fcd7
commit 8ff1b474bc
4 changed files with 41 additions and 3 deletions

27
user-mutex.c Normal file
View File

@ -0,0 +1,27 @@
#include <wolfssl/wolfcrypt/wc_port.h>
int wc_InitMutex(wolfSSL_Mutex* m)
{
(void)m;
return 0;
}
int wc_FreeMutex(wolfSSL_Mutex *m)
{
(void)m;
return 0;
}
int wc_LockMutex(wolfSSL_Mutex *m)
{
(void)m;
return 0;
}
int wc_UnLockMutex(wolfSSL_Mutex *m)
{
(void)m;
return 0;
}

2
user_settings.h Normal file
View File

@ -0,0 +1,2 @@
typedef int wolfSSL_Mutex;

View File

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

View File

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