From 5fb85451cb873579262dcf5ad4cb630f243ed21d Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 22 Mar 2017 08:08:43 -0600 Subject: [PATCH] Update some comments --- sched/pthread/pthread_mutexlock.c | 10 +++++++--- sched/pthread/pthread_mutexunlock.c | 15 +++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/sched/pthread/pthread_mutexlock.c b/sched/pthread/pthread_mutexlock.c index f94890505d..d5c8af2db2 100644 --- a/sched/pthread/pthread_mutexlock.c +++ b/sched/pthread/pthread_mutexlock.c @@ -136,8 +136,13 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) else #endif { - /* No, then we would deadlock... return an error (default behavior - * is like PTHREAD_MUTEX_ERRORCHECK) + /* No, then we would deadlock... return an error (default + * behavior is like PTHREAD_MUTEX_ERRORCHECK) + * + * NOTE: This is non-compliant behavior for the case of a + * NORMAL mutex. In that case, it the deadlock condition should + * not be detected and the thread should be permitted to + * deadlock. */ serr("ERROR: Returning EDEADLK\n"); @@ -169,4 +174,3 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex) sinfo("Returning %d\n", ret); return ret; } - diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 078d9094b9..56c14bb036 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -100,13 +100,22 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) if (mutex->pid != (int)getpid()) { - /* No... return an error (default behavior is like PTHREAD_MUTEX_ERRORCHECK) */ + /* No... return an EPERM error. + * + * Per POSIX: "EPERM should be returned if the mutex type is + * PTHREAD_MUTEX_ERRORCHECK or PTHREAD_MUTEX_RECURSIVE, or the + * mutex is a robust mutex, and the current thread does not own + * the mutex." + * + * For the case of the non-robust PTHREAD_MUTEX_NORMAL mutex, + * the behavior is undefined. Here we treat that type as though + * it were PTHREAD_MUTEX_ERRORCHECK type and just return an error. + */ serr("ERROR: Holder=%d returning EPERM\n", mutex->pid); ret = EPERM; } - /* Yes, the caller owns the semaphore.. Is this a recursive mutex? */ #ifdef CONFIG_MUTEX_TYPES @@ -116,6 +125,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) * the mutex lock, just decrement the count of locks held, and return * success. */ + mutex->nlocks--; } #endif @@ -134,6 +144,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) #endif ret = pthread_givesemaphore((FAR sem_t *)&mutex->sem); } + sched_unlock(); }