Handmade Hero»Forums»Code
Kim
Kim Jørgensen
64 posts
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.
Mārtiņš Možeiko
2559 posts / 2 projects
Day 133: GCC WriteBarrier/Interlocked equivalents
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);
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 133: GCC WriteBarrier/Interlocked equivalents
Thanks Martins! I will make the change on the next stream (please remind me if you happen to be watching!)

- Casey
Mārtiņš Možeiko
2559 posts / 2 projects
Day 133: GCC WriteBarrier/Interlocked equivalents
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.
Casey Muratori
801 posts / 1 project
Casey Muratori is a programmer at Molly Rocket on the game 1935 and is the host of the educational programming series Handmade Hero.
Day 133: GCC WriteBarrier/Interlocked equivalents
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