aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/include-abi/odp/api/abi/atomic.h
blob: cb5d6fcc994f24db0d7fb7f4092476c338aed645 (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
91
92
93
94
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2015-2018 Linaro Limited
 */

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

#ifndef ODP_API_ABI_ATOMIC_H_
#define ODP_API_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

#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

/** @addtogroup odp_atomic
 *  @{
 */

#include <odp/api/plat/atomic_inlines.h>

/**
 * @}
 */
#ifdef __cplusplus
}
#endif

#endif