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)
|
|
|
|
{
|
|
|
|
int key = irq_lock();
|
|
|
|
|
|
|
|
b->count++;
|
|
|
|
|
|
|
|
if (b->count >= b->max) {
|
|
|
|
b->count = 0;
|
|
|
|
|
|
|
|
while (!sys_dlist_is_empty(&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-04-03 09:40:10 +08:00
|
|
|
return _reschedule(key);
|
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
|
|
|
}
|
|
|
|
}
|