diff --git a/libs/libc/pthread/pthread_barrierwait.c b/libs/libc/pthread/pthread_barrierwait.c index 17108f059db..9e3f3dcfb0b 100644 --- a/libs/libc/pthread/pthread_barrierwait.c +++ b/libs/libc/pthread/pthread_barrierwait.c @@ -24,9 +24,9 @@ #include +#include #include #include -#include #include #include @@ -82,6 +82,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) { int semcount; int ret = OK; + irqstate_t flags; if (!barrier) { @@ -90,14 +91,14 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) /* Disable pre-emption throughout the following */ - sched_lock(); + flags = enter_critical_section(); /* Find out how many threads are already waiting at the barrier */ ret = sem_getvalue(&barrier->sem, &semcount); if (ret != OK) { - sched_unlock(); + leave_critical_section(flags); return get_errno(); } @@ -115,7 +116,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) /* Then return PTHREAD_BARRIER_SERIAL_THREAD to the final thread */ - sched_unlock(); + leave_critical_section(flags); return PTHREAD_BARRIER_SERIAL_THREAD; } else @@ -133,7 +134,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) * problem */ - sched_unlock(); + leave_critical_section(flags); return errornumber; } } @@ -143,7 +144,7 @@ int pthread_barrier_wait(FAR pthread_barrier_t *barrier) * zero. */ - sched_unlock(); + leave_critical_section(flags); return 0; } }