On 30 November 2014 at 18:28, Stefan Dösinger stefandoesinger@gmail.com wrote:
Am 2014-11-28 16:08, schrieb Henri Verbeet:
Do you need the InterlockedCompareExchange()?
Tbh I'm not sure when it is needed and when it isn't, so I chose to go for the safe option. I know the read of device->device_state should be atomic if its address is 4 byte aligned (and if it isn't InterlockedCompareExchange won't help). But on the other hand you've used it for read-only access in the fence implementation in your command stream work. What was the reason for that? Preventing the loop from looping over an unchanged register?
That code wasn't anything particularly final, but InterlockedCompareExchange() implies a memory barrier and would prevent the CPU from seeing stale values. I don't think seeing a stale value would really matter here, but if it does this probably also isn't enough since you're not protected from e.g. focus loss in the middle of a reset either.