zephyr/lib/posix/pthread_barrier.c
Evgeniy Paltsev 4e0f7ea540 posix: pthread: replace irq_lock with spinlock
We shouldn't use swapping with an interrupt lock held
as it works incorrectly on SMP platforms.

Fix that by replacing irq_lock with spinlock for pthread
subsystem.

NOTE: we fix that in a simple way with single spinlock
for mutex / cond_var / barrier. That could be improved
later (i.e. split it for several spinlocks).

Signed-off-by: Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>
Signed-off-by: Evgeniy Paltsev <PaltsevEvgeniy@gmail.com>
2021-09-03 12:20:19 -04:00

35 lines
660 B
C

/*
* Copyright (c) 2017 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <kernel.h>
#include <posix/pthread.h>
#include <ksched.h>
#include <wait_q.h>
extern struct k_spinlock z_pthread_spinlock;
int pthread_barrier_wait(pthread_barrier_t *b)
{
k_spinlock_key_t key = k_spin_lock(&z_pthread_spinlock);
int ret = 0;
b->count++;
if (b->count >= b->max) {
b->count = 0;
while (z_waitq_head(&b->wait_q)) {
_ready_one_thread(&b->wait_q);
}
z_reschedule(&z_pthread_spinlock, key);
ret = PTHREAD_BARRIER_SERIAL_THREAD;
} else {
(void) z_pend_curr(&z_pthread_spinlock, key, &b->wait_q, K_FOREVER);
}
return ret;
}