mirror of
https://git.tesses.org/tesses50/crosslang.git
synced 2026-09-30 16:54:14 +00:00
First commit
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#include "CrossLang.hpp"
|
||||
|
||||
namespace Tesses::CrossLang
|
||||
{
|
||||
GCList::GCList(GC* gc)
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
this->gc = gc;
|
||||
gc->SetRoot(this);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
GCList::GCList(GC& gc)
|
||||
{
|
||||
gc.BarrierBegin();
|
||||
this->gc = &gc;
|
||||
gc.SetRoot(this);
|
||||
gc.BarrierEnd();
|
||||
}
|
||||
GC* GCList::GetGC()
|
||||
{
|
||||
return this->gc;
|
||||
}
|
||||
void GCList::Remove(TObject obj)
|
||||
{
|
||||
if(std::holds_alternative<THeapObjectHolder>(obj))
|
||||
{
|
||||
auto _item=std::get<THeapObjectHolder>(obj).obj;
|
||||
this->gc->BarrierBegin();
|
||||
for(auto index = this->items.begin();index<this->items.end();index++)
|
||||
{
|
||||
if(*index == _item)
|
||||
{
|
||||
this->items.erase(index);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
this->gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
void GCList::Add(TObject obj)
|
||||
{
|
||||
|
||||
if(std::holds_alternative<THeapObjectHolder>(obj))
|
||||
{
|
||||
auto _item=std::get<THeapObjectHolder>(obj).obj;
|
||||
this->gc->BarrierBegin();
|
||||
|
||||
for(auto item : this->items)
|
||||
{
|
||||
if(item == _item) {
|
||||
this->gc->BarrierEnd();
|
||||
return;
|
||||
}
|
||||
}
|
||||
this->items.push_back(_item);
|
||||
this->gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
void GCList::Mark()
|
||||
{
|
||||
this->marked=true;
|
||||
for(auto item : this->items)
|
||||
{
|
||||
item->Mark();
|
||||
}
|
||||
}
|
||||
GCList::~GCList()
|
||||
{
|
||||
gc->BarrierBegin();
|
||||
this->gc->UnsetRoot(this);
|
||||
gc->BarrierEnd();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user