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)
|
|
|
|
{
|
2018-09-13 08:27:11 +08:00
|
|
|
/* FIXME: This function should return PTHREAD_BARRIER_SERIAL_THREAD
|
|
|
|
* for an arbitrary thread and 0 for the others.
|
|
|
|
*/
|
2017-12-18 15:41:03 +08:00
|
|
|
int key = irq_lock();
|
|
|
|
|
|
|
|
b->count++;
|
|
|
|
|
|
|
|
if (b->count >= b->max) {
|
|
|
|
b->count = 0;
|
|
|
|
|
2018-05-11 02:10:34 +08:00
|
|
|
while (_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
|
|
|
}
|
2018-09-13 08:27:11 +08:00
|
|
|
_reschedule(key);
|
|
|
|
return 0;
|
2017-12-18 15:41:03 +08:00
|
|
|
} else {
|
2018-03-27 02:58:10 +08:00
|
|
|
return _pend_current_thread(key, &b->wait_q, K_FOREVER);
|
2017-12-18 15:41:03 +08:00
|
|
|
}
|
|
|
|
}
|