2 * linux/include/asm-arm/atomic.h
4 * Copyright (c) 1996 Russell King.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
11 * 27-06-1996 RMK Created
12 * 13-04-1997 RMK Made functions atomic!
13 * 07-12-1997 RMK Upgraded for v2.1.
14 * 26-08-1998 PJB Added #ifdef __KERNEL__
16 #ifndef __ASM_ARM_ATOMIC_H
17 #define __ASM_ARM_ATOMIC_H
19 #include <linux/config.h>
22 #error SMP not supported
25 typedef struct { volatile int counter; } atomic_t;
27 #define ATOMIC_INIT(i) { (i) }
30 #include <asm/proc/system.h>
32 #define atomic_read(v) ((v)->counter)
33 #define atomic_set(v,i) (((v)->counter) = (i))
35 static inline void atomic_add(int i, volatile atomic_t *v)
39 local_irq_save(flags);
41 local_irq_restore(flags);
44 static inline void atomic_sub(int i, volatile atomic_t *v)
48 local_irq_save(flags);
50 local_irq_restore(flags);
53 static inline void atomic_inc(volatile atomic_t *v)
57 local_irq_save(flags);
59 local_irq_restore(flags);
62 static inline void atomic_dec(volatile atomic_t *v)
66 local_irq_save(flags);
68 local_irq_restore(flags);
71 static inline int atomic_dec_and_test(volatile atomic_t *v)
76 local_irq_save(flags);
78 v->counter = val -= 1;
79 local_irq_restore(flags);
84 static inline int atomic_add_negative(int i, volatile atomic_t *v)
89 local_irq_save(flags);
91 v->counter = val += i;
92 local_irq_restore(flags);
97 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
101 local_irq_save(flags);
103 local_irq_restore(flags);
106 /* Atomic operations are already serializing on ARM */
107 #define smp_mb__before_atomic_dec() barrier()
108 #define smp_mb__after_atomic_dec() barrier()
109 #define smp_mb__before_atomic_inc() barrier()
110 #define smp_mb__after_atomic_inc() barrier()