Yes, code compiles but it is incorrect:
| inline uint32 AtomicCompareExchangeUInt32(uint32 volatile *Value, uint32 New, uint32 Expected)
{
uint32 Result = __sync_val_compare_and_swap((long *)Value, Expected, New);
return(Result);
}
|
Value is pointer to 32-bit memory location, but (long*)Value cast makes compiler to generate 64-bit lock cmpxchg instruction, because long on 64-bit Linux/OSX is 64-bit value.
You don't need to use any cast, because compiler will automatically determine type of Value variable:
| uint32 Result = __sync_val_compare_and_swap(Value, Expected, New);
|