From 2f14b350960af0354608c041d7df501c44dc5640 Mon Sep 17 00:00:00 2001 From: Koundinya Veluri Date: Mon, 29 Jan 2018 19:08:02 -0800 Subject: Prevent compiler optimization that could cause local var values to change in multithreaded environments, in some places (#16089) --- src/vm/synch.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/vm/synch.h') diff --git a/src/vm/synch.h b/src/vm/synch.h index 30e6c30672..1da2107b8d 100644 --- a/src/vm/synch.h +++ b/src/vm/synch.h @@ -219,6 +219,12 @@ private: return *this; } + Counts VolatileLoadWithoutBarrier() const + { + LIMITED_METHOD_CONTRACT; + return ::VolatileLoadWithoutBarrier(&data); + } + Counts CompareExchange(Counts toCounts, Counts fromCounts) { LIMITED_METHOD_CONTRACT; @@ -264,7 +270,11 @@ public: private: BYTE __padding1[MAX_CACHE_LINE_SIZE]; // padding to ensure that m_counts gets its own cache line + + // Take care to use 'm_counts.VolatileLoadWithoutBarrier()` when loading this value into a local variable that will be + // reused. See AwareLock::m_lockState for details. Counts m_counts; + BYTE __padding2[MAX_CACHE_LINE_SIZE]; // padding to ensure that m_counts gets its own cache line #if defined(DEBUG) -- cgit v1.2.3