]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - include/asm-sh64/atomic.h
1 #ifndef __ASM_SH64_ATOMIC_H
2 #define __ASM_SH64_ATOMIC_H
5 * This file is subject to the terms and conditions of the GNU General Public
6 * License. See the file "COPYING" in the main directory of this archive
9 * include/asm-sh64/atomic.h
11 * Copyright (C) 2000, 2001 Paolo Alberelli
12 * Copyright (C) 2003 Paul Mundt
17 * Atomic operations that C can't guarantee us. Useful for
18 * resource counting etc..
22 typedef struct { volatile int counter
; } atomic_t
;
24 #define ATOMIC_INIT(i) ( (atomic_t) { (i) } )
26 #define atomic_read(v) ((v)->counter)
27 #define atomic_set(v,i) ((v)->counter = (i))
29 #include <asm/system.h>
32 * To get proper branch prediction for the main line, we must branch
33 * forward to code at the end of this object's .text section, then
34 * branch back to restart the operation.
37 static __inline__
void atomic_add(int i
, atomic_t
* v
)
41 local_irq_save(flags
);
43 local_irq_restore(flags
);
46 static __inline__
void atomic_sub(int i
, atomic_t
*v
)
50 local_irq_save(flags
);
52 local_irq_restore(flags
);
55 static __inline__
int atomic_add_return(int i
, atomic_t
* v
)
57 unsigned long temp
, flags
;
59 local_irq_save(flags
);
63 local_irq_restore(flags
);
68 #define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
70 static __inline__
int atomic_sub_return(int i
, atomic_t
* v
)
72 unsigned long temp
, flags
;
74 local_irq_save(flags
);
78 local_irq_restore(flags
);
83 #define atomic_dec_return(v) atomic_sub_return(1,(v))
84 #define atomic_inc_return(v) atomic_add_return(1,(v))
87 * atomic_inc_and_test - increment and test
88 * @v: pointer of type atomic_t
90 * Atomically increments @v by 1
91 * and returns true if the result is zero, or false for all
94 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
96 #define atomic_sub_and_test(i,v) (atomic_sub_return((i), (v)) == 0)
97 #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0)
99 #define atomic_inc(v) atomic_add(1,(v))
100 #define atomic_dec(v) atomic_sub(1,(v))
102 static __inline__
void atomic_clear_mask(unsigned int mask
, atomic_t
*v
)
106 local_irq_save(flags
);
108 local_irq_restore(flags
);
111 static __inline__
void atomic_set_mask(unsigned int mask
, atomic_t
*v
)
115 local_irq_save(flags
);
117 local_irq_restore(flags
);
120 /* Atomic operations are already serializing on SH */
121 #define smp_mb__before_atomic_dec() barrier()
122 #define smp_mb__after_atomic_dec() barrier()
123 #define smp_mb__before_atomic_inc() barrier()
124 #define smp_mb__after_atomic_inc() barrier()
126 #endif /* __ASM_SH64_ATOMIC_H */