7551bf6e6c2cd520cfc6a0f3a11f4d6b5d5d6067
[platform/kernel/u-boot.git] / arch / mips / include / asm / atomic.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2016 Cadence Design Systems Inc.
4  */
5
6 #ifndef _MIPS_ATOMIC_H
7 #define _MIPS_ATOMIC_H
8
9 #include <asm/system.h>
10
11 typedef struct { volatile int counter; } atomic_t;
12
13 #define ATOMIC_INIT(i)  { (i) }
14
15 #define atomic_read(v)          ((v)->counter)
16 #define atomic_set(v, i)        ((v)->counter = (i))
17
18 static inline void atomic_add(int i, atomic_t *v)
19 {
20         unsigned long flags;
21
22         local_irq_save(flags);
23         v->counter += i;
24         local_irq_restore(flags);
25 }
26
27 static inline void atomic_sub(int i, atomic_t *v)
28 {
29         unsigned long flags;
30
31         local_irq_save(flags);
32         v->counter -= i;
33         local_irq_restore(flags);
34 }
35
36 static inline void atomic_inc(atomic_t *v)
37 {
38         unsigned long flags;
39
40         local_irq_save(flags);
41         ++v->counter;
42         local_irq_restore(flags);
43 }
44
45 static inline void atomic_dec(atomic_t *v)
46 {
47         unsigned long flags;
48
49         local_irq_save(flags);
50         --v->counter;
51         local_irq_restore(flags);
52 }
53
54 #endif