forked from swiftlang/swift
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurrency-modules.swift
63 lines (47 loc) · 1.89 KB
/
concurrency-modules.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// RUN: %empty-directory(%t)
// RUN: %{python} %utils/split_file.py -o %t %s
// RUN: %target-swift-frontend -emit-module -o %t/MyModule.swiftmodule %t/MyModule.swift -enable-experimental-feature Embedded -parse-as-library
// RUN: %target-swift-frontend -c -I %t %t/Main.swift -enable-experimental-feature Embedded -o %t/a.o -parse-as-library
// RUN: %target-clang %t/a.o -o %t/a.out -L%swift_obj_root/lib/swift/embedded/%target-cpu-apple-macos -lswift_Concurrency -lswift_ConcurrencyDefaultExecutor -dead_strip
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: swift_in_compiler
// REQUIRES: executable_test
// REQUIRES: optimized_stdlib
// REQUIRES: OS=macosx
// REQUIRES: swift_feature_Embedded
// BEGIN MyModule.swift
import _Concurrency
nonisolated(unsafe)var glob:UnsafeMutableRawPointer?=nil
nonisolated(unsafe)var job:UnownedJob?=nil
publicfinalclassMyCustomExecutor:SerialExecutor,@uncheckedSendable{
privateinit(){}
nonisolated(unsafe)
publicstaticvarshared:MyCustomExecutor=MyCustomExecutor()
publicstaticfunc installGlobalExecutor(){
letfn:@convention(thin)()->()={
MyCustomExecutor.shared.unsafeEnqueue(job!)
}
glob =unsafeBitCast(fn, to:UnsafeMutableRawPointer?.self)
}
privatefunc enqueue(_ job:UnownedJob, withDelay nanoseconds:UInt64){}
privatefunc unsafeEnqueue(_ job:UnownedJob){
job.runSynchronously(on:self.asUnownedSerialExecutor())
}
publicfunc enqueue(_ job:consumingExecutorJob){
unsafeEnqueue(UnownedJob(job))
}
publicfunc asUnownedSerialExecutor()->UnownedSerialExecutor{
returnUnownedSerialExecutor(ordinary:self)
}
}
// BEGIN Main.swift
import MyModule
import _Concurrency
@main
structEntrypoint{
staticfunc main()async{
MyCustomExecutor.installGlobalExecutor()
print("OK!")
}
}
// CHECK: OK!