Skip to content

Commit

Permalink
Always use error checking pthread mutex.
Browse files Browse the repository at this point in the history
  • Loading branch information
andersio committed Jul 3, 2018
1 parent 7503872 commit eb8dac0
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Sources/Atomic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,7 @@ internal class Lock {
attr.deallocate()
}

// Darwin pthread for 32-bit ARM somehow returns `EAGAIN` when
// using `trylock` on a `PTHREAD_MUTEX_ERRORCHECK` mutex.
#if DEBUG && !arch(arm)
pthread_mutexattr_settype(attr, Int32(recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_ERRORCHECK))
#else
pthread_mutexattr_settype(attr, Int32(recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL))
#endif

let status = pthread_mutex_init(_lock, attr)
assert(status == 0, "Unexpected pthread mutex error code: \(status)")
Expand All @@ -187,6 +181,15 @@ internal class Lock {
case EBUSY:
return false
default:
#if DEBUG && arch(arm)
// Darwin pthread for 32-bit ARM somehow returns `EAGAIN` when
// using `trylock` on a `PTHREAD_MUTEX_ERRORCHECK` mutex.
//
// https://github.com/ReactiveCocoa/ReactiveSwift/pull/508
if status == EAGAIN {
return false
}
#endif
assertionFailure("Unexpected pthread mutex error code: \(status)")
return false
}
Expand Down

0 comments on commit eb8dac0

Please sign in to comment.