diff --git a/Sources/Logging/Locks.swift b/Sources/Logging/Locks.swift index 1e90d8c..70bf5f3 100644 --- a/Sources/Logging/Locks.swift +++ b/Sources/Logging/Locks.swift @@ -58,7 +58,7 @@ package final class Lock { #if os(Windows) fileprivate let mutex: UnsafeMutablePointer = UnsafeMutablePointer.allocate(capacity: 1) - #elseif os(OpenBSD) + #elseif os(FreeBSD) || os(OpenBSD) fileprivate let mutex: UnsafeMutablePointer = UnsafeMutablePointer.allocate(capacity: 1) #else @@ -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) @@ -176,6 +180,9 @@ internal final class ReadWriteLock: @unchecked Sendable { fileprivate let rwlock: UnsafeMutablePointer = UnsafeMutablePointer.allocate(capacity: 1) fileprivate var shared: Bool = true + #elseif os(FreeBSD) || os(OpenBSD) + fileprivate let rwlock: UnsafeMutablePointer = + UnsafeMutablePointer.allocate(capacity: 1) #else fileprivate let rwlock: UnsafeMutablePointer = UnsafeMutablePointer.allocate(capacity: 1) diff --git a/Sources/Logging/Logging.swift b/Sources/Logging/Logging.swift index 66569b4..bcbecce 100644 --- a/Sources/Logging/Logging.swift +++ b/Sources/Logging/Logging.swift @@ -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 @@ -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) @@ -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) diff --git a/Tests/LoggingTests/TestLogger.swift b/Tests/LoggingTests/TestLogger.swift index 7d6258a..fc77249 100644 --- a/Tests/LoggingTests/TestLogger.swift +++ b/Tests/LoggingTests/TestLogger.swift @@ -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