Skip to content

Commit 09b72f6

Browse files
authored
Improve precondition error messages in Lock functions (#58)
This commit adds error messages to the precondition checks in Lock functions that state the action that failed as well as the OS error code.
1 parent f1514a4 commit 09b72f6

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Sources/CoreMetrics/Locks.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ internal final class Lock {
4343
/// Create a new lock.
4444
public init() {
4545
let err = pthread_mutex_init(self.mutex, nil)
46-
precondition(err == 0)
46+
precondition(err == 0, "pthread_mutex_init failed with error \(err)")
4747
}
4848

4949
deinit {
5050
let err = pthread_mutex_destroy(self.mutex)
51-
precondition(err == 0)
51+
precondition(err == 0, "pthread_mutex_destroy failed with error \(err)")
5252
self.mutex.deallocate()
5353
}
5454

@@ -58,7 +58,7 @@ internal final class Lock {
5858
/// `unlock`, to simplify lock handling.
5959
public func lock() {
6060
let err = pthread_mutex_lock(self.mutex)
61-
precondition(err == 0)
61+
precondition(err == 0, "pthread_mutex_lock failed with error \(err)")
6262
}
6363

6464
/// Release the lock.
@@ -67,7 +67,7 @@ internal final class Lock {
6767
/// `lock`, to simplify lock handling.
6868
public func unlock() {
6969
let err = pthread_mutex_unlock(self.mutex)
70-
precondition(err == 0)
70+
precondition(err == 0, "pthread_mutex_unlock failed with error \(err)")
7171
}
7272
}
7373

@@ -107,12 +107,12 @@ internal final class ReadWriteLock {
107107
/// Create a new lock.
108108
public init() {
109109
let err = pthread_rwlock_init(self.rwlock, nil)
110-
precondition(err == 0)
110+
precondition(err == 0, "pthread_rwlock_init failed with error \(err)")
111111
}
112112

113113
deinit {
114114
let err = pthread_rwlock_destroy(self.rwlock)
115-
precondition(err == 0)
115+
precondition(err == 0, "pthread_rwlock_destroy failed with error \(err)")
116116
self.rwlock.deallocate()
117117
}
118118

@@ -122,7 +122,7 @@ internal final class ReadWriteLock {
122122
/// `unlock`, to simplify lock handling.
123123
public func lockRead() {
124124
let err = pthread_rwlock_rdlock(self.rwlock)
125-
precondition(err == 0)
125+
precondition(err == 0, "pthread_rwlock_rdlock failed with error \(err)")
126126
}
127127

128128
/// Acquire a writer lock.
@@ -131,7 +131,7 @@ internal final class ReadWriteLock {
131131
/// `unlock`, to simplify lock handling.
132132
public func lockWrite() {
133133
let err = pthread_rwlock_wrlock(self.rwlock)
134-
precondition(err == 0)
134+
precondition(err == 0, "pthread_rwlock_wrlock failed with error \(err)")
135135
}
136136

137137
/// Release the lock.
@@ -140,7 +140,7 @@ internal final class ReadWriteLock {
140140
/// `lock`, to simplify lock handling.
141141
public func unlock() {
142142
let err = pthread_rwlock_unlock(self.rwlock)
143-
precondition(err == 0)
143+
precondition(err == 0, "pthread_rwlock_unlock failed with error \(err)")
144144
}
145145
}
146146

0 commit comments

Comments
 (0)