memtest86plus/lib/barrier.h

50 lines
953 B
C
Raw Permalink Normal View History

2020-05-24 21:30:55 +01:00
// SPDX-License-Identifier: GPL-2.0
#ifndef BARRIER_H
#define BARRIER_H
/**
* \file
*
2020-05-24 21:30:55 +01:00
* Provides a barrier synchronisation primitive.
*
*//*
* Copyright (C) 2020-2022 Martin Whitaker.
2020-05-24 21:30:55 +01:00
*/
#include "cpulocal.h"
2020-05-24 21:30:55 +01:00
#include "spinlock.h"
/**
2020-05-24 21:30:55 +01:00
* A barrier object.
*/
typedef struct
{
int flag_num;
int num_threads;
int count;
2020-05-24 21:30:55 +01:00
} barrier_t;
/**
* Initialises a new barrier to block the specified number of threads.
2020-05-24 21:30:55 +01:00
*/
void barrier_init(barrier_t *barrier, int num_threads);
/**
* Resets an existing barrier to block the specified number of threads.
*/
void barrier_reset(barrier_t *barrier, int num_threads);
/**
* Waits for all threads to arrive at the barrier. A CPU core spins in an
* idle loop when waiting.
*/
void barrier_spin_wait(barrier_t *barrier);
/**
* Waits for all threads to arrive at the barrier. A CPU core halts when
* waiting.
2020-05-24 21:30:55 +01:00
*/
void barrier_halt_wait(barrier_t *barrier);
2020-05-24 21:30:55 +01:00
#endif // BARRIER_H