Adding comments for thread execution mode in DebuggerRCThread::SendIPCEvent
authorAndrew Au <andrewau@microsoft.com>
Fri, 10 Aug 2018 22:16:48 +0000 (15:16 -0700)
committerAndrew Au <cshung@gmail.com>
Wed, 7 Nov 2018 02:34:47 +0000 (18:34 -0800)
Commit migrated from https://github.com/dotnet/coreclr/commit/1992834d8b4d80ab4227d0e6a7c0f9b6939d890b

src/coreclr/src/debug/ee/rcthread.cpp

index 95d00f7..987c290 100644 (file)
@@ -1777,7 +1777,23 @@ HRESULT DebuggerRCThread::SendIPCEvent()
         NOTHROW;
         GC_NOTRIGGER; // duh, we're in preemptive..
 
-        if (!m_debugger->m_isBlockedOnGarbageCollectionEvent)
+        if (m_debugger->m_isBlockedOnGarbageCollectionEvent)
+        {
+            //
+            // If m_debugger->m_isBlockedOnGarbageCollectionEvent is true, then it must be reporting
+            // either the BeforeGarbageCollection event or the AfterGarbageCollection event
+            // The thread is in preemptive mode during BeforeGarbageCollection
+            // The thread is in cooperative mode during AfterGarbageCollection
+            // In either case, the thread mode doesn't really matter because GC has already taken control
+            // of execution.
+            //
+            // Despite the fact that we are actually in preemptive mode during BeforeGarbageCollection,
+            // because IsGCThread() is true, the EEContract::DoCheck() will happily accept the fact we are
+            // testing for MODE_COOPERATIVE.
+            //
+            MODE_COOPERATIVE;
+        }
+        else
         {
             if (ThisIsHelperThreadWorker())
             {
@@ -1794,8 +1810,6 @@ HRESULT DebuggerRCThread::SendIPCEvent()
                 MODE_PREEMPTIVE;
             }
         }
-
-
         PRECONDITION(ThisMaybeHelperThread());
     }
     CONTRACTL_END;