feat: add FreeBSD pthread support to NIOLock#170
Open
max-potapov wants to merge 1 commit into
Open
Conversation
### Motivation: NIOLock's pthread fallback branch types LockPrimitive as pthread_mutex_t and initializes pthread_mutexattr_t with a default initializer; both compile on Linux but fail on FreeBSD/OpenBSD where those types are opaque-pointer typedefs imported as Optional<OpaquePointer>. Additionally, PTHREAD_MUTEX_ERRORCHECK is imported as a pthread_mutextype enum case on FreeBSD whose .rawValue must be used to construct the CInt that pthread_mutexattr_settype expects. ### Modifications: Mirror the pattern landed in apple/swift-log#387: - alias LockPrimitive to pthread_mutex_t? on FreeBSD/OpenBSD - initialize pthread_mutexattr_t via the bitPattern overload - on FreeBSD/OpenBSD, access PTHREAD_MUTEX_ERRORCHECK via .rawValue before passing to pthread_mutexattr_settype ### Result: swift-prometheus compiles on FreeBSD with the official Swift FreeBSD preview toolchain.
FranzBusch
approved these changes
May 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
NIOLock's pthread fallback branch typesLockPrimitiveaspthread_mutex_tand initializespthread_mutexattr_twith a defaultinitializer; both compile on Linux but fail on FreeBSD / OpenBSD where
those types are opaque-pointer typedefs imported as
Optional<OpaquePointer>. Additionally,PTHREAD_MUTEX_ERRORCHECKisimported as a
pthread_mutextypeenum case on FreeBSD whose.rawValuemust be used to construct the
CIntthatpthread_mutexattr_settypeexpects.
This blocks swift-prometheus from compiling on FreeBSD with the
official Swift FreeBSD preview toolchain.
Modifications
Mirror the pattern landed in apple/swift-log#387; same fix is
being submitted for the sibling NIOLock copies in
apple/swift-http-types#123 and
swift-server/swift-service-lifecycle:
os(FreeBSD) || os(OpenBSD)aliasLockPrimitivetopthread_mutex_t?.pthread_mutexattr_tvia thebitPattern:overload.os(FreeBSD) || os(OpenBSD), accessPTHREAD_MUTEX_ERRORCHECKvia
.rawValuebefore passing topthread_mutexattr_settype.Touches one file (
Sources/Prometheus/NIOLock.swift), +11 lines, allbehind FreeBSD/OpenBSD conditionals. No behaviour change on existing
platforms.
Result
swift buildandswift testboth clean on FreeBSD 15.0 with theofficial Swift FreeBSD preview toolchain:
Without this change
Prometheusfails to compile on the sametoolchain.
Checks
behind
#if os(FreeBSD) || os(OpenBSD)).6.3-dev preview toolchain.
apple/swift-http-types#123.
convention (
feat: ...).