2020-05-24 21:30:55 +01:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
#ifndef BARRIER_H
|
|
|
|
#define BARRIER_H
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
*
|
2020-05-24 21:30:55 +01:00
|
|
|
* Provides a barrier synchronisation primitive.
|
|
|
|
*
|
2022-02-19 19:56:55 +00:00
|
|
|
*//*
|
2022-02-19 16:17:40 +00:00
|
|
|
* Copyright (C) 2020-2022 Martin Whitaker.
|
2020-05-24 21:30:55 +01:00
|
|
|
*/
|
|
|
|
|
2022-02-28 20:21:50 +00:00
|
|
|
#include "cpulocal.h"
|
|
|
|
|
2020-05-24 21:30:55 +01:00
|
|
|
#include "spinlock.h"
|
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2020-05-24 21:30:55 +01:00
|
|
|
* A barrier object.
|
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2022-02-28 20:21:50 +00:00
|
|
|
int flag_num;
|
|
|
|
int num_threads;
|
|
|
|
int count;
|
2020-05-24 21:30:55 +01:00
|
|
|
} barrier_t;
|
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2022-02-28 20:21:50 +00:00
|
|
|
* 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);
|
|
|
|
|
2022-02-19 16:17:40 +00:00
|
|
|
/**
|
2022-02-28 20:21:50 +00:00
|
|
|
* 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
|
|
|
*/
|
2022-02-28 20:21:50 +00:00
|
|
|
void barrier_halt_wait(barrier_t *barrier);
|
2020-05-24 21:30:55 +01:00
|
|
|
|
|
|
|
#endif // BARRIER_H
|