Re: MemoryFence()


Paolo Bonzini <pbonzini@...>
 

On 05/02/21 08:48, Laszlo Ersek wrote:
MemoryFence ();
do {
Value = *Address
} while (Value == 0xFF) ;
MemoryFence ();
If Address points to a byte in RAM that's manipulated by
multiple CPUs, then I think:
- volatile is not needed
- the two MemoryFence() calls should be removed
- an AcquireMemoryFence() call should be inserted into the loop, after
the read access. Because, presumably, once the flag assumes the
appropriate value (it has been "released")), we'll proceed to reading
some memory resource that was protected by the flag until then.
This is correct, alternatively you could have this:

do {
// Force re-reading *Address on every iteration
CompilerFence ();
Value = *Address;
} while (Value == 0xFF);
// As you explained above.
AcquireMemoryFence ();

Paolo

Join rfc@edk2.groups.io to automatically receive all group messages.