Skip to content

Commit 8e5d2c9

Browse files
committed
[SR-6420] Ensure that the pthread_key is initialised once
1 parent c13b850 commit 8e5d2c9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

CoreFoundation/Base.subproj/CFPlatform.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,11 +580,16 @@ CF_PRIVATE void __CFFinalizeWindowsThreadData() {
580580
#endif
581581

582582
static pthread_key_t __CFTSDIndexKey;
583+
static pthread_once_t __CFTSDIndexKey_once = PTHREAD_ONCE_INIT;
583584

584-
CF_PRIVATE void __CFTSDInitialize() {
585+
CF_PRIVATE void __CFTSDInitializeOnce() {
585586
(void)pthread_key_create(&__CFTSDIndexKey, __CFTSDFinalize);
586587
}
587588

589+
CF_PRIVATE void __CFTSDInitialize() {
590+
(void)pthread_once(&__CFTSDIndexKey_once, __CFTSDInitializeOnce);
591+
}
592+
588593
static void __CFTSDSetSpecific(void *arg) {
589594
#if DEPLOYMENT_TARGET_MACOSX || DEPLOYMENT_TARGET_EMBEDDED || DEPLOYMENT_TARGET_EMBEDDED_MINI
590595
pthread_setspecific(__CFTSDIndexKey, arg);

0 commit comments

Comments
 (0)