mirror of
https://github.com/apache/nuttx.git
synced 2026-09-28 03:09:13 +08:00
sched/pthread: Use -1 instead of 0 as PID for unclaimed mutexes
This commit is contained in:
committed by
Gregory Nutt
parent
ba55e8c7d8
commit
d16053c33c
@@ -270,7 +270,7 @@ int pthread_cond_timedwait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex,
|
||||
{
|
||||
/* Give up the mutex */
|
||||
|
||||
mutex->pid = 0;
|
||||
mutex->pid = -1;
|
||||
ret = pthread_givesemaphore((sem_t*)&mutex->sem);
|
||||
if (ret)
|
||||
{
|
||||
|
||||
@@ -113,7 +113,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
|
||||
sdbg("Give up mutex / take cond\n");
|
||||
|
||||
sched_lock();
|
||||
mutex->pid = 0;
|
||||
mutex->pid = -1;
|
||||
ret = pthread_givesemaphore((sem_t*)&mutex->sem);
|
||||
|
||||
/* Take the semaphore */
|
||||
@@ -127,7 +127,7 @@ int pthread_cond_wait(FAR pthread_cond_t *cond, FAR pthread_mutex_t *mutex)
|
||||
ret |= pthread_takesemaphore((sem_t*)&mutex->sem);
|
||||
if (!ret)
|
||||
{
|
||||
mutex->pid = getpid();;
|
||||
mutex->pid = getpid();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ int pthread_mutex_destroy(FAR pthread_mutex_t *mutex)
|
||||
|
||||
/* Is the semaphore available? */
|
||||
|
||||
if (mutex->pid != 0)
|
||||
if (mutex->pid != -1)
|
||||
{
|
||||
ret = EBUSY;
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ int pthread_mutex_init(FAR pthread_mutex_t *mutex, FAR const pthread_mutexattr_t
|
||||
|
||||
/* Indicate that the semaphore is not held by any thread. */
|
||||
|
||||
mutex->pid = 0;
|
||||
mutex->pid = -1;
|
||||
|
||||
/* Initialize the mutex like a semaphore with initial count = 1 */
|
||||
|
||||
|
||||
@@ -148,7 +148,7 @@ int pthread_mutex_unlock(FAR pthread_mutex_t *mutex)
|
||||
{
|
||||
/* Nullify the pid and lock count then post the semaphore */
|
||||
|
||||
mutex->pid = 0;
|
||||
mutex->pid = -1;
|
||||
#ifdef CONFIG_MUTEX_TYPES
|
||||
mutex->nlocks = 0;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user