• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef __ASM_METAG_CMPXCHG_LOCK1_H
2 #define __ASM_METAG_CMPXCHG_LOCK1_H
3 
4 #include <asm/global_lock.h>
5 
6 /* Use LOCK2 as these have to be atomic w.r.t. ordinary accesses. */
7 
xchg_u32(volatile u32 * m,unsigned long val)8 static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
9 {
10 	unsigned long flags, retval;
11 
12 	__global_lock2(flags);
13 	fence();
14 	retval = *m;
15 	*m = val;
16 	__global_unlock2(flags);
17 	return retval;
18 }
19 
xchg_u8(volatile u8 * m,unsigned long val)20 static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
21 {
22 	unsigned long flags, retval;
23 
24 	__global_lock2(flags);
25 	fence();
26 	retval = *m;
27 	*m = val & 0xff;
28 	__global_unlock2(flags);
29 	return retval;
30 }
31 
__cmpxchg_u32(volatile int * m,unsigned long old,unsigned long new)32 static inline unsigned long __cmpxchg_u32(volatile int *m, unsigned long old,
33 					  unsigned long new)
34 {
35 	__u32 retval;
36 	unsigned long flags;
37 
38 	__global_lock2(flags);
39 	retval = *m;
40 	if (retval == old) {
41 		fence();
42 		*m = new;
43 	}
44 	__global_unlock2(flags);
45 	return retval;
46 }
47 
48 #endif /* __ASM_METAG_CMPXCHG_LOCK1_H */
49