From 2b7a26ad17b546083c12003fa6fb748a489a967c Mon Sep 17 00:00:00 2001 From: Tate Haga Date: Wed, 17 Oct 2018 16:46:01 -0400 Subject: [PATCH] syntax fixes --- nx/include/switch/kernel/barrier.h | 24 +++++++++++++++++++----- nx/include/switch/kernel/semaphore.h | 2 -- nx/source/kernel/barrier.c | 22 +++++++++++----------- 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/nx/include/switch/kernel/barrier.h b/nx/include/switch/kernel/barrier.h index 76d2fcd9..2278d67e 100644 --- a/nx/include/switch/kernel/barrier.h +++ b/nx/include/switch/kernel/barrier.h @@ -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); diff --git a/nx/include/switch/kernel/semaphore.h b/nx/include/switch/kernel/semaphore.h index fac4aa66..12f4c5b0 100644 --- a/nx/include/switch/kernel/semaphore.h +++ b/nx/include/switch/kernel/semaphore.h @@ -42,5 +42,3 @@ void semaphoreWait(Semaphore *s); * @return true if no wait and successful lock, false otherwise. */ bool semaphoreTryWait(Semaphore *s); - - diff --git a/nx/source/kernel/barrier.c b/nx/source/kernel/barrier.c index 1b248b73..d0c9af1b 100644 --- a/nx/source/kernel/barrier.c +++ b/nx/source/kernel/barrier.c @@ -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); }