Skip to content

Commit ba37ea4

Browse files
Gate pthread usage on wasip1-threads
1 parent 69b0f49 commit ba37ea4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Sources/JavaScriptEventLoop/WebWorkerTaskExecutor.swift

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.0+
1+
#if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.1+
22

33
import JavaScriptKit
44
import _CJavaScriptKit
@@ -274,6 +274,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
274274
}
275275

276276
func start(timeout: Duration, checkInterval: Duration) async throws {
277+
#if canImport(wasi_pthread)
277278
class Context: @unchecked Sendable {
278279
let executor: WebWorkerTaskExecutor.Executor
279280
let worker: Worker
@@ -316,6 +317,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
316317
} while tid == 0
317318
swjs_listen_message_from_worker_thread(tid)
318319
}
320+
#else
321+
fatalError("Unsupported platform")
322+
#endif
319323
}
320324

321325
func terminate() {
@@ -420,6 +424,7 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
420424
///
421425
/// This function must be called once before using the Web Worker task executor.
422426
public static func installGlobalExecutor() {
427+
#if canImport(wasi_pthread)
423428
// Ensure this function is called only once.
424429
guard _mainThread == nil else { return }
425430

@@ -448,6 +453,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
448453
}
449454
}
450455
swift_task_enqueueGlobal_hook = unsafeBitCast(swift_task_enqueueGlobal_hook_impl, to: UnsafeMutableRawPointer?.self)
456+
#else
457+
fatalError("Unsupported platform")
458+
#endif
451459
}
452460
}
453461

0 commit comments

Comments
 (0)