Skip to content

Commit cbb7c29

Browse files
committed
Improve gActiveTPM detection for needing thread local.
1 parent 5770675 commit cbb7c29

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

src/tpm2.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,26 @@
3737
/* --- Local Variables -- */
3838
/******************************************************************************/
3939

40-
41-
#ifdef WOLFTPM_NO_ACTIVE_THREAD_LS
42-
/* if using gHwLock and want to use a shared active TPM2_CTX between threads */
43-
static TPM2_CTX* gActiveTPM;
44-
#else
45-
static THREAD_LS_T TPM2_CTX* gActiveTPM;
46-
#endif
47-
4840
#ifndef WOLFTPM2_NO_WOLFCRYPT
4941
static volatile int gWolfCryptRefCount = 0;
5042
#endif
5143

5244
#if !defined(WOLFTPM2_NO_WOLFCRYPT) && !defined(WOLFTPM_NO_LOCK) && \
5345
!defined(SINGLE_THREADED)
46+
/* if a mutex lock is supported, then don't use thread local on gActiveTPM */
47+
#undef WOLFTPM_NO_ACTIVE_THREAD_LS
48+
#define WOLFTPM_NO_ACTIVE_THREAD_LS
49+
5450
static wolfSSL_Mutex gHwLock WOLFSSL_MUTEX_INITIALIZER_CLAUSE(gHwLock);
5551
#endif
5652

53+
#ifdef WOLFTPM_NO_ACTIVE_THREAD_LS
54+
/* if using gHwLock and want to use a shared active TPM2_CTX between threads */
55+
static TPM2_CTX* gActiveTPM;
56+
#else
57+
static THREAD_LS_T TPM2_CTX* gActiveTPM;
58+
#endif
59+
5760
#ifdef WOLFTPM_LINUX_DEV
5861
#define INTERNAL_SEND_COMMAND TPM2_LINUX_SendCommand
5962
#define TPM2_INTERNAL_CLEANUP(ctx)

0 commit comments

Comments
 (0)