eunb.song@samsung.com [nuttx]
2017-03-22 11:08:48 UTC
Hi, Greg.
I compared pthread_mutex_unlock implementation between Nuttx and glibc.
And i found a difference when pthread_mutex_unlock() is called by process which does not call pthead_mutex_lock()
In case of, Nuttx, return EPERM;
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) */ serr("ERROR: Holder=%d returning EPERM\n", mutex->pid);
ret = EPERM;
}
in case of glibc, you can see http://git.savannah.gnu.org/cgit/hurd/libpthread.git/tree/sysdeps/generic/pt-mutex-unlock.c http://git.savannah.gnu.org/cgit/hurd/libpthread.git/tree/sysdeps/generic/pt-mutex-unlock.c
switch (attr->__mutex_type) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_RECURSIVE: if (mutex->__owner != _pthread_self ()) { __pthread_spin_unlock (&mutex->__lock); return EPERM; }-> only return EPERM for ERRORCHECK and RECURSIVE type.
So, in my point of view, below changes are needed. diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 078d909..fa17a58 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -98,7 +98,8 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) /* Does the calling thread own the semaphore? */ - if (mutex->pid != (int)getpid()) + if (((mutex->type == PTHREAD_MUTEX_RECURSIVE) || (mutex->type == PTHREAD_MUTEX_ERRORCHECK)) + && (mutex->pid != (int)getpid())) { /* No... return an error (default behavior is like PTHREAD_MUTEX_ERRORCHECK) */
I would appreciate if you say your opinion.
I compared pthread_mutex_unlock implementation between Nuttx and glibc.
And i found a difference when pthread_mutex_unlock() is called by process which does not call pthead_mutex_lock()
In case of, Nuttx, return EPERM;
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) */ serr("ERROR: Holder=%d returning EPERM\n", mutex->pid);
ret = EPERM;
}
in case of glibc, you can see http://git.savannah.gnu.org/cgit/hurd/libpthread.git/tree/sysdeps/generic/pt-mutex-unlock.c http://git.savannah.gnu.org/cgit/hurd/libpthread.git/tree/sysdeps/generic/pt-mutex-unlock.c
switch (attr->__mutex_type) { case PTHREAD_MUTEX_ERRORCHECK: case PTHREAD_MUTEX_RECURSIVE: if (mutex->__owner != _pthread_self ()) { __pthread_spin_unlock (&mutex->__lock); return EPERM; }-> only return EPERM for ERRORCHECK and RECURSIVE type.
So, in my point of view, below changes are needed. diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 078d909..fa17a58 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -98,7 +98,8 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex) /* Does the calling thread own the semaphore? */ - if (mutex->pid != (int)getpid()) + if (((mutex->type == PTHREAD_MUTEX_RECURSIVE) || (mutex->type == PTHREAD_MUTEX_ERRORCHECK)) + && (mutex->pid != (int)getpid())) { /* No... return an error (default behavior is like PTHREAD_MUTEX_ERRORCHECK) */
I would appreciate if you say your opinion.