InterlockedCompareExchange128 is a bit more complicated than the other InterlockedCompareExchange functions, so it requires a bit more work. It doesn't directly refer to 128bit ints, instead it takes pointers to 64bit ints for Destination and ComparandResult, and exchange is taken as two 64bit ints (high & low). The previous value is written to ComparandResult, and success is returned. This implementation does the following in order to produce a cmpxchg instruction:
- Cast everything to 128bit ints or int pointers, and glues together the Exchange values
- Reads from CompareandResult to get the comparand
- Calls cmpxchg volatile (on X86 this will produce a lock cmpxchg16b instruction)
- Result 0 (previous value) is written back to ComparandResult
- Result 1 (success bool) is zext'ed to a uchar and returned
Resolves bug 35251