blob: 42b32f5d3d6eb8a4af4bb861e252618c1a917036 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0+ */
Chris Zankel1387dab2016-08-10 18:36:44 +03002/*
3 * Copyright (C) 2016 Cadence Design Systems Inc.
Chris Zankel1387dab2016-08-10 18:36:44 +03004 */
5
6#ifndef _XTENSA_ATOMIC_H
7#define _XTENSA_ATOMIC_H
8
9#include <asm/system.h>
10
11typedef 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
18static 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
27static 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
36static 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
45static 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