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.
This commit is contained in:
parent
f1514a4c74
commit
09b72f68ed
|
|
@ -43,12 +43,12 @@ internal final class Lock {
|
||||||
/// Create a new lock.
|
/// Create a new lock.
|
||||||
public init() {
|
public init() {
|
||||||
let err = pthread_mutex_init(self.mutex, nil)
|
let err = pthread_mutex_init(self.mutex, nil)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_mutex_init failed with error \(err)")
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
let err = pthread_mutex_destroy(self.mutex)
|
let err = pthread_mutex_destroy(self.mutex)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_mutex_destroy failed with error \(err)")
|
||||||
self.mutex.deallocate()
|
self.mutex.deallocate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +58,7 @@ internal final class Lock {
|
||||||
/// `unlock`, to simplify lock handling.
|
/// `unlock`, to simplify lock handling.
|
||||||
public func lock() {
|
public func lock() {
|
||||||
let err = pthread_mutex_lock(self.mutex)
|
let err = pthread_mutex_lock(self.mutex)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_mutex_lock failed with error \(err)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Release the lock.
|
/// Release the lock.
|
||||||
|
|
@ -67,7 +67,7 @@ internal final class Lock {
|
||||||
/// `lock`, to simplify lock handling.
|
/// `lock`, to simplify lock handling.
|
||||||
public func unlock() {
|
public func unlock() {
|
||||||
let err = pthread_mutex_unlock(self.mutex)
|
let err = pthread_mutex_unlock(self.mutex)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_mutex_unlock failed with error \(err)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -107,12 +107,12 @@ internal final class ReadWriteLock {
|
||||||
/// Create a new lock.
|
/// Create a new lock.
|
||||||
public init() {
|
public init() {
|
||||||
let err = pthread_rwlock_init(self.rwlock, nil)
|
let err = pthread_rwlock_init(self.rwlock, nil)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_rwlock_init failed with error \(err)")
|
||||||
}
|
}
|
||||||
|
|
||||||
deinit {
|
deinit {
|
||||||
let err = pthread_rwlock_destroy(self.rwlock)
|
let err = pthread_rwlock_destroy(self.rwlock)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_rwlock_destroy failed with error \(err)")
|
||||||
self.rwlock.deallocate()
|
self.rwlock.deallocate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +122,7 @@ internal final class ReadWriteLock {
|
||||||
/// `unlock`, to simplify lock handling.
|
/// `unlock`, to simplify lock handling.
|
||||||
public func lockRead() {
|
public func lockRead() {
|
||||||
let err = pthread_rwlock_rdlock(self.rwlock)
|
let err = pthread_rwlock_rdlock(self.rwlock)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_rwlock_rdlock failed with error \(err)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Acquire a writer lock.
|
/// Acquire a writer lock.
|
||||||
|
|
@ -131,7 +131,7 @@ internal final class ReadWriteLock {
|
||||||
/// `unlock`, to simplify lock handling.
|
/// `unlock`, to simplify lock handling.
|
||||||
public func lockWrite() {
|
public func lockWrite() {
|
||||||
let err = pthread_rwlock_wrlock(self.rwlock)
|
let err = pthread_rwlock_wrlock(self.rwlock)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_rwlock_wrlock failed with error \(err)")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Release the lock.
|
/// Release the lock.
|
||||||
|
|
@ -140,7 +140,7 @@ internal final class ReadWriteLock {
|
||||||
/// `lock`, to simplify lock handling.
|
/// `lock`, to simplify lock handling.
|
||||||
public func unlock() {
|
public func unlock() {
|
||||||
let err = pthread_rwlock_unlock(self.rwlock)
|
let err = pthread_rwlock_unlock(self.rwlock)
|
||||||
precondition(err == 0)
|
precondition(err == 0, "pthread_rwlock_unlock failed with error \(err)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue