Skip to content

Commit de25f64

Browse files
authored
Fix some typos in the new FreeBSD-specific code. (#871)
Fixes some typos/code style bits and renames `withUnsafeUnderlyingLock()` to `withUnsafePlatformLock()` to make it more consistent with the newly-exposed `PlatformLock` typealias. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 591dc82 commit de25f64

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

Sources/Testing/ExitTests/SpawnProcess.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,11 @@ func spawnExecutable(
150150
// these file descriptors.
151151
_ = swt_posix_spawn_file_actions_addclosefrom_np(fileActions, highestFD + 1)
152152
#elseif os(FreeBSD)
153-
// Like Linux, this platfrom doesn't have POSIX_SPAWN_CLOEXEC_DEFAULT;
154-
// However; unlike Linux, all non-EOL FreeBSD (>= 13.1) supports
155-
// `posix_spawn_file_actions_addclosefrom_np` and therefore we don't need
156-
// need `swt_posix_spawn_file_actions_addclosefrom_np` to guard the availability
157-
// of this api.
153+
// Like Linux, this platform doesn't have POSIX_SPAWN_CLOEXEC_DEFAULT.
154+
// Unlike Linux, all non-EOL FreeBSD versions (≥13.1) support
155+
// `posix_spawn_file_actions_addclosefrom_np`. Therefore, we don't need
156+
// `swt_posix_spawn_file_actions_addclosefrom_np` to guard the
157+
// availability of this function.
158158
_ = posix_spawn_file_actions_addclosefrom_np(fileActions, highestFD + 1)
159159
#else
160160
#warning("Platform-specific implementation missing: cannot close unused file descriptors")

Sources/Testing/ExitTests/WaitFor.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ private let _childProcessContinuations = Locked<[pid_t: CheckedContinuation<Exit
8585
/// A condition variable used to suspend the waiter thread created by
8686
/// `_createWaitThread()` when there are no child processes to await.
8787
private nonisolated(unsafe) let _waitThreadNoChildrenCondition = {
88-
#if os(FreeBSD)
88+
#if os(FreeBSD)
8989
let result = UnsafeMutablePointer<pthread_cond_t?>.allocate(capacity: 1)
90-
#else
90+
#else
9191
let result = UnsafeMutablePointer<pthread_cond_t>.allocate(capacity: 1)
92-
#endif
92+
#endif
9393
_ = pthread_cond_init(result, nil)
9494
return result
9595
}()
@@ -126,7 +126,7 @@ private let _createWaitThread: Void = {
126126
// newly-scheduled waiter process. (If this condition is spuriously
127127
// woken, we'll just loop again, which is fine.) Note that we read errno
128128
// outside the lock in case acquiring the lock perturbs it.
129-
_childProcessContinuations.withUnsafeUnderlyingLock { lock, childProcessContinuations in
129+
_childProcessContinuations.withUnsafePlatformLock { lock, childProcessContinuations in
130130
if childProcessContinuations.isEmpty {
131131
_ = pthread_cond_wait(_waitThreadNoChildrenCondition, lock)
132132
}

Sources/Testing/Support/Locked.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
123123
}
124124
}
125125

126-
#if SWT_TARGET_OS_APPLE || os(Linux) || os(FreeBSD) || os(Android) || (os(WASI) && compiler(>=6.1) && _runtime(_multithreaded))
127126
/// Acquire the lock and invoke a function while it is held, yielding both the
128127
/// protected value and a reference to the lock itself.
129128
///
@@ -144,14 +143,13 @@ struct Locked<T>: RawRepresentable, Sendable where T: Sendable {
144143
/// - Warning: Callers that unlock the lock _must_ lock it again before the
145144
/// closure returns. If the lock is not acquired when `body` returns, the
146145
/// effect is undefined.
147-
nonmutating func withUnsafeUnderlyingLock<R>(_ body: (UnsafeMutablePointer<PlatformLock>, T) throws -> R) rethrows -> R {
146+
nonmutating func withUnsafePlatformLock<R>(_ body: (UnsafeMutablePointer<PlatformLock>, T) throws -> R) rethrows -> R {
148147
try withLock { value in
149148
try _storage.withUnsafeMutablePointerToElements { lock in
150149
try body(lock, value)
151150
}
152151
}
153152
}
154-
#endif
155153
}
156154

157155
extension Locked where T: AdditiveArithmetic {

0 commit comments

Comments
 (0)