Skip to content

Commit 84af891

Browse files
Avoid using Synchronization in the JavaScriptEventLoop
It required us to update the minimum deployment target but it's not worth doing so just for this.
1 parent 7a6fdd9 commit 84af891

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

Sources/JavaScriptEventLoop/JavaScriptEventLoop.swift

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import JavaScriptKit
22
import _Concurrency
33
import _CJavaScriptEventLoop
44
import _CJavaScriptKit
5-
import Synchronization
65

76
// NOTE: `@available` annotations are semantically wrong, but they make it easier to develop applications targeting WebAssembly in Xcode.
87

@@ -106,7 +105,7 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
106105
return eventLoop
107106
}
108107

109-
private static let didInstallGlobalExecutor = Atomic<Bool>(false)
108+
private nonisolated(unsafe) static var didInstallGlobalExecutor = false
110109

111110
/// Set JavaScript event loop based executor to be the global executor
112111
/// Note that this should be called before any of the jobs are created.
@@ -118,9 +117,8 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
118117
}
119118

120119
private static func installGlobalExecutorIsolated() {
121-
guard !didInstallGlobalExecutor.load(ordering: .sequentiallyConsistent) else {
122-
return
123-
}
120+
guard !didInstallGlobalExecutor else { return }
121+
didInstallGlobalExecutor = true
124122

125123
#if compiler(>=5.9)
126124
typealias swift_task_asyncMainDrainQueue_hook_Fn = @convention(thin) (
@@ -189,8 +187,6 @@ public final class JavaScriptEventLoop: SerialExecutor, @unchecked Sendable {
189187
swift_task_enqueueMainExecutor_hook_impl,
190188
to: UnsafeMutableRawPointer?.self
191189
)
192-
193-
didInstallGlobalExecutor.store(true, ordering: .sequentiallyConsistent)
194190
}
195191

196192
private func enqueue(_ job: UnownedJob, withDelay nanoseconds: UInt64) {

0 commit comments

Comments
 (0)