Changeset View
Changeset View
Standalone View
Standalone View
sys/compat/linuxkpi/common/include/asm/atomic.h
Context not available. | |||||
return (ret); | return (ret); | ||||
} | } | ||||
#define cmpxchg(ptr, old, new) ({ \ | #define cmpxchg(ptr, old, new) ({ \ | ||||
__typeof(*(ptr)) __ret; \ | union { \ | ||||
\ | __typeof(*(ptr)) val; \ | ||||
CTASSERT(sizeof(__ret) == 1 || sizeof(__ret) == 2 || \ | u8 u8[0]; \ | ||||
sizeof(__ret) == 4 || sizeof(__ret) == 8); \ | u16 u16[0]; \ | ||||
\ | u32 u32[0]; \ | ||||
__ret = (old); \ | u64 u64[0]; \ | ||||
switch (sizeof(__ret)) { \ | } __ret = { .val = (old) }, __new = { .val = (new) }; \ | ||||
case 1: \ | \ | ||||
while (!atomic_fcmpset_8((volatile int8_t *)(ptr), \ | CTASSERT(sizeof(__ret) == 1 || sizeof(__ret) == 2 || \ | ||||
(int8_t *)&__ret, (new)) && __ret == (old)) \ | sizeof(__ret) == 4 || sizeof(__ret) == 8); \ | ||||
; \ | \ | ||||
break; \ | switch (sizeof(__ret.val)) { \ | ||||
case 2: \ | case 1: \ | ||||
while (!atomic_fcmpset_16((volatile int16_t *)(ptr), \ | while (!atomic_fcmpset_8((volatile u8 *)(ptr), \ | ||||
(int16_t *)&__ret, (new)) && __ret == (old)) \ | __ret.u8, __new.u8[0]) && __ret.val == (old)) \ | ||||
; \ | ; \ | ||||
break; \ | break; \ | ||||
case 4: \ | case 2: \ | ||||
while (!atomic_fcmpset_32((volatile int32_t *)(ptr), \ | while (!atomic_fcmpset_16((volatile u16 *)(ptr), \ | ||||
(int32_t *)&__ret, (new)) && __ret == (old)) \ | __ret.u16, __new.u16[0]) && __ret.val == (old)) \ | ||||
; \ | ; \ | ||||
break; \ | break; \ | ||||
case 8: \ | case 4: \ | ||||
while (!atomic_fcmpset_64((volatile int64_t *)(ptr), \ | while (!atomic_fcmpset_32((volatile u32 *)(ptr), \ | ||||
(int64_t *)&__ret, (new)) && __ret == (old)) \ | __ret.u32, __new.u32[0]) && __ret.val == (old)) \ | ||||
; \ | ; \ | ||||
break; \ | break; \ | ||||
} \ | case 8: \ | ||||
__ret; \ | while (!atomic_fcmpset_64((volatile u64 *)(ptr), \ | ||||
__ret.u64, __new.u64[0]) && __ret.val == (old)) \ | |||||
; \ | |||||
break; \ | |||||
} \ | |||||
__ret.val; \ | |||||
markj: I can't immediately see the purpose of this change. | |||||
Done Inline ActionsThere was a build error with the previous cmpxchg which is why I included this in the merge. I don't know who wrote it but assumed it fixed something. johalun0_gmail.com: There was a build error with the previous cmpxchg which is why I included this in the merge. I… | |||||
Done Inline ActionsWhy add a default case? We definitely don't want to silently proceed there. markj: Why add a default case? We definitely don't want to silently proceed there. | |||||
Not Done Inline ActionsThe CTASSERT() will take that one. hselasky: The CTASSERT() will take that one. | |||||
}) | }) | ||||
#define cmpxchg_relaxed(...) cmpxchg(__VA_ARGS__) | #define cmpxchg_relaxed(...) cmpxchg(__VA_ARGS__) | ||||
Context not available. |
I can't immediately see the purpose of this change.