aboutsummaryrefslogtreecommitdiff
path: root/include/odp/api/abi-default/atomic.h
blob: 9999360fc4466dee7b56386a4d79354b3bb50671 (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2015-2018 Linaro Limited
 * Copyright (c) 2021 ARM Limited
 */

/**
 * @file
 *
 * ODP atomic operations
 */

#ifndef ODP_ABI_ATOMIC_H_
#define ODP_ABI_ATOMIC_H_

#ifdef __cplusplus
extern "C" {
#endif

#include <odp/api/std_types.h>
#include <odp/api/align.h>

/**
 * @internal
 * Atomic 32-bit unsigned integer
 */
typedef struct ODP_ALIGNED(sizeof(uint32_t)) odp_atomic_u32_s {
	uint32_t v; /**< Actual storage for the atomic variable */
} odp_atomic_u32_t;

#if __GCC_ATOMIC_LLONG_LOCK_FREE >= 2

/**
 * @internal
 * Atomic 64-bit unsigned integer
 */
typedef struct ODP_ALIGNED(sizeof(uint64_t)) odp_atomic_u64_s {
	uint64_t v; /**< Actual storage for the atomic variable */
} odp_atomic_u64_t;

#else

/**
 * @internal
 * Use embedded lock for atomic 64-bit variable implementation
 */
#define ODP_ATOMIC_U64_LOCK	1

/**
 * @internal
 * Atomic 64-bit unsigned integer
 */
typedef struct ODP_ALIGNED(sizeof(uint64_t)) odp_atomic_u64_s {
	uint64_t v; /**< Actual storage for the atomic variable */
	/* Some architectures do not support lock-free operations on 64-bit
	 * data types. We use a spin lock to ensure atomicity. */
	char lock; /**< Spin lock (if needed) used to ensure atomic access */
} odp_atomic_u64_t;

#endif

#if defined(__SIZEOF_INT128__) || defined(_ODP_LOCK_FREE_128BIT_ATOMICS)

/**
 * @internal
 * Atomic 128-bit unsigned integer
 */
typedef struct ODP_ALIGNED(sizeof(odp_u128_t)) odp_atomic_u128_s {
	odp_u128_t v; /**< Actual storage for the atomic variable */
} odp_atomic_u128_t;

#else

/**
 * @internal
 * Atomic 128-bit unsigned integer
 */
typedef struct ODP_ALIGNED(sizeof(odp_u128_t)) odp_atomic_u128_s {
	odp_u128_t v; /**< Actual storage for the atomic variable */
	/* Some architectures do not support lock-free operations on 128-bit
	 * data types. We use a spin lock to ensure atomicity. */
	char lock; /**< Spin lock (if needed) used to ensure atomic access */
} odp_atomic_u128_t;

#endif

#ifdef __cplusplus
}
#endif

#endif