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>
This commit is contained in:
parent
278b3120ee
commit
eb7d5b69e9
@ -82,7 +82,7 @@ void CRYPTO_STATIC_MUTEX_unlock_write(struct CRYPTO_STATIC_MUTEX *lock) {
|
|||||||
ReleaseSRWLockExclusive(&lock->lock);
|
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 thread_local_destructor_t g_destructors[NUM_OPENSSL_THREAD_LOCALS];
|
||||||
|
|
||||||
static CRYPTO_once_t g_thread_local_init_once = CRYPTO_ONCE_INIT;
|
static CRYPTO_once_t g_thread_local_init_once = CRYPTO_ONCE_INIT;
|
||||||
@ -90,10 +90,6 @@ static DWORD g_thread_local_key;
|
|||||||
static int g_thread_local_failed;
|
static int g_thread_local_failed;
|
||||||
|
|
||||||
static void thread_local_init(void) {
|
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_key = TlsAlloc();
|
||||||
g_thread_local_failed = (g_thread_local_key == TLS_OUT_OF_INDEXES);
|
g_thread_local_failed = (g_thread_local_key == TLS_OUT_OF_INDEXES);
|
||||||
}
|
}
|
||||||
@ -121,12 +117,11 @@ static void NTAPI thread_local_destructor(PVOID module, DWORD reason,
|
|||||||
|
|
||||||
thread_local_destructor_t destructors[NUM_OPENSSL_THREAD_LOCALS];
|
thread_local_destructor_t destructors[NUM_OPENSSL_THREAD_LOCALS];
|
||||||
|
|
||||||
EnterCriticalSection(&g_destructors_lock);
|
AcquireSRWLockExclusive(&g_destructors_lock);
|
||||||
OPENSSL_memcpy(destructors, g_destructors, sizeof(destructors));
|
OPENSSL_memcpy(destructors, g_destructors, sizeof(destructors));
|
||||||
LeaveCriticalSection(&g_destructors_lock);
|
ReleaseSRWLockExclusive(&g_destructors_lock);
|
||||||
|
|
||||||
unsigned i;
|
for (unsigned i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) {
|
||||||
for (i = 0; i < NUM_OPENSSL_THREAD_LOCALS; i++) {
|
|
||||||
if (destructors[i] != NULL) {
|
if (destructors[i] != NULL) {
|
||||||
destructors[i](pointers[i]);
|
destructors[i](pointers[i]);
|
||||||
}
|
}
|
||||||
@ -250,9 +245,9 @@ int CRYPTO_set_thread_local(thread_local_data_t index, void *value,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EnterCriticalSection(&g_destructors_lock);
|
AcquireSRWLockExclusive(&g_destructors_lock);
|
||||||
g_destructors[index] = destructor;
|
g_destructors[index] = destructor;
|
||||||
LeaveCriticalSection(&g_destructors_lock);
|
ReleaseSRWLockExclusive(&g_destructors_lock);
|
||||||
|
|
||||||
pointers[index] = value;
|
pointers[index] = value;
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user