diff --git a/libc/pthread/pthread_rwlock_rdlock.c b/libc/pthread/pthread_rwlock_rdlock.c index 19979f79bb2..29dcf7daae1 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 fcda35cb4f5..93a6a238582 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