Skip to content

Commit b1a6ce8

Browse files
authored
Merge pull request #2872 from apple/maxd/wasi-cfinternal
Add support for WASI in CFInternal.h
2 parents e7cbd3b + 2632819 commit b1a6ce8

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

CoreFoundation/Base.subproj/CFInternal.h

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ CF_EXTERN_C_BEGIN
104104
#include <stdatomic.h>
105105
#include <Block.h>
106106

107-
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
107+
#if TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
108108

109109
#if TARGET_OS_MAC || (TARGET_OS_BSD && !defined(__OpenBSD__)) || TARGET_OS_ANDROID
110110
#include <xlocale.h>
@@ -113,7 +113,7 @@ CF_EXTERN_C_BEGIN
113113
#include <sys/time.h>
114114
#include <signal.h>
115115
#include <stdio.h>
116-
#endif // TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD
116+
#endif // TARGET_OS_MAC || TARGET_OS_LINUX || TARGET_OS_BSD || TARGET_OS_WASI
117117

118118
#if __has_include(<unistd.h>)
119119
#include <unistd.h>
@@ -317,10 +317,18 @@ static inline void __CFRuntimeSetValue(CFTypeRef cf, uint8_t n1, uint8_t n2, uin
317317
__CFInfoType info = atomic_load(&(((CFRuntimeBase *)cf)->_cfinfoa));
318318
__CFInfoType newInfo;
319319
__CFInfoType mask = __CFInfoMask(n1, n2);
320+
321+
#if !TARGET_OS_WASI
320322
do {
323+
#endif
321324
// maybe don't need to do the negation part because the right side promises that we are not going to touch the rest of the word
322325
newInfo = (info & ~mask) | ((x << n2) & mask);
326+
// Atomics are not supported on WASI, see https://bugs.swift.org/browse/SR-12097 for more details
327+
#if !TARGET_OS_WASI
323328
} while (!atomic_compare_exchange_weak(&(((CFRuntimeBase *)cf)->_cfinfoa), &info, newInfo));
329+
#else
330+
((CFRuntimeBase *)cf)->_cfinfoa = newInfo;
331+
#endif
324332
}
325333

326334
/// Set a flag in a CFTypeRef info bitfield.
@@ -1024,7 +1032,7 @@ CF_INLINE const char *CFPathRelativeToAppleFrameworksRoot(const char *path, Bool
10241032
enum {
10251033
DISPATCH_QUEUE_OVERCOMMIT = 0x2ull,
10261034
};
1027-
#endif
1035+
#endif // __has_include(<dispatch/private.h>)
10281036

10291037
#if TARGET_OS_LINUX || TARGET_OS_WIN32
10301038
#define QOS_CLASS_USER_INITIATED DISPATCH_QUEUE_PRIORITY_HIGH
@@ -1040,7 +1048,7 @@ CF_INLINE long qos_class_self() {
10401048
return QOS_CLASS_DEFAULT;
10411049
}
10421050

1043-
#endif
1051+
#endif // TARGET_OS_LINUX || TARGET_OS_WIN32
10441052

10451053
// Returns a generic dispatch queue for when you want to just throw some work
10461054
// into the concurrent pile to execute, and don't care about specifics except
@@ -1064,12 +1072,13 @@ CF_INLINE dispatch_queue_t __CFDispatchQueueGetGenericBackground(void) {
10641072
return dispatch_get_global_queue(QOS_CLASS_UTILITY, DISPATCH_QUEUE_OVERCOMMIT);
10651073
}
10661074

1067-
#endif
1075+
CF_PRIVATE dispatch_data_t _CFDataCreateDispatchData(CFDataRef data); //avoids copying in most cases
1076+
1077+
#endif // __HAS_DISPATCH__
10681078

10691079
CF_PRIVATE CFStringRef _CFStringCopyBundleUnloadingProtectedString(CFStringRef str);
10701080

10711081
CF_PRIVATE uint8_t *_CFDataGetBytePtrNonObjC(CFDataRef data);
1072-
CF_PRIVATE dispatch_data_t _CFDataCreateDispatchData(CFDataRef data); //avoids copying in most cases
10731082

10741083
// Use this for functions that are intended to be breakpoint hooks. If you do not, the compiler may optimize them away.
10751084
// Based on: BREAKPOINT_FUNCTION in objc-os.h

0 commit comments

Comments
 (0)