From: James Turner Date: Sun, 6 Oct 2013 17:11:50 +0000 (+0200) Subject: Reset: Nasal additions to force GC, clear saved refs. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=7fdf42b69969ddea8eedaeef6380ddb6604250c7;p=simgear.git Reset: Nasal additions to force GC, clear saved refs. --- diff --git a/simgear/nasal/code.c b/simgear/nasal/code.c index 5601b074..0ce9b053 100644 --- a/simgear/nasal/code.c +++ b/simgear/nasal/code.c @@ -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; diff --git a/simgear/nasal/gc.c b/simgear/nasal/gc.c index 9773c795..c3f1e660 100644 --- a/simgear/nasal/gc.c +++ b/simgear/nasal/gc.c @@ -118,6 +118,15 @@ static void bottleneck() } } +void naGC() +{ + LOCK(); + globals->needGC = 1; + bottleneck(); + UNLOCK(); + naCheckBottleneck(); +} + void naCheckBottleneck() { if(globals->bottleneck) { LOCK(); bottleneck(); UNLOCK(); } diff --git a/simgear/nasal/nasal.h b/simgear/nasal/nasal.h index db7354ea..e57c856b 100644 --- a/simgear/nasal/nasal.h +++ b/simgear/nasal/nasal.h @@ -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.