add thread local storage macro and make gActiveTPM local to the thread

pull/253/head
John Bland 2023-01-16 15:36:45 -05:00
parent a0bd9fef98
commit 1825b6f457
3 changed files with 20 additions and 1 deletions

View File

@ -64,6 +64,10 @@ AC_CHECK_SIZEOF([long], 4)
AC_CHECK_FUNCS([gethostbyname getaddrinfo gettimeofday inet_ntoa memset socket])
AC_CHECK_LIB([network],[socket])
# Thread local storage
AX_TLS([thread_ls_on=yes],[thread_ls_on=no])
AS_IF([test "x$thread_ls_on" = "xyes"],[AM_CFLAGS="$AM_CFLAGS -DHAVE_THREAD_LS"])
# DEBUG
DEBUG_CFLAGS="-g -O0 -DDEBUG_WOLFTPM"

View File

@ -32,7 +32,7 @@
/* --- Local Variables -- */
/******************************************************************************/
static TPM2_CTX* gActiveTPM;
static THREAD_LS_T TPM2_CTX* gActiveTPM;
#ifndef WOLFTPM2_NO_WOLFCRYPT
static volatile int gWolfCryptRefCount = 0;
#endif

View File

@ -189,6 +189,21 @@ typedef int64_t INT64;
#define XFEOF feof
#endif
/* set up thread local storage if available */
#ifdef HAVE_THREAD_LS
#if defined(_MSC_VER)
#define THREAD_LS_T __declspec(thread)
/* Thread local storage only in FreeRTOS v8.2.1 and higher */
#elif defined(FREERTOS) || defined(FREERTOS_TCP) || \
defined(WOLFSSL_ZEPHYR)
#define THREAD_LS_T
#else
#define THREAD_LS_T __thread
#endif
#else
#define THREAD_LS_T
#endif
#endif /* !WOLFTPM2_NO_WOLFCRYPT */
#ifndef WOLFTPM_CUSTOM_TYPES