Skip to content
Open
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
14 changes: 14 additions & 0 deletions Sources/Logging/Locks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ internal final class Lock: @unchecked Sendable {
#elseif os(Windows)
fileprivate let mutex: UnsafeMutablePointer<SRWLOCK> =
UnsafeMutablePointer.allocate(capacity: 1)
#elseif os(FreeBSD) || os(OpenBSD)
fileprivate let mutex: UnsafeMutablePointer<pthread_mutex_t?> =
UnsafeMutablePointer.allocate(capacity: 1)
#else
fileprivate let mutex: UnsafeMutablePointer<pthread_mutex_t> =
UnsafeMutablePointer.allocate(capacity: 1)
Expand All @@ -66,9 +69,17 @@ internal final class Lock: @unchecked Sendable {
#elseif os(Windows)
InitializeSRWLock(self.mutex)
#else
#if os(FreeBSD) || os(OpenBSD)
var attr = pthread_mutexattr_t(bitPattern: 0)
#else
var attr = pthread_mutexattr_t()
#endif
pthread_mutexattr_init(&attr)
#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)
precondition(err == 0, "\(#function) failed in pthread_mutex with error \(err)")
Expand Down Expand Up @@ -157,6 +168,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
8 changes: 8 additions & 0 deletions Sources/Logging/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1355,7 +1355,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 @@ -1375,7 +1379,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
2 changes: 2 additions & 0 deletions Tests/LoggingTests/TestLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,8 @@ public class MDC {
return Int(pthread_mach_thread_np(pthread_self()))
#elseif os(Windows)
return Int(GetCurrentThreadId())
#elseif os(FreeBSD) || os(OpenBSD)
return Int(pthread_getthreadid_np())
#else
return Int(pthread_self())
#endif
Expand Down
Loading