1
- #if compiler(>=6.1) && _runtime(_multithreaded) // @_expose and @_extern are only available in Swift 6.1+
1
+ #if compiler(>=6.0) // `TaskExecutor` is available since Swift 6.0
2
2
3
3
import JavaScriptKit
4
4
import _CJavaScriptKit
5
5
import _CJavaScriptEventLoop
6
6
7
- import Synchronization
7
+ #if canImport(Synchronization)
8
+ import Synchronization
9
+ #endif
8
10
#if canImport(wasi_pthread)
9
11
import wasi_pthread
10
12
import WASILibc
@@ -471,7 +473,9 @@ public final class WebWorkerTaskExecutor: TaskExecutor {
471
473
/// Enqueue a job scheduled from a Web Worker thread to the main thread.
472
474
/// This function is called when a job is enqueued from a Web Worker thread.
473
475
@available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
476
+ #if compiler(>=6.1) // @_expose and @_extern are only available in Swift 6.1+
474
477
@_expose ( wasm, " swjs_enqueue_main_job_from_worker " )
478
+ #endif
475
479
func _swjs_enqueue_main_job_from_worker( _ job: UnownedJob ) {
476
480
WebWorkerTaskExecutor . traceStatsIncrement ( \. receiveJobFromWorkerThread)
477
481
JavaScriptEventLoop . shared. enqueue ( ExecutorJob ( job) )
@@ -480,15 +484,17 @@ func _swjs_enqueue_main_job_from_worker(_ job: UnownedJob) {
480
484
/// Wake up the worker thread.
481
485
/// This function is called when a job is enqueued from the main thread to a worker thread.
482
486
@available ( macOS 15 . 0 , iOS 18 . 0 , watchOS 11 . 0 , tvOS 18 . 0 , visionOS 2 . 0 , * )
487
+ #if compiler(>=6.1) // @_expose and @_extern are only available in Swift 6.1+
483
488
@_expose ( wasm, " swjs_wake_worker_thread " )
489
+ #endif
484
490
func _swjs_wake_worker_thread( ) {
485
491
WebWorkerTaskExecutor . Worker. currentThread!. run ( )
486
492
}
487
493
488
- #endif
489
-
490
494
fileprivate func trace( _ message: String ) {
491
495
#if JAVASCRIPTKIT_TRACE
492
496
JSObject . global. process. stdout. write ( " [trace tid= \( swjs_get_worker_thread_id ( ) ) ] \( message) \n " )
493
497
#endif
494
498
}
499
+
500
+ #endif // compiler(>=6.0)
0 commit comments