Fix problems in last commit noted by Jeongchan Kim: last change returned -EINVAL vs EINVAL; Treat the case where the mutex is already unlocked just like the case where the mutex is held by another thread -- return EPERM.
This commit is contained in:
parent
a8282c0c39
commit
5e8037390c
@ -53,7 +53,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: pthread_mutex_unlock
|
* Name: pthread_mutex_islocked
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Return true is the mutex is locked.
|
* Return true is the mutex is locked.
|
||||||
@ -114,13 +114,13 @@ static inline bool pthread_mutex_islocked(FAR struct pthread_mutex_s *mutex)
|
|||||||
|
|
||||||
int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
|
int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = EPERM;
|
||||||
|
|
||||||
sinfo("mutex=0x%p\n", mutex);
|
sinfo("mutex=0x%p\n", mutex);
|
||||||
DEBUGASSERT(mutex != NULL);
|
DEBUGASSERT(mutex != NULL);
|
||||||
if (mutex == NULL)
|
if (mutex == NULL)
|
||||||
{
|
{
|
||||||
return -EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make sure the semaphore is stable while we make the following checks.
|
/* Make sure the semaphore is stable while we make the following checks.
|
||||||
@ -130,8 +130,10 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
|
|||||||
sched_lock();
|
sched_lock();
|
||||||
|
|
||||||
/* The unlock operation is only performed if the mutex is actually locked.
|
/* The unlock operation is only performed if the mutex is actually locked.
|
||||||
* If the mutex is not locked, then SUCCESS will be returned (there is
|
* EPERM *must* be returned if the mutex type is PTHREAD_MUTEX_ERRORCHECK
|
||||||
* no error return value specified for this case).
|
* or PTHREAD_MUTEX_RECURSIVE, or the mutex is a robust mutex, and the
|
||||||
|
* current thread does not own the mutex. Behavior is undefined for the
|
||||||
|
* remaining case.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if (pthread_mutex_islocked(mutex))
|
if (pthread_mutex_islocked(mutex))
|
||||||
|
Loading…
Reference in New Issue
Block a user