Reset: Nasal additions to force GC, clear saved refs.

This commit is contained in:
James Turner
2013-10-06 19:11:50 +02:00
parent aeb0e9aac3
commit 7fdf42b699
3 changed files with 23 additions and 0 deletions

View File

@@ -765,6 +765,14 @@ void naSave(naContext ctx, naRef obj)
naVec_append(globals->save, obj);
}
void naClearSaved()
{
naContext c;
c = naNewContext();
globals->save = naNewVector(c);
naFreeContext(c);
}
int naStackDepth(naContext ctx)
{
return ctx ? ctx->fTop + naStackDepth(ctx->callChild): 0;

View File

@@ -118,6 +118,15 @@ static void bottleneck()
}
}
void naGC()
{
LOCK();
globals->needGC = 1;
bottleneck();
UNLOCK();
naCheckBottleneck();
}
void naCheckBottleneck()
{
if(globals->bottleneck) { LOCK(); bottleneck(); UNLOCK(); }

View File

@@ -42,10 +42,16 @@ naContext naSubContext(naContext super);
void naSetUserData(naContext c, void* p);
void* naGetUserData(naContext c) GCC_PURE;
// run GC now (may block)
void naGC();
// "Save" this object in the context, preventing it (and objects
// referenced by it) from being garbage collected.
void naSave(naContext ctx, naRef obj);
// Drop all saved references
void naClearSaved();
// Similar, but the object is automatically released when the
// context next runs native bytecode. Useful for saving off C-space
// temporaries to protect them before passing back into a naCall.