mirror of
https://github.com/apple/swift-async-algorithms
synced 2026-11-26 04:37:48 +00:00
Add precondition guards to pthread_mutex calls (#243)
While in the current configuration lock/unlock shouldn't ever fail, it seems polite to guard against basic misuse in debug builds. Co-authored-by: Dan Appel <dan_appel@apple.com>
This commit is contained in:
1 parent
aed5422380
commit
3f12423c47
1 file changed
+3
-3
@@ -37,7 +37,7 @@ internal struct Lock {
|
||||
#if canImport(Darwin)
|
||||
platformLock.initialize(to: os_unfair_lock())
|
||||
#elseif canImport(Glibc)
|
||||
pthread_mutex_init(platformLock, nil)
|
||||
precondition(pthread_mutex_init(platformLock, nil) == 0, "pthread_mutex_init failed")
|
||||
#elseif canImport(WinSDK)
|
||||
InitializeSRWLock(platformLock)
|
||||
#endif
|
||||
@@ -45,7 +45,7 @@ internal struct Lock {
|
||||
|
||||
fileprivate static func deinitialize(_ platformLock: PlatformLock) {
|
||||
#if canImport(Glibc)
|
||||
pthread_mutex_destroy(platformLock)
|
||||
precondition(pthread_mutex_destroy(platformLock) == 0, "pthread_mutex_destroy failed")
|
||||
#endif
|
||||
platformLock.deinitialize(count: 1)
|
||||
}
|
||||
@@ -64,7 +64,7 @@ internal struct Lock {
|
||||
#if canImport(Darwin)
|
||||
os_unfair_lock_unlock(platformLock)
|
||||
#elseif canImport(Glibc)
|
||||
pthread_mutex_unlock(platformLock)
|
||||
precondition(pthread_mutex_unlock(platformLock) == 0, "pthread_mutex_unlock failed")
|
||||
#elseif canImport(WinSDK)
|
||||
ReleaseSRWLockExclusive(platformLock)
|
||||
#endif
|
||||
|
||||
Reference in new issue
Block a user