Fix pthread use on FreeBSD (#253)

Much like OpenBSD, the FreeBSD pthread APIs are not imported with the
appropriate nullability annotations, so the base pthread mutex type
should be an optional value. Eventually we should provide API notes to
fix this issue, but that is not in place today.
See https://github.com/swiftlang/swift/issues/81407
This commit is contained in:
Evan Wilde authored and GitHub committed 2025-05-21 12:54:15 +01:00
1 parent b77cbe9d98
commit 9d7ff7720e
1 file changed
+3 -3
+3 -3
View File
@@ -35,7 +35,7 @@ import wasi_pthread
#if os(Windows)
@usableFromInline
typealias LockPrimitive = SRWLOCK
#elseif os(OpenBSD)
#elseif os(OpenBSD) || os(FreeBSD)
@usableFromInline
typealias LockPrimitive = pthread_mutex_t?
#else
@@ -54,14 +54,14 @@ extension LockOperations {
#if os(Windows)
InitializeSRWLock(mutex)
#elseif (compiler(<6.1) && !os(WASI)) || (compiler(>=6.1) && _runtime(_multithreaded))
#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
var attr = pthread_mutexattr_t(bitPattern: 0)
#else
var attr = pthread_mutexattr_t()
#endif
pthread_mutexattr_init(&attr)
debugOnly {
#if os(OpenBSD)
#if os(OpenBSD) || os(FreeBSD)
pthread_mutexattr_settype(&attr, .init(PTHREAD_MUTEX_ERRORCHECK.rawValue))
#else
pthread_mutexattr_settype(&attr, .init(PTHREAD_MUTEX_ERRORCHECK))