aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-v850/atomic.h
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /include/asm-v850/atomic.h
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'include/asm-v850/atomic.h')
-rw-r--r--include/asm-v850/atomic.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/include/asm-v850/atomic.h b/include/asm-v850/atomic.h
new file mode 100644
index 000000000000..8284aa7363f2
--- /dev/null
+++ b/include/asm-v850/atomic.h
@@ -0,0 +1,99 @@
1/*
2 * include/asm-v850/atomic.h -- Atomic operations
3 *
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 *
11 * Written by Miles Bader <miles@gnu.org>
12 */
13
14#ifndef __V850_ATOMIC_H__
15#define __V850_ATOMIC_H__
16
17#include <linux/config.h>
18
19#include <asm/system.h>
20
21#ifdef CONFIG_SMP
22#error SMP not supported
23#endif
24
25typedef struct { int counter; } atomic_t;
26
27#define ATOMIC_INIT(i) { (i) }
28
29#ifdef __KERNEL__
30
31#define atomic_read(v) ((v)->counter)
32#define atomic_set(v,i) (((v)->counter) = (i))
33
34extern __inline__ int atomic_add_return (int i, volatile atomic_t *v)
35{
36 unsigned long flags;
37 int res;
38
39 local_irq_save (flags);
40 res = v->counter + i;
41 v->counter = res;
42 local_irq_restore (flags);
43
44 return res;
45}
46
47static __inline__ int atomic_sub_return (int i, volatile atomic_t *v)
48{
49 unsigned long flags;
50 int res;
51
52 local_irq_save (flags);
53 res = v->counter - i;
54 v->counter = res;
55 local_irq_restore (flags);
56
57 return res;
58}
59
60static __inline__ void atomic_clear_mask (unsigned long mask, unsigned long *addr)
61{
62 unsigned long flags;
63
64 local_irq_save (flags);
65 *addr &= ~mask;
66 local_irq_restore (flags);
67}
68
69#endif
70
71#define atomic_add(i, v) atomic_add_return ((i), (v))
72#define atomic_sub(i, v) atomic_sub_return ((i), (v))
73
74#define atomic_dec_return(v) atomic_sub_return (1, (v))
75#define atomic_inc_return(v) atomic_add_return (1, (v))
76#define atomic_inc(v) atomic_inc_return (v)
77#define atomic_dec(v) atomic_dec_return (v)
78
79/*
80 * atomic_inc_and_test - increment and test
81 * @v: pointer of type atomic_t
82 *
83 * Atomically increments @v by 1
84 * and returns true if the result is zero, or false for all
85 * other cases.
86 */
87#define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
88
89#define atomic_sub_and_test(i,v) (atomic_sub_return ((i), (v)) == 0)
90#define atomic_dec_and_test(v) (atomic_sub_return (1, (v)) == 0)
91#define atomic_add_negative(i,v) (atomic_add_return ((i), (v)) < 0)
92
93/* Atomic operations are already serializing on ARM */
94#define smp_mb__before_atomic_dec() barrier()
95#define smp_mb__after_atomic_dec() barrier()
96#define smp_mb__before_atomic_inc() barrier()
97#define smp_mb__after_atomic_inc() barrier()
98
99#endif /* __V850_ATOMIC_H__ */