diff options
author | Ben Adams <thundercat@illyriad.co.uk> | 2016-07-29 18:01:33 +0100 |
---|---|---|
committer | Ben Adams <thundercat@illyriad.co.uk> | 2016-08-09 21:00:07 +0100 |
commit | b8220e45b14ea4174e323b1ca7b74ac2fd128e0e (patch) | |
tree | dbbc02701c62359aabee3512b725792556a886f6 /src/vm/threadpoolrequest.cpp | |
parent | a033207e0dbe403473c4c980d9b5646131d84776 (diff) | |
download | coreclr-b8220e45b14ea4174e323b1ca7b74ac2fd128e0e.tar.gz coreclr-b8220e45b14ea4174e323b1ca7b74ac2fd128e0e.tar.bz2 coreclr-b8220e45b14ea4174e323b1ca7b74ac2fd128e0e.zip |
Adjust fences and add padding
Diffstat (limited to 'src/vm/threadpoolrequest.cpp')
-rw-r--r-- | src/vm/threadpoolrequest.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/src/vm/threadpoolrequest.cpp b/src/vm/threadpoolrequest.cpp index 5b970c8194..3b5cb37c6b 100644 --- a/src/vm/threadpoolrequest.cpp +++ b/src/vm/threadpoolrequest.cpp @@ -362,7 +362,7 @@ void UnManagedPerAppDomainTPCount::SetAppDomainRequestsActive() { WRAPPER_NO_CONTRACT; #ifndef DACCESS_COMPILE - LONG count = m_outstandingThreadRequestCount; + LONG count = VolatileLoad(&m_outstandingThreadRequestCount); while (count < (LONG)ThreadpoolMgr::NumberOfProcessors) { LONG prevCount = FastInterlockCompareExchange(&m_outstandingThreadRequestCount, count+1, count); @@ -383,7 +383,7 @@ void UnManagedPerAppDomainTPCount::SetAppDomainRequestsActive() bool FORCEINLINE UnManagedPerAppDomainTPCount::TakeActiveRequest() { LIMITED_METHOD_CONTRACT; - LONG count = m_outstandingThreadRequestCount; + LONG count = VolatileLoad(&m_outstandingThreadRequestCount); while (count > 0) { @@ -602,7 +602,7 @@ void ManagedPerAppDomainTPCount::SetAppDomainRequestsActive() _ASSERTE(m_id.m_dwId != 0); #ifndef DACCESS_COMPILE - LONG count = m_numRequestsPending; + LONG count = VolatileLoad(&m_numRequestsPending); while (count != ADUnloading) { LONG prev = FastInterlockCompareExchange(&m_numRequestsPending, count+1, count); @@ -631,12 +631,15 @@ void ManagedPerAppDomainTPCount::ClearAppDomainRequestsActive(BOOL bADU) if (bADU) { - m_numRequestsPending = ADUnloading; + VolatileStore(&m_numRequestsPending, ADUnloading); } else { - LONG count = m_numRequestsPending; - while (count != ADUnloading && count > 0) + LONG count = VolatileLoad(&m_numRequestsPending); + // Test is: count > 0 && count != ADUnloading + // Since: const ADUnloading == -1 + // Both are tested: (count > 0) means following also true (count != ADUnloading) + while (count > 0) { LONG prev = FastInterlockCompareExchange(&m_numRequestsPending, 0, count); if (prev == count) @@ -649,8 +652,11 @@ void ManagedPerAppDomainTPCount::ClearAppDomainRequestsActive(BOOL bADU) bool ManagedPerAppDomainTPCount::TakeActiveRequest() { LIMITED_METHOD_CONTRACT; - LONG count = m_numRequestsPending; - while (count != ADUnloading && count > 0) + LONG count = VolatileLoad(&m_numRequestsPending); + // Test is: count > 0 && count != ADUnloading + // Since: const ADUnloading == -1 + // Both are tested: (count > 0) means following also true (count != ADUnloading) + while (count > 0) { LONG prev = FastInterlockCompareExchange(&m_numRequestsPending, count-1, count); if (prev == count) @@ -681,7 +687,7 @@ void ManagedPerAppDomainTPCount::ClearAppDomainUnloading() // it should be, but if it's smaller then we will be permanently out of sync with the // AD. // - m_numRequestsPending = ThreadpoolMgr::NumberOfProcessors; + VolatileStore(&m_numRequestsPending, (LONG)ThreadpoolMgr::NumberOfProcessors); if (!CLRThreadpoolHosted() && ThreadpoolMgr::IsInitialized()) { ThreadpoolMgr::MaybeAddWorkingWorker(); |