Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/hx/gc/Immix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2372,21 +2372,24 @@ void MarkStringArray(String *inPtr, int inLength, hx::MarkContext *__inCtx)

FILE_SCOPE std::mutex* sGCRootLock = nullptr;
typedef std::unordered_set<hx::Object **> RootSet;
static RootSet sgRootSet;
// Never freed. Threads that are still running when the process exits, such as the thread pools of
// native libraries, remove their roots from thread-local destructors (see ThreadInfoHolder), which
// can run after the destructors of static objects. A static set would already be destroyed by then.
static RootSet *sgRootSet = new RootSet();

typedef std::unordered_map<void *,int> OffsetRootSet;
static OffsetRootSet *sgOffsetRootSet=0;

void GCAddRoot(hx::Object **inRoot)
{
std::lock_guard<std::mutex> lock(*sGCRootLock);
sgRootSet.insert(inRoot);
sgRootSet->insert(inRoot);
}

void GCRemoveRoot(hx::Object **inRoot)
{
std::lock_guard<std::mutex> lock(*sGCRootLock);
sgRootSet.erase(inRoot);
sgRootSet->erase(inRoot);
}


Expand Down Expand Up @@ -4270,7 +4273,7 @@ class GlobalAllocator
// Threads in GC free zones, or not registered at all, can still add and remove roots
std::lock_guard<std::mutex> rootLock(*hx::sGCRootLock);

for(hx::RootSet::iterator i = hx::sgRootSet.begin(); i!=hx::sgRootSet.end(); ++i)
for(hx::RootSet::iterator i = hx::sgRootSet->begin(); i!=hx::sgRootSet->end(); ++i)
{
hx::Object **obj = *i;
if (*obj)
Expand Down Expand Up @@ -4720,7 +4723,7 @@ class GlobalAllocator
// Threads in GC free zones, or not registered at all, can still add and remove roots
std::lock_guard<std::mutex> rootLock(*hx::sGCRootLock);

for(hx::RootSet::iterator i = hx::sgRootSet.begin(); i!=hx::sgRootSet.end(); ++i)
for(hx::RootSet::iterator i = hx::sgRootSet->begin(); i!=hx::sgRootSet->end(); ++i)
{
hx::Object *&obj = **i;
if (obj)
Expand Down
Loading