sched/pthread/barrierwait: replace syscall(2) to kernel api

syscall(2) cannot be called from kernel space

Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
chao an
2023-10-24 22:16:00 +08:00
committed by Xiang Xiao
parent c19c943835
commit cdec5c80c2
+13 -17
View File
@@ -25,8 +25,8 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <nuttx/irq.h> #include <nuttx/irq.h>
#include <nuttx/semaphore.h>
#include <pthread.h> #include <pthread.h>
#include <semaphore.h>
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
@@ -80,11 +80,11 @@
int pthread_barrier_wait(FAR pthread_barrier_t *barrier) int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
{ {
int semcount;
int ret = OK;
irqstate_t flags; irqstate_t flags;
int semcount;
int ret;
if (!barrier) if (barrier == NULL)
{ {
return EINVAL; return EINVAL;
} }
@@ -95,11 +95,11 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
/* Find out how many threads are already waiting at the barrier */ /* Find out how many threads are already waiting at the barrier */
ret = sem_getvalue(&barrier->sem, &semcount); ret = nxsem_get_value(&barrier->sem, &semcount);
if (ret != OK) if (ret != OK)
{ {
leave_critical_section(flags); leave_critical_section(flags);
return get_errno(); return -ret;
} }
/* If the number of waiters would be equal to the count, then we are done */ /* If the number of waiters would be equal to the count, then we are done */
@@ -110,8 +110,8 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
while (semcount < 0) while (semcount < 0)
{ {
sem_post(&barrier->sem); nxsem_post(&barrier->sem);
sem_getvalue(&barrier->sem, &semcount); nxsem_get_value(&barrier->sem, &semcount);
} }
/* Then return PTHREAD_BARRIER_SERIAL_THREAD to the final thread */ /* Then return PTHREAD_BARRIER_SERIAL_THREAD to the final thread */
@@ -119,23 +119,20 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
leave_critical_section(flags); leave_critical_section(flags);
return PTHREAD_BARRIER_SERIAL_THREAD; return PTHREAD_BARRIER_SERIAL_THREAD;
} }
else
{
/* Otherwise, this thread must wait as well */ /* Otherwise, this thread must wait as well */
while (sem_wait(&barrier->sem) != OK) while ((ret = nxsem_wait(&barrier->sem)) != OK)
{ {
/* If the thread is awakened by a signal, just continue to wait */ /* If the thread is awakened by a signal, just continue to wait */
int errornumber = get_errno(); if (ret != -EINTR)
if (errornumber != EINTR)
{ {
/* If it is awakened by some other error, then there is a /* If it is awakened by some other error, then there is a
* problem * problem
*/ */
leave_critical_section(flags); break;
return errornumber;
} }
} }
@@ -145,6 +142,5 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier)
*/ */
leave_critical_section(flags); leave_critical_section(flags);
return 0; return -ret;
}
} }