-
Notifications
You must be signed in to change notification settings - Fork 169
Add Musl import, error if unrecognised platform #325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,19 +13,23 @@ | |
import Darwin | ||
#elseif canImport(Glibc) | ||
import Glibc | ||
#elseif canImport(Musl) | ||
import Musl | ||
#elseif canImport(WinSDK) | ||
import WinSDK | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
|
||
internal struct Lock { | ||
#if canImport(Darwin) | ||
typealias Primitive = os_unfair_lock | ||
#elseif canImport(Glibc) | ||
#elseif canImport(Glibc) || canImport(Musl) | ||
typealias Primitive = pthread_mutex_t | ||
#elseif canImport(WinSDK) | ||
typealias Primitive = SRWLOCK | ||
#else | ||
typealias Primitive = Int | ||
#error("Unsupported platform") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From gitblame it seem like this was added for web assembly: swift-testing uses a combination of os(WASI) and _runtime(_multithreaded) combined with compiler(>=6.1) FWIW Mutex has just landed in Swift 6.0 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc: @0xpablo |
||
#endif | ||
|
||
typealias PlatformLock = UnsafeMutablePointer<Primitive> | ||
|
@@ -38,16 +42,18 @@ internal struct Lock { | |
fileprivate static func initialize(_ platformLock: PlatformLock) { | ||
#if canImport(Darwin) | ||
platformLock.initialize(to: os_unfair_lock()) | ||
#elseif canImport(Glibc) | ||
#elseif canImport(Glibc) || canImport(Musl) | ||
let result = pthread_mutex_init(platformLock, nil) | ||
precondition(result == 0, "pthread_mutex_init failed") | ||
#elseif canImport(WinSDK) | ||
InitializeSRWLock(platformLock) | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
fileprivate static func deinitialize(_ platformLock: PlatformLock) { | ||
#if canImport(Glibc) | ||
#if canImport(Glibc) || canImport(Musl) | ||
let result = pthread_mutex_destroy(platformLock) | ||
precondition(result == 0, "pthread_mutex_destroy failed") | ||
#endif | ||
|
@@ -57,21 +63,25 @@ internal struct Lock { | |
fileprivate static func lock(_ platformLock: PlatformLock) { | ||
#if canImport(Darwin) | ||
os_unfair_lock_lock(platformLock) | ||
#elseif canImport(Glibc) | ||
#elseif canImport(Glibc) || canImport(Musl) | ||
pthread_mutex_lock(platformLock) | ||
#elseif canImport(WinSDK) | ||
AcquireSRWLockExclusive(platformLock) | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
fileprivate static func unlock(_ platformLock: PlatformLock) { | ||
#if canImport(Darwin) | ||
os_unfair_lock_unlock(platformLock) | ||
#elseif canImport(Glibc) | ||
#elseif canImport(Glibc) || canImport(Musl) | ||
let result = pthread_mutex_unlock(platformLock) | ||
precondition(result == 0, "pthread_mutex_unlock failed") | ||
#elseif canImport(WinSDK) | ||
ReleaseSRWLockExclusive(platformLock) | ||
#else | ||
#error("Unsupported platform") | ||
#endif | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.