diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2015-08-06 02:27:54 +0200 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2015-08-06 02:27:54 +0200 |
commit | 8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4 (patch) | |
tree | 288fd98d99c5468e9ef01231cba16d76083b62ea /pcilib | |
parent | 16ecf368c5cb4bebc3f5330bd0f25db06606f862 (diff) | |
download | pcitool-8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4.tar.gz pcitool-8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4.tar.bz2 pcitool-8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4.tar.xz pcitool-8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4.zip |
Fix handling of inconsistent mutexes
Diffstat (limited to 'pcilib')
-rw-r--r-- | pcilib/lock.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/pcilib/lock.c b/pcilib/lock.c index 9045ffa..03a2377 100644 --- a/pcilib/lock.c +++ b/pcilib/lock.c @@ -174,8 +174,9 @@ int pcilib_lock_custom(pcilib_lock_t *lock, pcilib_lock_flags_t flags, pcilib_ti err = pthread_mutex_consistent(&lock->mutex); if (err) { pcilib_error("Failed to mark mutex as consistent, errno %i", err); + break; } - break; + return 0; case ETIMEDOUT: case EBUSY: return PCILIB_ERROR_TIMEOUT; @@ -203,6 +204,13 @@ void pcilib_unlock(pcilib_lock_t *lock) { if (!lock) return; - if ((err = pthread_mutex_unlock(&lock->mutex)) != 0) - pcilib_error("Can't unlock mutex, errno %i", err); + if ((err = pthread_mutex_unlock(&lock->mutex)) != 0) { + switch (err) { + case EPERM: + pcilib_error("Trying to unlock not locked mutex (%s) or the mutex which was locked by a different thread", lock->name); + break; + default: + pcilib_error("Can't unlock mutex, errno %i", err); + } + } } |