Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / score / include / asm / cmpxchg.h
blobe503073c89789986e7c991f88b289a65720c61d2
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_SCORE_CMPXCHG_H
3 #define _ASM_SCORE_CMPXCHG_H
5 #include <linux/irqflags.h>
7 struct __xchg_dummy { unsigned long a[100]; };
8 #define __xg(x) ((struct __xchg_dummy *)(x))
10 static inline
11 unsigned long __xchg(volatile unsigned long *m, unsigned long val)
13 unsigned long retval;
14 unsigned long flags;
16 local_irq_save(flags);
17 retval = *m;
18 *m = val;
19 local_irq_restore(flags);
20 return retval;
23 #define xchg(ptr, v) \
24 ((__typeof__(*(ptr))) __xchg((unsigned long *)(ptr), \
25 (unsigned long)(v)))
27 static inline unsigned long __cmpxchg(volatile unsigned long *m,
28 unsigned long old, unsigned long new)
30 unsigned long retval;
31 unsigned long flags;
33 local_irq_save(flags);
34 retval = *m;
35 if (retval == old)
36 *m = new;
37 local_irq_restore(flags);
38 return retval;
41 #define cmpxchg(ptr, o, n) \
42 ((__typeof__(*(ptr))) __cmpxchg((unsigned long *)(ptr), \
43 (unsigned long)(o), \
44 (unsigned long)(n)))
46 #include <asm-generic/cmpxchg-local.h>
48 #endif /* _ASM_SCORE_CMPXCHG_H */