Re: MemoryFence()


Paolo Bonzini <pbonzini@...>
 

Il ven 5 feb 2021, 19:21 Laszlo Ersek <lersek@...> ha scritto:

ReleaseMemoryFence ();
*SpinLock = SPIN_LOCK_RELEASED;
No concern that the store might not be atomic?
Not as long as it's a pointer or smaller.
This is why I'd like someone else to write the primitives :)
To expand: it is an assumption on the implementation of the C compiler; it
admittedly goes beyond the C standard but it is a reasonable assumption,
compilers may *merge* loads and stores but have no reason to split aligned
loads and stores. Likewise for processors (the pointer limitation is
because sizes larger than the pointer's may not have an instruction that
reads or writes them atomically).

The standard would require you to use C11 atomic loads and stores, but as
far as I understand you cannot assume that they exist on all edk2 compilers.

- Is it architecture-dependent?
No.

- Is it alignment-dependent?
Unaligned pointers are already undefined behavior so you can ignore how
they are dealt with at the processor level.

Paolo


etc... :)

(I'm not challenging your statement of course; I know I should have
known, just not sure where from...)

Thanks,
Laszlo

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