diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-12-20 16:17:46 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2010-12-20 16:17:46 -0200 |
commit | 737f119187aca3c8f6743ec6e3cfc04e83723180 (patch) | |
tree | 4e1bfb4b2bef35dd2acfe2915ab51481cd9ebc16 /lgc.c | |
parent | 8980c630bf40e05dad71ded377e3d0f0a17b076c (diff) | |
download | lua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.gz lua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.bz2 lua-737f119187aca3c8f6743ec6e3cfc04e83723180.zip |
better control for GC running or stopped
Diffstat (limited to 'lgc.c')
-rw-r--r-- | lgc.c | 21 |
1 files changed, 12 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.104 2010/11/26 14:32:31 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.105 2010/12/03 11:48:25 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -715,15 +715,15 @@ static void GCTM (lua_State *L, int propagateerrors) { | |||
715 | if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ | 715 | if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */ |
716 | int status; | 716 | int status; |
717 | lu_byte oldah = L->allowhook; | 717 | lu_byte oldah = L->allowhook; |
718 | lu_mem oldd = g->GCdebt; | 718 | int running = g->gcrunning; |
719 | L->allowhook = 0; /* stop debug hooks during GC tag method */ | 719 | L->allowhook = 0; /* stop debug hooks during GC tag method */ |
720 | stopgc(g); /* avoid GC steps */ | 720 | g->gcrunning = 0; /* avoid GC steps */ |
721 | setobj2s(L, L->top, tm); /* push finalizer... */ | 721 | setobj2s(L, L->top, tm); /* push finalizer... */ |
722 | setobj2s(L, L->top + 1, &v); /* ... and its argument */ | 722 | setobj2s(L, L->top + 1, &v); /* ... and its argument */ |
723 | L->top += 2; /* and (next line) call the finalizer */ | 723 | L->top += 2; /* and (next line) call the finalizer */ |
724 | status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); | 724 | status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); |
725 | L->allowhook = oldah; /* restore hooks */ | 725 | L->allowhook = oldah; /* restore hooks */ |
726 | g->GCdebt = oldd; /* restore threshold */ | 726 | g->gcrunning = running; /* restore state */ |
727 | if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ | 727 | if (status != LUA_OK && propagateerrors) { /* error while running __gc? */ |
728 | if (status == LUA_ERRRUN) { /* is there an error msg.? */ | 728 | if (status == LUA_ERRRUN) { /* is there an error msg.? */ |
729 | luaO_pushfstring(L, "error in __gc tag method (%s)", | 729 | luaO_pushfstring(L, "error in __gc tag method (%s)", |
@@ -984,11 +984,14 @@ static void step (lua_State *L) { | |||
984 | 984 | ||
985 | 985 | ||
986 | void luaC_step (lua_State *L) { | 986 | void luaC_step (lua_State *L) { |
987 | int i; | 987 | global_State *g = G(L); |
988 | if (isgenerational(G(L))) generationalcollection(L); | 988 | if (g->gcrunning) { |
989 | else step(L); | 989 | int i; |
990 | for (i = 0; i < GCFINALIZENUM && G(L)->tobefnz; i++) | 990 | if (isgenerational(g)) generationalcollection(L); |
991 | GCTM(L, 1); /* Call a few pending finalizers */ | 991 | else step(L); |
992 | for (i = 0; i < GCFINALIZENUM && g->tobefnz; i++) | ||
993 | GCTM(L, 1); /* Call a few pending finalizers */ | ||
994 | } | ||
992 | } | 995 | } |
993 | 996 | ||
994 | 997 | ||