Przeglądaj źródła

threadContext: improve JsSetCurrentContext calls

- also fix a wrong definition override
Oguz Bastemur 8 lat temu
rodzic
commit
e75f73be44

+ 0 - 1
lib/Common/CommonPal.h

@@ -28,7 +28,6 @@
 #else // Windows
     #define _ALWAYSINLINE __forceinline
     #define _NOINLINE __declspec(noinline)
-    #define __forceinline inline
 #endif
 
 // Only VC compiler support overflow guard

+ 3 - 0
lib/Jsrt/JsrtContext.cpp

@@ -87,6 +87,9 @@ bool JsrtContext::TrySetCurrent(JsrtContext * context)
         {
             return false;
         }
+        // no need to rootAddRef and Release for the same context
+        if (s_tlvSlot == context) return true;
+
         threadContext->GetRecycler()->RootAddRef((LPVOID)context);
     }
     else

+ 14 - 7
lib/Runtime/Base/ThreadContextTlsEntry.cpp

@@ -92,17 +92,24 @@ bool ThreadContextTLSEntry::TrySetThreadContext(ThreadContext * threadContext)
         ENTRY_FOR_CURRENT_THREAD() = entry;
 #endif
     }
-    else if (entry->threadContext != NULL && entry->threadContext != threadContext)
+    else if (entry->threadContext != NULL)
     {
-        // If the thread has an active thread context and either that thread context is thread
-        // bound (in which case it cannot be moved off this thread), or if the thread context
-        // is running script, you cannot move it off this thread.
-        if (entry->threadContext->IsThreadBound() || entry->threadContext->IsInScript())
+        if (entry->threadContext == threadContext)
         {
-            return false;
+            return true;
         }
+        else
+        {
+            // If the thread has an active thread context and either that thread context is thread
+            // bound (in which case it cannot be moved off this thread), or if the thread context
+            // is running script, you cannot move it off this thread.
+            if (entry->threadContext->IsThreadBound() || entry->threadContext->IsInScript())
+            {
+                return false;
+            }
 
-        ClearThreadContext(entry, true);
+            ClearThreadContext(entry, true);
+        }
     }
 
     SetThreadContext(entry, threadContext);