Insert MemoryBarrier revert Comthreadpool
authorBen Adams <thundercat@illyriad.co.uk>
Tue, 9 Aug 2016 23:15:18 +0000 (00:15 +0100)
committerBen Adams <thundercat@illyriad.co.uk>
Tue, 9 Aug 2016 23:15:18 +0000 (00:15 +0100)
Commit migrated from https://github.com/dotnet/coreclr/commit/519dcde5a6c4fe999e08219e7edd7c9f90e6c96e

src/coreclr/src/vm/comthreadpool.cpp
src/coreclr/src/vm/win32threadpool.cpp
src/coreclr/src/vm/win32threadpool.h

index 8231214..7f629b5 100644 (file)
@@ -251,7 +251,6 @@ FCIMPL0(FC_BOOL_RET, ThreadPoolNative::NotifyRequestComplete)
         pThread->HasCriticalRegion() ||
         pThread->HasThreadAffinity();
 
-    // Read fenced call
     bool shouldAdjustWorkers = ThreadpoolMgr::ShouldAdjustMaxWorkersActive();
 
     // 
@@ -267,15 +266,15 @@ FCIMPL0(FC_BOOL_RET, ThreadPoolNative::NotifyRequestComplete)
     {
         HELPER_METHOD_FRAME_BEGIN_RET_0();
 
-        if (needReset)
-            pThread->InternalReset(FALSE, TRUE, TRUE, FALSE);
-
         if (shouldAdjustWorkers)
         {
             ThreadpoolMgr::AdjustMaxWorkersActive();
             tal.Release();
         }
 
+        if (needReset)
+            pThread->InternalReset(FALSE, TRUE, TRUE, FALSE);
+
         HELPER_METHOD_FRAME_END();    
     }
 
index cc58cea..2ec7ded 100644 (file)
@@ -1262,11 +1262,11 @@ void ThreadpoolMgr::AdjustMaxWorkersActive()
             }
         }
 
-        // Memory fences below writes
-        VolatileStore(&PriorCompletedWorkRequests, totalNumCompletions);
+        PriorCompletedWorkRequests = totalNumCompletions;
         PriorCompletedWorkRequestsTime = currentTicks;
         NextCompletedWorkRequestsTime = currentTicks + ThreadAdjustmentInterval;
         CurrentSampleStartTime = endTime;
+        MemoryBarrier();
     }
 }
 
index 0ca01f8..50eb708 100644 (file)
@@ -1142,8 +1142,9 @@ public:
         if (CLRThreadpoolHosted())
             return false;
 
+        MemoryBarrier();
         DWORD priorTime = PriorCompletedWorkRequestsTime; 
-        DWORD requiredInterval = VolatileLoad(&NextCompletedWorkRequestsTime) - priorTime; // fences above read
+        DWORD requiredInterval = NextCompletedWorkRequestsTime - priorTime; // fences above read
         DWORD elapsedInterval = GetTickCount() - priorTime;
         if (elapsedInterval >= requiredInterval)
         {