aboutsummaryrefslogtreecommitdiff
path: root/platform/linux-generic/arch/aarch64/odp_atomic.c
blob: 56604f7f0a27c64fd86af1106e6e8221705d42cf (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
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright (c) 2015-2018 Linaro Limited
 * Copyright (c) 2021 ARM Limited
 */

#include <odp/api/atomic.h>

int odp_atomic_lock_free_u64(odp_atomic_op_t *atomic_op)
{
#if __GCC_ATOMIC_LLONG_LOCK_FREE < 2
	/* All operations have locks */
	if (atomic_op)
		atomic_op->all_bits = 0;

	return 0;
#else
	/* All operations are lock-free */
	if (atomic_op) {
		atomic_op->all_bits = ~((uint32_t)0);
		atomic_op->op.init  = 0;
	}

	return 2;
#endif
}

int odp_atomic_lock_free_u128(odp_atomic_op_t *atomic_op)
{
#ifdef _ODP_LOCK_FREE_128BIT_ATOMICS
	if (atomic_op) {
		atomic_op->all_bits = 0;
		atomic_op->op.load  = 1;
		atomic_op->op.store = 1;
		atomic_op->op.cas  = 1;
	}

	return 2;
#elif defined(__SIZEOF_INT128__)
	if (__atomic_is_lock_free(16, NULL)) {
		if (atomic_op) {
			atomic_op->all_bits = 0;
			atomic_op->op.load  = 1;
			atomic_op->op.store = 1;
			atomic_op->op.cas  = 1;
		}
		return 2;
	}
#endif
	/* All operations have locks */
	if (atomic_op)
		atomic_op->all_bits = 0;

	return 0;
}