target: Fix kref->refcount underflow in transport_cmd_finish_abort
[linux/fpc-iii.git] / arch / sh / include / asm / bitops-cas.h
blob88f793c04d3cf0388702ad461ccd15554ebeee8b
1 #ifndef __ASM_SH_BITOPS_CAS_H
2 #define __ASM_SH_BITOPS_CAS_H
4 static inline unsigned __bo_cas(volatile unsigned *p, unsigned old, unsigned new)
6 __asm__ __volatile__("cas.l %1,%0,@r0"
7 : "+r"(new)
8 : "r"(old), "z"(p)
9 : "t", "memory" );
10 return new;
13 static inline void set_bit(int nr, volatile void *addr)
15 unsigned mask, old;
16 volatile unsigned *a = addr;
18 a += nr >> 5;
19 mask = 1U << (nr & 0x1f);
21 do old = *a;
22 while (__bo_cas(a, old, old|mask) != old);
25 static inline void clear_bit(int nr, volatile void *addr)
27 unsigned mask, old;
28 volatile unsigned *a = addr;
30 a += nr >> 5;
31 mask = 1U << (nr & 0x1f);
33 do old = *a;
34 while (__bo_cas(a, old, old&~mask) != old);
37 static inline void change_bit(int nr, volatile void *addr)
39 unsigned mask, old;
40 volatile unsigned *a = addr;
42 a += nr >> 5;
43 mask = 1U << (nr & 0x1f);
45 do old = *a;
46 while (__bo_cas(a, old, old^mask) != old);
49 static inline int test_and_set_bit(int nr, volatile void *addr)
51 unsigned mask, old;
52 volatile unsigned *a = addr;
54 a += nr >> 5;
55 mask = 1U << (nr & 0x1f);
57 do old = *a;
58 while (__bo_cas(a, old, old|mask) != old);
60 return !!(old & mask);
63 static inline int test_and_clear_bit(int nr, volatile void *addr)
65 unsigned mask, old;
66 volatile unsigned *a = addr;
68 a += nr >> 5;
69 mask = 1U << (nr & 0x1f);
71 do old = *a;
72 while (__bo_cas(a, old, old&~mask) != old);
74 return !!(old & mask);
77 static inline int test_and_change_bit(int nr, volatile void *addr)
79 unsigned mask, old;
80 volatile unsigned *a = addr;
82 a += nr >> 5;
83 mask = 1U << (nr & 0x1f);
85 do old = *a;
86 while (__bo_cas(a, old, old^mask) != old);
88 return !!(old & mask);
91 #include <asm-generic/bitops/non-atomic.h>
93 #endif /* __ASM_SH_BITOPS_CAS_H */