/* * Atomic xchg and cmpxchg operations. * * This file is subject to the terms and conditions of the GNU General Public * License. See the file "COPYING" in the main directory of this archive * for more details. * * Copyright (C) 2001 - 2005 Tensilica Inc.
*/
/* * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make * them available.
*/ #define arch_cmpxchg_local(ptr, o, n) \
((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsignedlong)(o),\
(unsignedlong)(n), sizeof(*(ptr)))) #define arch_cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n)) #define arch_cmpxchg64(ptr, o, n) arch_cmpxchg64_local((ptr), (o), (n))
/* * xchg_u32 * * Note that a14 is used here because the register allocation * done by the compiler is not guaranteed and a window overflow * may not occur between the rsil and wsr instructions. By using * a14 in the rsil, the machine is guaranteed to be in a state * where no register reference will cause an overflow.
*/
staticinline u32 xchg_small(volatilevoid *ptr, u32 x, int size)
{ int off = (unsignedlong)ptr % sizeof(u32); volatile u32 *p = ptr - off; #ifdef __BIG_ENDIAN int bitoff = (sizeof(u32) - size - off) * BITS_PER_BYTE; #else int bitoff = off * BITS_PER_BYTE; #endif
u32 bitmask = ((0x1 << size * BITS_PER_BYTE) - 1) << bitoff;
u32 oldv, newv;
u32 ret;
do {
oldv = READ_ONCE(*p);
ret = (oldv & bitmask) >> bitoff;
newv = (oldv & ~bitmask) | (x << bitoff);
} while (__cmpxchg_u32(p, oldv, newv) != oldv);
return ret;
}
/* * This only works if the compiler isn't horribly bad at optimizing. * gcc-2.5.8 reportedly can't handle this, but I define that one to * be dead anyway.
*/
externvoid __xchg_called_with_bad_pointer(void);
static __inline__ unsignedlong
__arch_xchg(unsignedlong x, volatilevoid * ptr, int size)
{ switch (size) { case 1: return xchg_small(ptr, x, 1); case 2: return xchg_small(ptr, x, 2); case 4: return xchg_u32(ptr, x); default:
__xchg_called_with_bad_pointer(); return x;
}
}
#endif/* __ASSEMBLER__ */
#endif/* _XTENSA_CMPXCHG_H */
Messung V0.5
¤ Dauer der Verarbeitung: 0.12 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.