Skip to content

Commit da644c7

Browse files
author
gojimmypi
committed
wolfSSL_NewThread() type update for Espressif FreeRTOS
1 parent 64e48de commit da644c7

2 files changed

Lines changed: 27 additions & 15 deletions

File tree

wolfcrypt/src/wc_port.c

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@
127127
#include <wolfssl/wolfcrypt/port/psa/psa.h>
128128
#endif
129129

130+
#if defined(FREERTOS) && defined(WOLFSSL_ESPIDF)
131+
#include <freertos/FreeRTOS.h>
132+
#include <freertos/task.h>
133+
/* The Espressif-specific platform include: */
134+
#include <pthread.h>
135+
#endif
130136

131137
/* prevent multiple mutex initializations */
132138
static volatile int initRefCount = 0;
@@ -3426,6 +3432,7 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
34263432

34273433
#ifndef SINGLE_THREADED
34283434

3435+
/* Environment-specific multi-thread implementation check */
34293436
#if defined(USE_WINDOWS_API) && !defined(WOLFSSL_PTHREADS)
34303437
int wolfSSL_NewThread(THREAD_TYPE* thread,
34313438
THREAD_CB cb, void* arg)
@@ -3724,7 +3731,8 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37243731

37253732
#endif /* WOLFSSL_COND */
37263733

3727-
#elif defined(WOLFSSL_PTHREADS)
3734+
#elif defined(WOLFSSL_PTHREADS) || \
3735+
(defined(FREERTOS) && defined(WOLFSSL_ESPIDF))
37283736

37293737
int wolfSSL_NewThread(THREAD_TYPE* thread,
37303738
THREAD_CB cb, void* arg)
@@ -3738,18 +3746,18 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
37383746
return 0;
37393747
}
37403748

3741-
#ifdef WOLFSSL_THREAD_NO_JOIN
3742-
int wolfSSL_NewThreadNoJoin(THREAD_CB_NOJOIN cb, void* arg)
3743-
{
3744-
THREAD_TYPE thread;
3745-
int ret;
3746-
XMEMSET(&thread, 0, sizeof(thread));
3747-
ret = wolfSSL_NewThread(&thread, cb, arg);
3748-
if (ret == 0)
3749-
ret = pthread_detach(thread);
3750-
return ret;
3751-
}
3752-
#endif
3749+
#ifdef WOLFSSL_THREAD_NO_JOIN
3750+
int wolfSSL_NewThreadNoJoin(THREAD_CB_NOJOIN cb, void* arg)
3751+
{
3752+
THREAD_TYPE thread;
3753+
int ret;
3754+
XMEMSET(&thread, 0, sizeof(thread));
3755+
ret = wolfSSL_NewThread(&thread, cb, arg);
3756+
if (ret == 0)
3757+
ret = pthread_detach(thread);
3758+
return ret;
3759+
}
3760+
#endif
37533761

37543762
int wolfSSL_JoinThread(THREAD_TYPE thread)
37553763
{
@@ -3937,6 +3945,6 @@ char* mystrnstr(const char* s1, const char* s2, unsigned int n)
39373945
#endif /* __MACH__ */
39383946
#endif /* WOLFSSL_COND */
39393947

3940-
#endif
3948+
#endif /* Environment check */
39413949

3942-
#endif /* SINGLE_THREADED */
3950+
#endif /* not SINGLE_THREADED */

wolfssl/wolfcrypt/types.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,10 @@ typedef struct w64wrapper {
13991399
#ifndef HAVE_SELFTEST
14001400
#define WOLFSSL_THREAD_NO_JOIN
14011401
#endif
1402+
#elif defined(FREERTOS) && defined(WOLFSSL_ESPIDF)
1403+
typedef void* THREAD_RETURN;
1404+
typedef pthread_t THREAD_TYPE;
1405+
#define WOLFSSL_THREAD
14021406
#elif defined(FREERTOS)
14031407
typedef unsigned int THREAD_RETURN;
14041408
typedef TaskHandle_t THREAD_TYPE;

0 commit comments

Comments
 (0)