syntax fixes

This commit is contained in:
Tate Haga 2018-10-17 16:46:01 -04:00
parent 39e205973c
commit 2b7a26ad17
3 changed files with 30 additions and 18 deletions

View File

@ -1,16 +1,30 @@
/**
* @file barrier.h
* @brief Multi-threading Barrier
* @author tatehaga
* @copyright libnx Authors
*/
#pragma once
#include "semaphore.h"
// barrier structure
typedef struct barrier{
typedef struct Barrier{
u64 count;
u64 thread_total;
Semaphore throttle;
Semaphore lock;
Semaphore thread_wait;
} barrier;
} Barrier;
void barrierInit(barrier *my_barrier, u64 thread_count);
/**
* @brief Initializes a barrier and the number of threads to wait on.
* @param b Barrier object.
* @param thread_count initial value for the number of threads the barrier must wait for.
*/
void barrierInit(Barrier *b, u64 thread_count);
void barrierWait(barrier *b);
/**
* @brief Forces threads to wait until all threads have called barrierWait.
* @param b Barrier object.
*/
void barrierWait(Barrier *b);

View File

@ -42,5 +42,3 @@ void semaphoreWait(Semaphore *s);
* @return true if no wait and successful lock, false otherwise.
*/
bool semaphoreTryWait(Semaphore *s);

View File

@ -1,25 +1,25 @@
#include "kernel/barrier.h"
void barrierInit(barrier *my_barrier, u64 thread_count){
my_barrier->count = 0;
my_barrier->thread_total = thread_count;
semaphoreInit(&my_barrier->throttle, 0);
semaphoreInit(&my_barrier->lock, 1);
semaphoreInit(&my_barrier->thread_wait, 0);
void barrierInit(Barrier *b, u64 thread_count) {
b->count = 0;
b->thread_total = thread_count;
semaphoreInit(&b->throttle, 0);
semaphoreInit(&b->lock, 1);
semaphoreInit(&b->thread_wait, 0);
}
void barrierWait(barrier *b){
void barrierWait(Barrier *b) {
semaphoreWait(&b->lock);
if(b->count < b->thread_total){
if(b->count < b->thread_total) {
b->count++;
}
if(b->count < b->thread_total){
if(b->count < b->thread_total) {
semaphoreSignal(&b->lock);
semaphoreWait(&b->thread_wait);
semaphoreSignal(&b->throttle);
}
else if(b->count == b->thread_total){
for(int i = 0; i < b->thread_total-1; i++){
else if(b->count == b->thread_total) {
for(int i = 0; i < b->thread_total-1; i++) {
semaphoreSignal(&b->thread_wait);
semaphoreWait(&b->throttle);
}