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
17 changes: 12 additions & 5 deletions Sources/Logging/Locks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ package final class Lock {
#if os(Windows)
fileprivate let mutex: UnsafeMutablePointer<SRWLOCK> =
UnsafeMutablePointer.allocate(capacity: 1)
#elseif os(OpenBSD)
#elseif os(FreeBSD) || os(OpenBSD)
fileprivate let mutex: UnsafeMutablePointer<pthread_mutex_t?> =
UnsafeMutablePointer.allocate(capacity: 1)
#else
Expand All @@ -70,15 +70,19 @@ package final class Lock {
package init() {
#if os(Windows)
InitializeSRWLock(self.mutex)
#elseif os(OpenBSD)
var attr = pthread_mutexattr_t(bitPattern: 0)
let err = pthread_mutex_init(self.mutex, &attr)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
#elseif (compiler(<6.1) && !os(WASI)) || (compiler(>=6.1) && _runtime(_multithreaded))
#if os(FreeBSD) || os(OpenBSD)
var attr = pthread_mutexattr_t(bitPattern: 0)
#else
var attr = pthread_mutexattr_t()
#endif
pthread_mutexattr_init(&attr)
debugOnly {
#if os(FreeBSD) || os(OpenBSD)
pthread_mutexattr_settype(&attr, .init(PTHREAD_MUTEX_ERRORCHECK.rawValue))
#else
pthread_mutexattr_settype(&attr, .init(PTHREAD_MUTEX_ERRORCHECK))
#endif
}

let err = pthread_mutex_init(self.mutex, &attr)
Expand Down Expand Up @@ -176,6 +180,9 @@ internal final class ReadWriteLock: @unchecked Sendable {
fileprivate let rwlock: UnsafeMutablePointer<SRWLOCK> =
UnsafeMutablePointer.allocate(capacity: 1)
fileprivate var shared: Bool = true
#elseif os(FreeBSD) || os(OpenBSD)
fileprivate let rwlock: UnsafeMutablePointer<pthread_rwlock_t?> =
UnsafeMutablePointer.allocate(capacity: 1)
#else
fileprivate let rwlock: UnsafeMutablePointer<pthread_rwlock_t> =
UnsafeMutablePointer.allocate(capacity: 1)
Expand Down
10 changes: 9 additions & 1 deletion Sources/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1388,7 +1388,7 @@ public struct MultiplexLogHandler: LogHandler {
}
}

#if canImport(WASILibc) || os(Android)
#if canImport(WASILibc) || os(Android) || os(OpenBSD)
internal typealias CFilePointer = OpaquePointer
#else
internal typealias CFilePointer = UnsafeMutablePointer<FILE>
Expand Down Expand Up @@ -1444,7 +1444,11 @@ internal struct StdioOutputStream: TextOutputStream, @unchecked Sendable {
#elseif os(Windows)
let systemStderr = CRT.stderr
#elseif canImport(Glibc)
#if os(FreeBSD) || os(OpenBSD)
let systemStderr = Glibc.stderr
#else
let systemStderr = Glibc.stderr!
#endif
#elseif canImport(Android)
let systemStderr = Android.stderr
#elseif canImport(Musl)
Expand All @@ -1464,7 +1468,11 @@ internal struct StdioOutputStream: TextOutputStream, @unchecked Sendable {
#elseif os(Windows)
let systemStdout = CRT.stdout
#elseif canImport(Glibc)
#if os(FreeBSD) || os(OpenBSD)
let systemStdout = Glibc.stdout
#else
let systemStdout = Glibc.stdout!
#endif
#elseif canImport(Android)
let systemStdout = Android.stdout
#elseif canImport(Musl)
Expand Down
4 changes: 4 additions & 0 deletions Tests/LoggingTests/TestLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,10 @@ public class MDC {
return Int(pthread_mach_thread_np(pthread_self()))
#elseif os(Windows)
return Int(GetCurrentThreadId())
#elseif os(FreeBSD)
return Int(pthread_getthreadid_np())
#elseif os(OpenBSD)
return Int(bitPattern: pthread_self())
#else
return Int(pthread_self())
#endif
Expand Down
Loading