Day 133: GCC WriteBarrier/Interlocked equivalents

Thank you guys for bringing the issue up during Q&A. Now am I able to compile on GCC again :)

...And of course thanks to Casey for this amazing project.
Yes, code compiles but it is incorrect:
1
2
3
4
5
6
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:
1
    uint32 Result = __sync_val_compare_and_swap(Value, Expected, New);
Thanks Martins! I will make the change on the next stream (please remind me if you happen to be watching!)

- Casey
No problem!
But somebody else will need to remind you this. I work on west coast and watching streams live at 5PM doesn't work well with my job.
I tried to switch this on tonight's stream. Check it out and let me know if it's kosher for your build now!

Thanks,
- Casey