Skip to content

Commit

Permalink
Improve precondition error messages in Lock functions (#58)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cpriebe authored Feb 10, 2020
1 parent f1514a4 commit 09b72f6
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions Sources/CoreMetrics/Locks.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ internal final class Lock {
/// Create a new lock.
public init() {
let err = pthread_mutex_init(self.mutex, nil)
precondition(err == 0)
precondition(err == 0, "pthread_mutex_init failed with error \(err)")
}

deinit {
let err = pthread_mutex_destroy(self.mutex)
precondition(err == 0)
precondition(err == 0, "pthread_mutex_destroy failed with error \(err)")
self.mutex.deallocate()
}

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

/// Release the lock.
Expand All @@ -67,7 +67,7 @@ internal final class Lock {
/// `lock`, to simplify lock handling.
public func unlock() {
let err = pthread_mutex_unlock(self.mutex)
precondition(err == 0)
precondition(err == 0, "pthread_mutex_unlock failed with error \(err)")
}
}

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

deinit {
let err = pthread_rwlock_destroy(self.rwlock)
precondition(err == 0)
precondition(err == 0, "pthread_rwlock_destroy failed with error \(err)")
self.rwlock.deallocate()
}

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

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

/// Release the lock.
Expand All @@ -140,7 +140,7 @@ internal final class ReadWriteLock {
/// `lock`, to simplify lock handling.
public func unlock() {
let err = pthread_rwlock_unlock(self.rwlock)
precondition(err == 0)
precondition(err == 0, "pthread_rwlock_unlock failed with error \(err)")
}
}

Expand Down

0 comments on commit 09b72f6

Please sign in to comment.