pthreads: Add some assertions.

This commit is contained in:
Gregory Nutt 2017-03-26 13:54:43 -06:00
parent fe03ef02c4
commit 5a69453e16
2 changed files with 6 additions and 2 deletions

View File

@ -170,6 +170,7 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex)
else if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL) else if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
{ {
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0);
/* A thread holds the mutex, but there is no such thread. POSIX /* A thread holds the mutex, but there is no such thread. POSIX
* requires that the 'robust' mutex return EOWNERDEAD in this case. * requires that the 'robust' mutex return EOWNERDEAD in this case.
@ -177,7 +178,8 @@ int pthread_mutex_lock(FAR pthread_mutex_t *mutex)
* fo fix the mutex. * fo fix the mutex.
*/ */
ret = EOWNERDEAD; mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
ret = EOWNERDEAD;
} }
else else
{ {

View File

@ -157,6 +157,7 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL) if (mutex->pid > 0 && sched_gettcb(mutex->pid) == NULL)
{ {
DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */ DEBUGASSERT(mutex->pid != 0); /* < 0: available, >0 owned, ==0 error */
DEBUGASSERT((mutex->flags & _PTHREAD_MFLAGS_INCONSISTENT) != 0);
/* A thread holds the mutex, but there is no such thread. /* A thread holds the mutex, but there is no such thread.
* POSIX requires that the 'robust' mutex return EOWNERDEAD * POSIX requires that the 'robust' mutex return EOWNERDEAD
@ -164,7 +165,8 @@ int pthread_mutex_trylock(FAR pthread_mutex_t *mutex)
* call pthread_mutx_consistent() fo fix the mutex. * call pthread_mutx_consistent() fo fix the mutex.
*/ */
ret = EOWNERDEAD; mutex->flags |= _PTHREAD_MFLAGS_INCONSISTENT;
ret = EOWNERDEAD;
} }
/* The mutex is locked by another, active thread */ /* The mutex is locked by another, active thread */