From 8b8a2bee0bce0bc9cc78d43f236c6a3d8a0bd2e4 Mon Sep 17 00:00:00 2001 From: "Suren A. Chilingaryan" Date: Thu, 6 Aug 2015 02:27:54 +0200 Subject: Fix handling of inconsistent mutexes --- pcilib/lock.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'pcilib') 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); + } + } } -- cgit v1.2.3