Skip to content

Commit

Permalink
Merge pull request #265 from Unity-Technologies/fix-threadstatic-cleanup
Browse files Browse the repository at this point in the history
Fix threadstatic cleanup
  • Loading branch information
alexey-zakharov committed Apr 15, 2024
2 parents 349310f + eb84218 commit 41138ef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 1 addition & 3 deletions src/coreclr/vm/loaderallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -964,13 +964,11 @@ void LoaderAllocator::SetHandleValue(LOADERHANDLE handle, OBJECTREF value)
{
NOTHROW;
GC_NOTRIGGER;
MODE_ANY;
MODE_COOPERATIVE;
PRECONDITION(handle != NULL);
}
CONTRACTL_END;

GCX_COOP();

GCPROTECT_BEGIN(value);

// If the slot value does have the low bit set, then it is a simple pointer to the value
Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/vm/threadstatics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ void ThreadLocalBlock::FreeTLM(SIZE_T i, BOOL isThreadShuttingdown)
{
ThreadLocalModule::CollectibleDynamicEntry *entry = (ThreadLocalModule::CollectibleDynamicEntry*)pThreadLocalModule->m_pDynamicClassTable[k].m_pDynamicEntry;
PTR_LoaderAllocator pLoaderAllocator = entry->m_pLoaderAllocator;
// Skip assemblies that are already unloaded
if (!pLoaderAllocator->IsUnloaded())

// LoaderAllocator may be collected when the thread is shutting down.
// We enter coop mode to ensure that we get a valid value of the exposed object and
// can safely clean up handles if it is not yet collected.
GCX_COOP();

LOADERALLOCATORREF loaderAllocator = pLoaderAllocator->GetExposedObject();
if (loaderAllocator != NULL)
{
if (entry->m_hGCStatics != NULL)
{
Expand Down

0 comments on commit 41138ef

Please sign in to comment.