winpthreads: fix return value of pthread_mutex_unlock
If `pthread_mutex_t` object passed to `pthread_mutex_unlock` is a valid but
unlocked mutex of type `PTHREAD_MUTEX_ERRORCHECK` or `PTHREAD_MUTEX_RECURSIVE`,
`pthread_mutex_unlock` would fail with `EINVAL`.
This behavior caused tests mutex{6e,6es,7e}.c to fail since they expected
`pthread_mutex_unlock` to fail with `EPERM` in such case.
POSIX[1] says the following about `pthread_mutex_unlock`:
The pthread_mutex_unlock() function shall fail if:
[EPERM]
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.
It mentions `EINVAL` in RATIONALE:
If an implementation detects that the value specified by the mutex argument
does not refer to an initialized mutex object, it is recommended that the
function should fail and report an [EINVAL] error.
Error condition for `EPERM` fits situation when `pthread_mutex_t` object is a
valid but unlocked mutex; it has no owner which means that the calling thread
does not own it and as such the calling thread cannot unlock it.
[1] https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/pthread_mutex_lock.html
Signed-off-by: Kirill Makurin <maiddaisuki@outlook.com>
Signed-off-by: LIU Hao <lh_mouse@126.com>
2 files changed