From 84849cfc5ec7b74bab3c7a21b2babed14c89e37d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Mon, 10 Apr 2017 08:44:08 -0600 Subject: [PATCH] examples/ostest: pthread rwlock cleanup handlers must call pthread_consistent, not pthread_mutex_unlock() on cancellation if robust mutexes are enabled. --- libc/pthread/pthread_rwlock_rdlock.c | 13 ++++++++++++- libc/pthread/pthread_rwlock_wrlock.c | 14 +++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 19979f79bb..29dcf7daae 100644 --- a/libc/pthread/pthread_rwlock_rdlock.c +++ b/libc/pthread/pthread_rwlock_rdlock.c @@ -55,7 +55,18 @@ static void rdlock_cleanup(FAR void *arg) { FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; - pthread_mutex_unlock(&rw_lock->lock); +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Check if this is a robust mutex in an inconsistent state */ + + if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) + { + (void)pthread_mutex_consistent(&rw_lock->lock); + } + else +#endif + { + (void)pthread_mutex_unlock(&rw_lock->lock); + } } #endif diff --git a/libc/pthread/pthread_rwlock_wrlock.c b/libc/pthread/pthread_rwlock_wrlock.c index fcda35cb4f..93a6a23858 100644 --- a/libc/pthread/pthread_rwlock_wrlock.c +++ b/libc/pthread/pthread_rwlock_wrlock.c @@ -56,7 +56,19 @@ static void wrlock_cleanup(FAR void *arg) FAR pthread_rwlock_t *rw_lock = (FAR pthread_rwlock_t *)arg; rw_lock->num_writers--; - pthread_mutex_unlock(&rw_lock->lock); + +#ifndef CONFIG_PTHREAD_MUTEX_UNSAFE + /* Check if this is a robust mutex in an inconsistent state */ + + if ((rw_lock->lock.flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0) + { + (void)pthread_mutex_consistent(&rw_lock->lock); + } + else +#endif + { + (void)pthread_mutex_unlock(&rw_lock->lock); + } } #endif