diff --git a/include/pthread.h b/include/pthread.h index a94af29793..f2bac8cf70 100644 --- a/include/pthread.h +++ b/include/pthread.h @@ -137,8 +137,8 @@ /* Definitions to map some non-standard, BSD thread management interfaces to * the non-standard Linux-like prctl() interface. Since these are simple - * mappings to prctl, they will return 0 sucess and -1 on failure with the - * err number in errno. This is an inconsistency with out pthread interfaces. + * mappings to prctl, they will return 0 on success and -1 on failure with the + * err number in errno. This is an inconsistency with the pthread interfaces. */ #define pthread_setname_np(thread, name) \ @@ -160,14 +160,13 @@ extern "C" typedef int pthread_key_t; typedef FAR void *pthread_addr_t; -typedef pthread_addr_t any_t; typedef pthread_addr_t (*pthread_startroutine_t)(pthread_addr_t); typedef pthread_startroutine_t pthread_func_t; struct pthread_attr_s { - size_t stacksize; /* Size of the stack allocated for the pthead */ + size_t stacksize; /* Size of the stack allocated for the pthread */ int16_t priority; /* Priority of the pthread */ uint8_t policy; /* Pthread scheduler policy */ uint8_t inheritsched; /* Inherit parent prio/policy? */ @@ -206,9 +205,9 @@ struct pthread_mutex_s typedef struct pthread_mutex_s pthread_mutex_t; #ifdef CONFIG_MUTEX_TYPES -# define PTHREAD_MUTEX_INITIALIZER {0, SEM_INITIALIZER(1), PTHREAD_MUTEX_DEFAULT, 0} +# define PTHREAD_MUTEX_INITIALIZER {-1, SEM_INITIALIZER(1), PTHREAD_MUTEX_DEFAULT, 0} #else -# define PTHREAD_MUTEX_INITIALIZER {0, SEM_INITIALIZER(1)} +# define PTHREAD_MUTEX_INITIALIZER {-1, SEM_INITIALIZER(1)} #endif struct pthread_barrierattr_s @@ -307,7 +306,7 @@ void pthread_yield(void); /* Compare two thread IDs. */ -#define pthread_equal(t1,t2) (t1 == t2) +#define pthread_equal(t1,t2) ((t1) == (t2)) /* Thread scheduling parameters */ diff --git a/sched/pthread/pthread_condtimedwait.c b/sched/pthread/pthread_condtimedwait.c index f6f8ec65bb..b9d266a763 100644 --- a/sched/pthread/pthread_condtimedwait.c +++ b/sched/pthread/pthread_condtimedwait.c @@ -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) { diff --git a/sched/pthread/pthread_condwait.c b/sched/pthread/pthread_condwait.c index 55856ccbc8..7460510a14 100644 --- a/sched/pthread/pthread_condwait.c +++ b/sched/pthread/pthread_condwait.c @@ -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(); } } diff --git a/sched/pthread/pthread_mutexdestroy.c b/sched/pthread/pthread_mutexdestroy.c index b8abcb7168..3f768e1458 100644 --- a/sched/pthread/pthread_mutexdestroy.c +++ b/sched/pthread/pthread_mutexdestroy.c @@ -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; } diff --git a/sched/pthread/pthread_mutexinit.c b/sched/pthread/pthread_mutexinit.c index 1224e61b6a..0236830a06 100644 --- a/sched/pthread/pthread_mutexinit.c +++ b/sched/pthread/pthread_mutexinit.c @@ -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 */ diff --git a/sched/pthread/pthread_mutexunlock.c b/sched/pthread/pthread_mutexunlock.c index 990f17de8a..0d340d08c7 100644 --- a/sched/pthread/pthread_mutexunlock.c +++ b/sched/pthread/pthread_mutexunlock.c @@ -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