Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use error checking pthread mutex. #654

Merged
merged 4 commits into from
Jul 10, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 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 @@ -184,7 +178,7 @@ internal class Lock {
switch status {
case 0:
return true
case EBUSY:
case EBUSY, EAGAIN:
return false
default:
assertionFailure("Unexpected pthread mutex error code: \(status)")
Expand Down