2 * cmpxchg.h -- forked from asm/atomic.h with this copyright:
4 * Copyright 2010 Tilera Corporation. All Rights Reserved.
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation, version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
13 * NON INFRINGEMENT. See the GNU General Public License for
18 #ifndef _ASM_TILE_CMPXCHG_H
19 #define _ASM_TILE_CMPXCHG_H
23 /* Nonexistent functions intended to cause link errors. */
24 extern unsigned long __xchg_called_with_bad_pointer(void);
25 extern unsigned long __cmpxchg_called_with_bad_pointer(void);
27 #define xchg(ptr, x) \
30 switch (sizeof(*(ptr))) { \
32 __x = (typeof(__x))(typeof(__x-__x))atomic_xchg( \
34 (u32)(typeof((x)-(x)))(x)); \
37 __x = (typeof(__x))(typeof(__x-__x))atomic64_xchg( \
38 (atomic64_t *)(ptr), \
39 (u64)(typeof((x)-(x)))(x)); \
42 __xchg_called_with_bad_pointer(); \
47 #define cmpxchg(ptr, o, n) \
50 switch (sizeof(*(ptr))) { \
52 __x = (typeof(__x))(typeof(__x-__x))atomic_cmpxchg( \
54 (u32)(typeof((o)-(o)))(o), \
55 (u32)(typeof((n)-(n)))(n)); \
58 __x = (typeof(__x))(typeof(__x-__x))atomic64_cmpxchg( \
59 (atomic64_t *)(ptr), \
60 (u64)(typeof((o)-(o)))(o), \
61 (u64)(typeof((n)-(n)))(n)); \
64 __cmpxchg_called_with_bad_pointer(); \
69 #define tas(ptr) (xchg((ptr), 1))
71 #endif /* __ASSEMBLY__ */
73 #endif /* _ASM_TILE_CMPXCHG_H */