Skip to content

Commit 3f12423

Browse files
DanappelxxDan Appel
and
Dan Appel
authored
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 <[email protected]>
1 parent aed5422 commit 3f12423

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Sources/AsyncAlgorithms/Locking.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ internal struct Lock {
3737
#if canImport(Darwin)
3838
platformLock.initialize(to: os_unfair_lock())
3939
#elseif canImport(Glibc)
40-
pthread_mutex_init(platformLock, nil)
40+
precondition(pthread_mutex_init(platformLock, nil) == 0, "pthread_mutex_init failed")
4141
#elseif canImport(WinSDK)
4242
InitializeSRWLock(platformLock)
4343
#endif
4444
}
4545

4646
fileprivate static func deinitialize(_ platformLock: PlatformLock) {
4747
#if canImport(Glibc)
48-
pthread_mutex_destroy(platformLock)
48+
precondition(pthread_mutex_destroy(platformLock) == 0, "pthread_mutex_destroy failed")
4949
#endif
5050
platformLock.deinitialize(count: 1)
5151
}
@@ -64,7 +64,7 @@ internal struct Lock {
6464
#if canImport(Darwin)
6565
os_unfair_lock_unlock(platformLock)
6666
#elseif canImport(Glibc)
67-
pthread_mutex_unlock(platformLock)
67+
precondition(pthread_mutex_unlock(platformLock) == 0, "pthread_mutex_unlock failed")
6868
#elseif canImport(WinSDK)
6969
ReleaseSRWLockExclusive(platformLock)
7070
#endif

0 commit comments

Comments
 (0)