File: barrier.h

package info (click to toggle)
memtest86%2B 6.10-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,532 kB
  • sloc: ansic: 19,267; asm: 2,027; makefile: 367; sh: 134
file content (49 lines) | stat: -rw-r--r-- 953 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// SPDX-License-Identifier: GPL-2.0
#ifndef BARRIER_H
#define BARRIER_H
/**
 * \file
 *
 * Provides a barrier synchronisation primitive.
 *
 *//*
 * Copyright (C) 2020-2022 Martin Whitaker.
 */

#include "cpulocal.h"

#include "spinlock.h"

/**
 * A barrier object.
 */
typedef struct
{
    int     flag_num;
    int     num_threads;
    int     count;
} barrier_t;

/**
 * Initialises a new barrier to block the specified number of threads.
 */
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.
 */
void barrier_halt_wait(barrier_t *barrier);

#endif // BARRIER_H