From 7bfa2dcb7f2c55f43e53c3e4915037c0bd081efc Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 3 Sep 2020 11:29:33 +0100 Subject: [PATCH 1/2] Add locking primitives for TARGET_OS_WASI in CFLocking.h WebAssembly/WASI doesn't support multi-threading yet, so these primitives don't do anything in this single-threaded environment, but allow the rest of the code using them to compile. --- CoreFoundation/Base.subproj/CFLocking.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/CoreFoundation/Base.subproj/CFLocking.h b/CoreFoundation/Base.subproj/CFLocking.h index ebe8539cda..4fe85937d4 100644 --- a/CoreFoundation/Base.subproj/CFLocking.h +++ b/CoreFoundation/Base.subproj/CFLocking.h @@ -96,6 +96,20 @@ typedef CFLock_t OSSpinLock; #define OSSpinLockLock(lock) __CFLock(lock) #define OSSpinLockUnlock(lock) __CFUnlock(lock) +#elif TARGET_OS_WASI +typedef int32_t CFLock_t; +typedef CFLock_t OSSpinLock; +#define CFLockInit 0 +#define CF_LOCK_INIT_FOR_STRUCTS(X) (X = CFLockInit) +#define OS_SPINLOCK_INIT CFLockInit + +#define OSSpinLockLock(lock) __CFLock(lock) +#define OSSpinLockUnlock(lock) __CFUnlock(lock) +#define __CFLock(A) do {} while (0) +#define __CFUnlock(A) do {} while (0) + +static inline CFLock_t __CFLockInit(void) { return CFLockInit; } + #else #warning CF locks not defined for this platform -- CF is not thread-safe From acbecae047cdd59866a68966a9ab07597748bfe1 Mon Sep 17 00:00:00 2001 From: Max Desiatov Date: Thu, 3 Sep 2020 11:31:43 +0100 Subject: [PATCH 2/2] Add a clarifying comment with a link to bugs.swift.org --- CoreFoundation/Base.subproj/CFLocking.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CoreFoundation/Base.subproj/CFLocking.h b/CoreFoundation/Base.subproj/CFLocking.h index 4fe85937d4..10da46f2cd 100644 --- a/CoreFoundation/Base.subproj/CFLocking.h +++ b/CoreFoundation/Base.subproj/CFLocking.h @@ -97,6 +97,8 @@ typedef CFLock_t OSSpinLock; #define OSSpinLockUnlock(lock) __CFUnlock(lock) #elif TARGET_OS_WASI + +// Empty shims until https://bugs.swift.org/browse/SR-12097 is resolved. typedef int32_t CFLock_t; typedef CFLock_t OSSpinLock; #define CFLockInit 0