Skip to content

Commit

Permalink
Gate the use of _runtime(_multithreaded) with compiler(>=6.1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Nov 28, 2024
1 parent a05e798 commit 9a141cb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions Sources/JavaScriptKit/FundamentalObjects/JSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class JSObject: Equatable {
@_spi(JSObject_id)
public var id: JavaScriptObjectRef

#if _runtime(_multithreaded)
#if compiler(>=6.1) && _runtime(_multithreaded)
private let ownerThread: pthread_t
#endif

Expand All @@ -47,14 +47,14 @@ public class JSObject: Equatable {
/// is a programmer error and will result in a runtime assertion failure because JavaScript
/// object spaces are not shared across threads backed by Web Workers.
private func assertOnOwnerThread(hint: @autoclosure () -> String) {
#if _runtime(_multithreaded)
#if compiler(>=6.1) && _runtime(_multithreaded)
precondition(pthread_equal(ownerThread, pthread_self()) != 0, "JSObject is being accessed from a thread other than the owner thread: \(hint())")
#endif
}

/// Asserts that the two objects being compared are owned by the same thread.
private static func assertSameOwnerThread(lhs: JSObject, rhs: JSObject, hint: @autoclosure () -> String) {
#if _runtime(_multithreaded)
#if compiler(>=6.1) && _runtime(_multithreaded)
precondition(pthread_equal(lhs.ownerThread, rhs.ownerThread) != 0, "JSObject is being accessed from a thread other than the owner thread: \(hint())")
#endif
}
Expand Down Expand Up @@ -206,7 +206,7 @@ public class JSObject: Equatable {

// `JSObject` storage itself is immutable, and use of `JSObject.global` from other
// threads maintains the same semantics as `globalThis` in JavaScript.
#if _runtime(_multithreaded)
#if compiler(>=6.1) && _runtime(_multithreaded)
@LazyThreadLocal(initialize: {
return JSObject(id: _JS_Predef_Value_Global)
})
Expand Down
2 changes: 1 addition & 1 deletion Sources/JavaScriptKit/ThreadLocal.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if _runtime(_multithreaded)
#if compiler(>=6.1) && _runtime(_multithreaded)
#if canImport(wasi_pthread)
import wasi_pthread
#elseif canImport(Darwin)
Expand Down

0 comments on commit 9a141cb

Please sign in to comment.