summaryrefslogtreecommitdiffstats
path: root/src/mercury/mercury_thread_spin.c
blob: 60ef1f6e9085106eea8a2c7d3aed5aad30c7c145 (plain)
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
/*
 * Copyright (C) 2013-2019 Argonne National Laboratory, Department of Energy,
 *                    UChicago Argonne, LLC and The HDF Group.
 * All rights reserved.
 *
 * The full copyright notice, including terms governing use, modification,
 * and redistribution, is contained in the COPYING file that can be
 * found at the root of the source code distribution tree.
 */

#include "mercury_thread_spin.h"

/*---------------------------------------------------------------------------*/
int
hg_thread_spin_init(hg_thread_spin_t *lock)
{
#if defined(_WIN32)
    *lock = 0;

    return HG_UTIL_SUCCESS;
#elif defined(HG_UTIL_HAS_PTHREAD_SPINLOCK_T)
    if (pthread_spin_init(lock, 0))
        return HG_UTIL_FAIL;

    return HG_UTIL_SUCCESS;
#else
    return hg_thread_mutex_init(lock);
#endif
}

/*---------------------------------------------------------------------------*/
int
hg_thread_spin_destroy(hg_thread_spin_t *lock)
{
#if defined(_WIN32)
    (void) lock;

    return HG_UTIL_SUCCESS;
#elif defined(HG_UTIL_HAS_PTHREAD_SPINLOCK_T)
    if (pthread_spin_destroy(lock))
        return HG_UTIL_FAIL;

    return HG_UTIL_SUCCESS;
#else
    return hg_thread_mutex_destroy(lock);
#endif
}