Files
swift-mirror/test/embedded/embedded-platform-multi-threaded-darwin-mutex.swift
Doug Gregor 48e60681f9 [Embedded tests] Add %target-embedded-synchronization substitution
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.
2026-07-14 11:56:50 -07:00

39 lines
982 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-darwin-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
// REQUIRES: swift_feature_Embedded
// REQUIRES: swift_embedded_platform
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
}
}