summaryrefslogtreecommitdiff
path: root/src/vm/comsynchronizable.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/vm/comsynchronizable.cpp')
-rw-r--r--src/vm/comsynchronizable.cpp50
1 files changed, 41 insertions, 9 deletions
diff --git a/src/vm/comsynchronizable.cpp b/src/vm/comsynchronizable.cpp
index 01ba49651b..8fce346142 100644
--- a/src/vm/comsynchronizable.cpp
+++ b/src/vm/comsynchronizable.cpp
@@ -20,7 +20,6 @@
#include "excep.h"
#include "vars.hpp"
#include "field.h"
-#include "security.h"
#include "comsynchronizable.h"
#include "dbginterface.h"
#include "comdelegate.h"
@@ -29,6 +28,10 @@
#include "appdomain.hpp"
#include "appdomain.inl"
+#ifndef FEATURE_PAL
+#include "utilcode.h"
+#endif
+
#include "newapis.h"
// To include definition of CAPTURE_BUCKETS_AT_TRANSITION
@@ -1543,9 +1546,18 @@ void QCALLTYPE ThreadNative::InformThreadNameChange(QCall::ThreadHandle thread,
QCALL_CONTRACT;
BEGIN_QCALL;
-
+
Thread* pThread = &(*thread);
+#ifndef FEATURE_PAL
+ // Set on Windows 10 Creators Update and later machines the unmanaged thread name as well. That will show up in ETW traces and debuggers which is very helpful
+ // if more and more threads get a meaningful name
+ if (len > 0 && name != NULL)
+ {
+ SetThreadName(pThread->GetThreadHandle(), name);
+ }
+#endif
+
#ifdef PROFILING_SUPPORTED
{
BEGIN_PIN_PROFILER(CORProfilerTrackThreads());
@@ -1612,22 +1624,41 @@ FCIMPL1(FC_BOOL_RET, ThreadNative::IsThreadpoolThread, ThreadBaseObject* thread)
}
FCIMPLEND
+INT32 QCALLTYPE ThreadNative::GetOptimalMaxSpinWaitsPerSpinIteration()
+{
+ QCALL_CONTRACT;
+
+ INT32 optimalMaxNormalizedYieldsPerSpinIteration;
+
+ BEGIN_QCALL;
+
+ Thread::EnsureYieldProcessorNormalizedInitialized();
+ optimalMaxNormalizedYieldsPerSpinIteration = Thread::GetOptimalMaxNormalizedYieldsPerSpinIteration();
+
+ END_QCALL;
+
+ return optimalMaxNormalizedYieldsPerSpinIteration;
+}
FCIMPL1(void, ThreadNative::SpinWait, int iterations)
{
FCALL_CONTRACT;
+ if (iterations <= 0)
+ {
+ return;
+ }
+
//
// If we're not going to spin for long, it's ok to remain in cooperative mode.
// The threshold is determined by the cost of entering preemptive mode; if we're
// spinning for less than that number of cycles, then switching to preemptive
- // mode won't help a GC start any faster. That number is right around 1000000
- // on my machine.
+ // mode won't help a GC start any faster.
//
- if (iterations <= 1000000)
+ if (iterations <= 100000 && Thread::IsYieldProcessorNormalizedInitialized())
{
- for(int i = 0; i < iterations; i++)
- YieldProcessor();
+ for (int i = 0; i < iterations; i++)
+ Thread::YieldProcessorNormalized();
return;
}
@@ -1637,8 +1668,9 @@ FCIMPL1(void, ThreadNative::SpinWait, int iterations)
HELPER_METHOD_FRAME_BEGIN_NOPOLL();
GCX_PREEMP();
- for(int i = 0; i < iterations; i++)
- YieldProcessor();
+ Thread::EnsureYieldProcessorNormalizedInitialized();
+ for (int i = 0; i < iterations; i++)
+ Thread::YieldProcessorNormalized();
HELPER_METHOD_FRAME_END();
}