From 89e8303f4ea5f1041f3633db7948e7aef17b5226 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 12 Jun 2001 15:43:13 -0300 Subject: more robust treatment of GC tag methods (now they can create new objects while running...) --- lgc.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'lgc.c') diff --git a/lgc.c b/lgc.c index e7d533d3..d3c9490c 100644 --- a/lgc.c +++ b/lgc.c @@ -1,5 +1,5 @@ /* -** $Id: lgc.c,v 1.101 2001/06/07 15:01:21 roberto Exp roberto $ +** $Id: lgc.c,v 1.102 2001/06/08 19:01:38 roberto Exp roberto $ ** Garbage Collector ** See Copyright Notice in lua.h */ @@ -18,18 +18,6 @@ #include "ltm.h" -/* -** optional lock for GC -** (when Lua calls GC tag methods it unlocks the regular lock) -*/ -#ifndef lua_lockgc -#define lua_lockgc(L) { -#endif - -#ifndef lua_unlockgc -#define lua_unlockgc(L) } -#endif - typedef struct GCState { Hash *tmark; /* list of marked tables to be visited */ @@ -281,7 +269,7 @@ static void collecttable (lua_State *L) { } -static void collectudata (lua_State *L) { +void luaC_collectudata (lua_State *L) { Udata **p = &G(L)->rootudata; Udata *next; while ((next = *p) != NULL) { @@ -351,9 +339,8 @@ static void callgcTM (lua_State *L, const TObject *obj) { } -static void callgcTMudata (lua_State *L) { +void luaC_callgcTMudata (lua_State *L) { int tag; - G(L)->GCthreshold = 2*G(L)->nblocks; /* avoid GC during tag methods */ for (tag=G(L)->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ Udata *udata; while ((udata = G(L)->TMtable[tag].collected) != NULL) { @@ -368,14 +355,14 @@ static void callgcTMudata (lua_State *L) { void luaC_collect (lua_State *L, int all) { - lua_lockgc(L); - collectudata(L); - callgcTMudata(L); + luaC_collectudata(L); collectstrings(L, all); collecttable(L); collectproto(L); collectclosure(L); - lua_unlockgc(L); + checkMbuffer(L); + G(L)->GCthreshold = 2*G(L)->nblocks; /* set new threshold */ + luaC_callgcTMudata(L); } @@ -383,8 +370,6 @@ void luaC_collectgarbage (lua_State *L) { markall(L); invalidatetables(G(L)); luaC_collect(L, 0); - checkMbuffer(L); - G(L)->GCthreshold = 2*G(L)->nblocks; /* set new threshold */ callgcTM(L, &luaO_nilobject); } -- cgit v1.2.3-55-g6feb