1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef SMP_ATOMIC_H 4 #define SMP_ATOMIC_H 5 6 #if CONFIG(SMP) 7 #include <arch/smp/atomic.h> 8 #else 9 10 typedef struct { int counter; } atomic_t; 11 #define ATOMIC_INIT(i) { (i) } 12 13 /** 14 * @file include/smp/atomic.h 15 */ 16 17 /** 18 * atomic_read - read atomic variable 19 * @param v: pointer of type atomic_t 20 * 21 * Atomically reads the value of v. Note that the guaranteed 22 * useful range of an atomic_t is only 24 bits. 23 */ 24 #define atomic_read(v) ((v)->counter) 25 26 /** 27 * atomic_set - set atomic variable 28 * @param v: pointer of type atomic_t 29 * @param i: required value 30 * 31 * Atomically sets the value of v to i. Note that the guaranteed 32 * useful range of an atomic_t is only 24 bits. 33 */ 34 #define atomic_set(v, i) (((v)->counter) = (i)) 35 36 /** 37 * atomic_inc - increment atomic variable 38 * @param v: pointer of type atomic_t 39 * 40 * Atomically increments v by 1. Note that the guaranteed 41 * useful range of an atomic_t is only 24 bits. 42 */ 43 #define atomic_inc(v) (((v)->counter)++) 44 45 /** 46 * atomic_dec - decrement atomic variable 47 * @param v: pointer of type atomic_t 48 * 49 * Atomically decrements v by 1. Note that the guaranteed 50 * useful range of an atomic_t is only 24 bits. 51 */ 52 #define atomic_dec(v) (((v)->counter)--) 53 54 #endif /* CONFIG_SMP */ 55 56 #endif /* SMP_ATOMIC_H */ 57