Replace the last CRITICAL_SECTION with SRWLOCK. We don't support Windows XP, so we can rely on SRWLOCK. Per https://crbug.com/592752, SRWLOCKs are more efficient and less of a hassle to use. We'd previously converted CRYPTO_MUTEX to SRWLOCK, but I missed this one. Not that this one lock matters much, may as well. It's less initialization code. Change-Id: I7ae435be5202b0a19f42015c9abff932dc04dbc7 Reviewed-on: https://boringssl-review.googlesource.com/c/33445 Commit-Queue: David Benjamin <davidben@google.com> Commit-Queue: Adam Langley <agl@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/thread_win.c b/crypto/thread_win.c index 4501165..c8e19f5 100644 --- a/crypto/thread_win.c +++ b/crypto/thread_win.c
@@ -82,7 +82,7 @@ ReleaseSRWLockExclusive(&lock->lock); } -static CRITICAL_SECTION g_destructors_lock; +static SRWLOCK g_destructors_lock = SRWLOCK_INIT; static thread_local_destructor_t g_destructors[NUM_OPENSSL_THREAD_LOCALS]; static CRYPTO_once_t g_thread_local_init_once = CRYPTO_ONCE_INIT; @@ -90,10 +90,6 @@ static int g_thread_local_failed; static void thread_local_init(void) { - if (!InitializeCriticalSectionAndSpinCount(&g_destructors_lock, 0x400)) { - g_thread_local_failed = 1; - return; - } g_thread_local_key = TlsAlloc(); g_thread_local_failed = (g_thread_local_key == TLS_OUT_OF_INDEXES); } @@ -121,12 +117,11 @@ thread_local_destructor_t destructors[NUM_OPENSSL_THREAD_LOCALS]; - EnterCriticalSection(&g_destructors_lock); + AcquireSRWLockExclusive(&g_destructors_lock); OPENSSL_memcpy(destructors, g_destructors, sizeof(destructors)); - LeaveCriticalSection(&g_destructors_lock); + ReleaseSRWLockExclusive(&g_destructors_lock); - unsigned i; - for (i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) { + for (unsigned i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) { if (destructors[i] != NULL) { destructors[i](pointers[i]); } @@ -250,9 +245,9 @@ } } - EnterCriticalSection(&g_destructors_lock); + AcquireSRWLockExclusive(&g_destructors_lock); g_destructors[index] = destructor; - LeaveCriticalSection(&g_destructors_lock); + ReleaseSRWLockExclusive(&g_destructors_lock); pointers[index] = value; return 1;