1
0
mirror of https://github.com/switchbrew/libnx.git synced 2025-07-04 10:32:15 +02:00
libnx/nx/source/kernel/barrier.c
2019-02-23 21:09:41 +01:00

23 lines
431 B
C

#include "kernel/barrier.h"
void barrierInit(Barrier *b, u64 total) {
b->count = 0;
b->total = total - 1;
mutexInit(&b->mutex);
condvarInit(&b->condvar);
}
void barrierWait(Barrier *b) {
mutexLock(&b->mutex);
if (b->count++ == b->total) {
b->count = 0;
condvarWake(&b->condvar, b->total);
}
else {
condvarWait(&b->condvar, &b->mutex);
}
mutexUnlock(&b->mutex);
}