1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2016-2019, Linaro Limited
4  */
5 
6 #ifndef __ATOMIC_H
7 #define __ATOMIC_H
8 
9 #include <compiler.h>
10 #include <types_ext.h>
11 
12 uint32_t atomic_inc32(volatile uint32_t *v);
13 uint32_t atomic_dec32(volatile uint32_t *v);
14 
atomic_cas_uint(unsigned int * p,unsigned int * oval,unsigned int nval)15 static inline bool atomic_cas_uint(unsigned int *p, unsigned int *oval,
16 				   unsigned int nval)
17 {
18 	return __compiler_compare_and_swap(p, oval, nval);
19 }
20 
atomic_cas_u32(uint32_t * p,uint32_t * oval,uint32_t nval)21 static inline bool atomic_cas_u32(uint32_t *p, uint32_t *oval, uint32_t nval)
22 {
23 	return __compiler_compare_and_swap(p, oval, nval);
24 }
25 
atomic_load_int(int * p)26 static inline int atomic_load_int(int *p)
27 {
28 	return __compiler_atomic_load(p);
29 }
30 
atomic_load_short(short int * p)31 static inline short int atomic_load_short(short int *p)
32 {
33 	return __compiler_atomic_load(p);
34 }
35 
atomic_load_uint(unsigned int * p)36 static inline unsigned int atomic_load_uint(unsigned int *p)
37 {
38 	return __compiler_atomic_load(p);
39 }
40 
atomic_load_u32(const uint32_t * p)41 static inline uint32_t atomic_load_u32(const uint32_t *p)
42 {
43 	return __compiler_atomic_load(p);
44 }
45 
atomic_store_int(int * p,int val)46 static inline void atomic_store_int(int *p, int val)
47 {
48 	__compiler_atomic_store(p, val);
49 }
50 
atomic_store_short(short int * p,short int val)51 static inline void atomic_store_short(short int *p, short int val)
52 {
53 	__compiler_atomic_store(p, val);
54 }
55 
atomic_store_uint(unsigned int * p,unsigned int val)56 static inline void atomic_store_uint(unsigned int *p, unsigned int val)
57 {
58 	__compiler_atomic_store(p, val);
59 }
60 
atomic_store_u32(uint32_t * p,uint32_t val)61 static inline void atomic_store_u32(uint32_t *p, uint32_t val)
62 {
63 	__compiler_atomic_store(p, val);
64 }
65 
66 #endif /*__ATOMIC_H*/
67