summaryrefslogtreecommitdiff
path: root/src/vm/win32threadpool.cpp
diff options
context:
space:
mode:
authorBen Adams <thundercat@illyriad.co.uk>2016-07-28 23:36:12 +0100
committerBen Adams <thundercat@illyriad.co.uk>2016-08-09 21:00:07 +0100
commitbfef88129d20c1b4fbf3a56269d1a4e9c50bcc29 (patch)
tree6a7f9f83c24eec9ae7b2ce5571fb1bfecb90318d /src/vm/win32threadpool.cpp
parent6f645eb0fda0c4fcf3f2daa45e18d798335dcd4a (diff)
downloadcoreclr-bfef88129d20c1b4fbf3a56269d1a4e9c50bcc29.tar.gz
coreclr-bfef88129d20c1b4fbf3a56269d1a4e9c50bcc29.tar.bz2
coreclr-bfef88129d20c1b4fbf3a56269d1a4e9c50bcc29.zip
WorkerThreadStart volatile read+cmpxchg loop
Diffstat (limited to 'src/vm/win32threadpool.cpp')
-rw-r--r--src/vm/win32threadpool.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/src/vm/win32threadpool.cpp b/src/vm/win32threadpool.cpp
index 95fa5c0ca5..8600484e27 100644
--- a/src/vm/win32threadpool.cpp
+++ b/src/vm/win32threadpool.cpp
@@ -1271,7 +1271,8 @@ void ThreadpoolMgr::MaybeAddWorkingWorker()
_ASSERTE(!CLRThreadpoolHosted());
- ThreadCounter::Counts counts = WorkerCounter.GetCleanCounts();
+ // counts volatile read paired with CompareExchangeCounts loop set
+ ThreadCounter::Counts counts = WorkerCounter.DangerousGetDirtyCounts();
ThreadCounter::Counts newCounts;
while (true)
{
@@ -1325,7 +1326,9 @@ void ThreadpoolMgr::MaybeAddWorkingWorker()
// Of course, there's no guarantee *that* will work - but hopefully enough time will have passed
// to allow whoever's using all the memory right now to release some.
//
- counts = WorkerCounter.GetCleanCounts();
+
+ // counts volatile read paired with CompareExchangeCounts loop set
+ counts = WorkerCounter.DangerousGetDirtyCounts();
while (true)
{
//
@@ -2255,7 +2258,8 @@ DWORD __stdcall ThreadpoolMgr::WorkerThreadStart(LPVOID lpArgs)
ThreadCounter::Counts counts, oldCounts, newCounts;
bool foundWork = true, wasNotRecalled = true;
- counts = WorkerCounter.GetCleanCounts();
+ // counts only used for Etw event
+ counts = WorkerCounter.DangerousGetDirtyCounts();
FireEtwThreadPoolWorkerThreadStart(counts.NumActive, counts.NumRetired, GetClrInstanceId());
#ifdef FEATURE_COMINTEROP
@@ -2286,7 +2290,8 @@ Work:
#ifdef FEATURE_COMINTEROP
if (pThread->SetApartment(Thread::AS_InMTA, TRUE) != Thread::AS_InMTA)
{
- counts = WorkerCounter.GetCleanCounts();
+ // counts volatile read paired with CompareExchangeCounts loop set
+ counts = WorkerCounter.DangerousGetDirtyCounts();
while (true)
{
newCounts = counts;
@@ -2311,7 +2316,8 @@ Work:
// make sure there's really work. If not, go back to sleep
- counts = WorkerCounter.GetCleanCounts();
+ // counts volatile read paired with CompareExchangeCounts loop set
+ counts = WorkerCounter.DangerousGetDirtyCounts();
while (true)
{
_ASSERTE(counts.NumActive > 0);
@@ -2383,7 +2389,8 @@ Work:
Retire:
- counts = WorkerCounter.GetCleanCounts();
+ // counts only used for Etw event
+ counts = WorkerCounter.DangerousGetDirtyCounts();
FireEtwThreadPoolWorkerThreadRetirementStart(counts.NumActive, counts.NumRetired, GetClrInstanceId());
// It's possible that some work came in just before we decremented the active thread count, in which
@@ -2403,7 +2410,9 @@ RetryRetire:
if (WAIT_OBJECT_0 == result)
{
foundWork = true;
- counts = WorkerCounter.GetCleanCounts();
+
+ // counts only used for Etw event
+ counts = WorkerCounter.DangerousGetDirtyCounts();
FireEtwThreadPoolWorkerThreadRetirementStop(counts.NumActive, counts.NumRetired, GetClrInstanceId());
goto Work;
}
@@ -2435,7 +2444,9 @@ RetryRetire:
// if we don't hit zero, then there's another retired thread that will pick up this signal. So it's ok
// to exit.
//
- counts = WorkerCounter.GetCleanCounts();
+
+ // counts volatile read paired with CompareExchangeCounts loop set
+ counts = WorkerCounter.DangerousGetDirtyCounts();
while (true)
{
if (counts.NumRetired == 0)
@@ -2491,7 +2502,8 @@ RetryWaitForWork:
DangerousNonHostedSpinLockHolder tal(&ThreadAdjustmentLock);
- counts = WorkerCounter.GetCleanCounts();
+ // counts volatile read paired with CompareExchangeCounts loop set
+ counts = WorkerCounter.DangerousGetDirtyCounts();
while (true)
{
if (counts.NumActive == counts.NumWorking)
@@ -2550,7 +2562,8 @@ Exit:
_ASSERTE(!IsIoPending());
- counts = WorkerCounter.GetCleanCounts();
+ // counts only used for Etw event
+ counts = WorkerCounter.DangerousGetDirtyCounts();
FireEtwThreadPoolWorkerThreadStop(counts.NumActive, counts.NumRetired, GetClrInstanceId());
return ERROR_SUCCESS;