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