2017-12-18 15:41:03 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017 Intel Corporation
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <kernel.h>
|
2018-04-06 01:11:15 +08:00
|
|
|
#include <posix/pthread.h>
|
|
|
|
#include <ksched.h>
|
|
|
|
#include <wait_q.h>
|
2017-12-18 15:41:03 +08:00
|
|
|
|
|
|
|
int pthread_barrier_wait(pthread_barrier_t *b)
|
|
|
|
{
|
2019-03-02 07:22:22 +08:00
|
|
|
unsigned int key = irq_lock();
|
|
|
|
int ret = 0;
|
2017-12-18 15:41:03 +08:00
|
|
|
|
|
|
|
b->count++;
|
|
|
|
|
|
|
|
if (b->count >= b->max) {
|
|
|
|
b->count = 0;
|
|
|
|
|
2019-03-09 05:19:05 +08:00
|
|
|
while (z_waitq_head(&b->wait_q)) {
|
2018-04-11 23:21:26 +08:00
|
|
|
_ready_one_thread(&b->wait_q);
|
2017-12-18 15:41:03 +08:00
|
|
|
}
|
2019-03-09 05:19:05 +08:00
|
|
|
z_reschedule_irqlock(key);
|
2019-03-02 07:22:22 +08:00
|
|
|
ret = PTHREAD_BARRIER_SERIAL_THREAD;
|
2017-12-18 15:41:03 +08:00
|
|
|
} else {
|
2019-03-09 05:19:05 +08:00
|
|
|
(void) z_pend_curr_irqlock(key, &b->wait_q, K_FOREVER);
|
2017-12-18 15:41:03 +08:00
|
|
|
}
|
2019-03-02 07:22:22 +08:00
|
|
|
|
|
|
|
return ret;
|
2017-12-18 15:41:03 +08:00
|
|
|
}
|