diff --git a/src/coreclr/gc/env/volatile.h b/src/coreclr/gc/env/volatile.h index 285bb5ffa19..42910a1ce97 100644 --- a/src/coreclr/gc/env/volatile.h +++ b/src/coreclr/gc/env/volatile.h @@ -297,6 +297,27 @@ void VolatileStoreWithoutBarrier(T* pt, T val) #endif } +// +// Memory ordering barrier that waits for loads in progress to complete. +// Any effects of loads or stores that appear after, in program order, will "happen after" relative to this. +// Other operations such as computation or instruction prefetch are not affected. +// +// Architectural mapping: +// arm64 : dmb ishld +// arm : dmb ish +// x86/64 : compiler fence +inline +void VolatileLoadBarrier() +{ +#if defined(HOST_ARM64) && defined(__GNUC__) + asm volatile ("dmb ishld" : : : "memory"); +#elif defined(HOST_ARM64) && defined(_MSC_VER) + __dmb(_ARM64_BARRIER_ISHLD); +#else + VOLATILE_MEMORY_BARRIER(); +#endif +} + // // Volatile implements accesses with our volatile semantics over a variable of type T. // Wherever you would have used a "volatile Foo" or, equivalently, "Foo volatile", use Volatile diff --git a/src/coreclr/gc/satori/SatoriLock.h b/src/coreclr/gc/satori/SatoriLock.h index 89c3e5fa5e8..bd8fbae8f04 100644 --- a/src/coreclr/gc/satori/SatoriLock.h +++ b/src/coreclr/gc/satori/SatoriLock.h @@ -79,7 +79,7 @@ public: } #if !defined(TARGET_AMD64) - MemoryBarrier(); + VolatileLoadBarrier(); #endif }