mirror of
https://github.com/apple/swift.git
synced 2026-10-16 16:50:49 +02:00
Under interface-LTO the Synchronization library's archive holds real code that clients must link against; under the default Inlinable model it's empty. Introduce a lit substitution that always adds `-lswiftSynchronization` and thread it through every executable embedded test that `import`s Synchronization. Harmless under default codegen (the archive is empty), load-bearing under interface-LTO.
38 lines
973 B
Swift
38 lines
973 B
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %target-swift-frontend -parse-as-library -enable-experimental-feature Embedded -disable-availability-checking -wmo %s -c -o %t/main.o
|
|
// RUN: %target-embedded-link %target-clang-resource-dir-opt %t/main.o %target-embedded-multi-threaded-posix-shim %target-embedded-synchronization -o %t/a.out -dead_strip
|
|
// RUN: %target-run %t/a.out | %FileCheck %s
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: optimized_stdlib
|
|
// REQUIRES: synchronization
|
|
// REQUIRES: OS=macosx || OS=linux-gnu || OS=wasip1
|
|
// REQUIRES: swift_feature_Embedded
|
|
|
|
import Synchronization
|
|
|
|
@main
|
|
struct Main {
|
|
static func main() {
|
|
let mutex = Mutex(0)
|
|
|
|
let first = mutex.withLock { value -> Int in
|
|
value += 1
|
|
return value
|
|
}
|
|
print(first)
|
|
// CHECK: 1
|
|
|
|
let second = mutex.withLockIfAvailable { value -> Int in
|
|
value += 41
|
|
return value
|
|
}
|
|
print(second ?? -1)
|
|
// CHECK: 42
|
|
|
|
print("done")
|
|
// CHECK: done
|
|
}
|
|
}
|