Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Sources/Testing/Support/Locked+Platform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,14 @@ typealias DefaultLock = Never
#warning("Platform-specific implementation missing: locking unavailable")
typealias DefaultLock = Never
#endif

#if SWT_NO_DYNAMIC_LINKING
/// A function which, when called by another file, ensures that the file in
/// which ``DefaultLock`` is declared is linked.
///
/// When static linking is used, the linker may opt to strip some or all of the
/// symbols (including protocol conformance metadata) declared in this file.
/// ``LockedWith`` calls this function in ``LockedWith/init(rawValue:)`` to work
/// around that issue.
func linkLockImplementations() {}
#endif
4 changes: 4 additions & 0 deletions Sources/Testing/Support/Locked.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ struct LockedWith<L, T>: RawRepresentable where L: Lockable {
private nonisolated(unsafe) var _storage: ManagedBuffer<T, L>

init(rawValue: T) {
#if SWT_NO_DYNAMIC_LINKING
linkLockImplementations()
#endif

_storage = _Storage.create(minimumCapacity: 1, makingHeaderWith: { _ in rawValue })
_storage.withUnsafeMutablePointerToElements { lock in
L.initializeLock(at: lock)
Expand Down