mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-24 04:17:52 +00:00
Extract the result to test the preconditions seperate from the function calls for locking (#244)
This commit is contained in:
1 parent
3f12423c47
commit
e7b9b6039d
1 file changed
+6
-3
@@ -37,7 +37,8 @@ internal struct Lock {
|
||||
#if canImport(Darwin)
|
||||
platformLock.initialize(to: os_unfair_lock())
|
||||
#elseif canImport(Glibc)
|
||||
precondition(pthread_mutex_init(platformLock, nil) == 0, "pthread_mutex_init failed")
|
||||
let result = pthread_mutex_init(platformLock, nil)
|
||||
precondition(result == 0, "pthread_mutex_init failed")
|
||||
#elseif canImport(WinSDK)
|
||||
InitializeSRWLock(platformLock)
|
||||
#endif
|
||||
@@ -45,7 +46,8 @@ internal struct Lock {
|
||||
|
||||
fileprivate static func deinitialize(_ platformLock: PlatformLock) {
|
||||
#if canImport(Glibc)
|
||||
precondition(pthread_mutex_destroy(platformLock) == 0, "pthread_mutex_destroy failed")
|
||||
let result = pthread_mutex_destroy(platformLock)
|
||||
precondition(result == 0, "pthread_mutex_destroy failed")
|
||||
#endif
|
||||
platformLock.deinitialize(count: 1)
|
||||
}
|
||||
@@ -64,7 +66,8 @@ internal struct Lock {
|
||||
#if canImport(Darwin)
|
||||
os_unfair_lock_unlock(platformLock)
|
||||
#elseif canImport(Glibc)
|
||||
precondition(pthread_mutex_unlock(platformLock) == 0, "pthread_mutex_unlock failed")
|
||||
let result = pthread_mutex_unlock(platformLock)
|
||||
precondition(result == 0, "pthread_mutex_unlock failed")
|
||||
#elseif canImport(WinSDK)
|
||||
ReleaseSRWLockExclusive(platformLock)
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user