libnx v4.9.0
Loading...
Searching...
No Matches
barrier.h
Go to the documentation of this file.
1/**
2 * @file barrier.h
3 * @brief Multi-threading Barrier
4 * @author tatehaga
5 * @copyright libnx Authors
6 */
7#pragma once
8#include "mutex.h"
9#include "condvar.h"
10
11/// Barrier structure.
12typedef struct Barrier {
13 u64 count; ///< Number of threads to reach the barrier.
14 u64 total; ///< Number of threads to wait on.
15 Mutex mutex;
16 CondVar condvar;
17} Barrier;
18
19/**
20 * @brief Initializes a barrier and the number of threads to wait on.
21 * @param b Barrier object.
22 * @param thread_count Initial value for the number of threads the barrier must wait for.
23 */
24void barrierInit(Barrier *b, u64 thread_count);
25
26/**
27 * @brief Forces threads to wait until all threads have called barrierWait.
28 * @param b Barrier object.
29 */
void barrierWait(Barrier *b)
Forces threads to wait until all threads have called barrierWait.
void barrierInit(Barrier *b, u64 thread_count)
Initializes a barrier and the number of threads to wait on.
Condition variable synchronization primitive.
u32 CondVar
Condition variable.
Definition condvar.h:13
Mutex synchronization primitive.
_LOCK_T Mutex
Mutex datatype, defined in newlib.
Definition mutex.h:12
Barrier structure.
Definition barrier.h:12
u64 count
Number of threads to reach the barrier.
Definition barrier.h:13
u64 total
Number of threads to wait on.
Definition barrier.h:14
uint64_t u64
64-bit unsigned integer.
Definition types.h:22