Coverage Report

Created: 2026-10-28 18:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5TSbarrier.h
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*
14
 * Purpose: This file contains support for thread barrier operations, equivalent
15
 *        to the pthread 'pthread_barrier_t' type and capabilities.
16
 *
17
 * Note:  Because this threadsafety framework operates outside the library,
18
 *        it does not use the error stack (although it does use error macros
19
 *        that don't push errors on a stack) and only uses the "namecheck only"
20
 *        FUNC_ENTER_* / FUNC_LEAVE_* macros.
21
 */
22
23
/****************/
24
/* Module Setup */
25
/****************/
26
27
/***********/
28
/* Headers */
29
/***********/
30
31
/****************/
32
/* Local Macros */
33
/****************/
34
35
/******************/
36
/* Local Typedefs */
37
/******************/
38
39
/********************/
40
/* Local Prototypes */
41
/********************/
42
43
/*********************/
44
/* Package Variables */
45
/*********************/
46
47
/*****************************/
48
/* Library Private Variables */
49
/*****************************/
50
51
/*******************/
52
/* Local Variables */
53
/*******************/
54
55
/*--------------------------------------------------------------------------
56
 * Function:    H5TS_barrier_wait
57
 *
58
 * Purpose:     Wait at a barrier.
59
 *
60
 * Note:      Similar to pthread_barrier_wait, a barrier may be reused
61
 *    multiple times without intervening calls to H5TS_barrier_init.
62
 *
63
 * Return:      Non-negative on success / Negative on failure
64
 *
65
 *--------------------------------------------------------------------------
66
 */
67
static inline herr_t
68
H5TS_barrier_wait(H5TS_barrier_t *barrier)
69
0
{
70
0
    if (H5_UNLIKELY(NULL == barrier))
71
0
        return FAIL;
72
0
73
0
#ifdef H5_HAVE_PTHREAD_BARRIER
74
0
    {
75
0
        int ret = pthread_barrier_wait(barrier);
76
0
        if (H5_UNLIKELY(ret != 0 && ret != PTHREAD_BARRIER_SERIAL_THREAD))
77
0
            return FAIL;
78
0
    }
79
0
#else
80
0
    {
81
0
        const unsigned my_generation = H5TS_atomic_load_uint(&barrier->generation);
82
0
83
0
        /* When the last thread enters, reset the openings & bump the generation */
84
0
        if (1 == H5TS_atomic_fetch_sub_uint(&barrier->openings, 1)) {
85
0
            H5TS_atomic_store_uint(&barrier->openings, barrier->count);
86
0
            H5TS_atomic_fetch_add_uint(&barrier->generation, 1);
87
0
        }
88
0
        else {
89
0
            /* Not the last thread, wait for the generation to change */
90
0
            while (H5TS_atomic_load_uint(&barrier->generation) == my_generation)
91
0
                H5TS_thread_yield();
92
0
        }
93
0
    }
94
0
#endif
95
0
96
0
    return SUCCEED;
97
0
} /* end H5TS_barrier_wait() */
Unexecuted instantiation: H5.c:H5TS_barrier_wait
Unexecuted instantiation: H5Eint.c:H5TS_barrier_wait