summaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-21 10:18:10 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2012-05-21 10:18:10 -0300
commit398811a3131cb025ca61d1a0839e3f99ba632ae9 (patch)
treed9643a0d86495befa7c498de2d9dbcd89fad4779 /lgc.c
parent2a66b34f720cdfb34e3455eb3dbc7fb8aa931981 (diff)
downloadlua-398811a3131cb025ca61d1a0839e3f99ba632ae9.tar.gz
lua-398811a3131cb025ca61d1a0839e3f99ba632ae9.tar.bz2
lua-398811a3131cb025ca61d1a0839e3f99ba632ae9.zip
simpler macro 'luaC_condGC' + better 'step' in 'lua_gc' +
micro bug in 'luaC_checkfinalizer' (current sweep object could be removed from 'allgc' list)
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/lgc.c b/lgc.c
index 219d86d9..435c5e48 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.122 2012/05/14 17:52:56 roberto Exp roberto $ 2** $Id: lgc.c,v 2.123 2012/05/20 20:36:44 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*/
@@ -863,11 +863,18 @@ void luaC_checkfinalizer (lua_State *L, GCObject *o, Table *mt) {
863 return; /* nothing to be done */ 863 return; /* nothing to be done */
864 else { /* move 'o' to 'finobj' list */ 864 else { /* move 'o' to 'finobj' list */
865 GCObject **p; 865 GCObject **p;
866 for (p = &g->allgc; *p != o; p = &gch(*p)->next) ; 866 GCheader *ho = gch(o);
867 *p = gch(o)->next; /* remove 'o' from root list */ 867 /* avoid removing current sweep object */
868 gch(o)->next = g->finobj; /* link it in list 'finobj' */ 868 if (g->gcstate == GCSsweep && g->sweepgc == &ho->next) {
869 /* step to next object in the list */
870 g->sweepgc = (ho->next == NULL) ? NULL : &gch(ho->next)->next;
871 }
872 /* search for pointer pointing to 'o' */
873 for (p = &g->allgc; *p != o; p = &gch(*p)->next) { /* empty */ }
874 *p = ho->next; /* remove 'o' from root list */
875 ho->next = g->finobj; /* link it in list 'finobj' */
869 g->finobj = o; 876 g->finobj = o;
870 l_setbit(gch(o)->marked, SEPARATED); /* mark it as such */ 877 l_setbit(ho->marked, SEPARATED); /* mark it as such */
871 resetoldbit(o); /* see MOVE OLD rule */ 878 resetoldbit(o); /* see MOVE OLD rule */
872 } 879 }
873} 880}
@@ -1085,7 +1092,7 @@ static void step (lua_State *L) {
1085/* 1092/*
1086** performs a basic GC step 1093** performs a basic GC step
1087*/ 1094*/
1088void luaC_step (lua_State *L) { 1095void luaC_forcestep (lua_State *L) {
1089 global_State *g = G(L); 1096 global_State *g = G(L);
1090 int i; 1097 int i;
1091 if (isgenerational(g)) generationalcollection(L); 1098 if (isgenerational(g)) generationalcollection(L);
@@ -1097,6 +1104,17 @@ void luaC_step (lua_State *L) {
1097 1104
1098 1105
1099/* 1106/*
1107** performs a basic GC step only if collector is running
1108*/
1109void luaC_step (lua_State *L) {
1110 global_State *g = G(L);
1111 if (g->gcrunning) luaC_forcestep(L);
1112 else luaE_setdebt(g, -GCSTEPSIZE); /* avoid being called too often */
1113}
1114
1115
1116
1117/*
1100** performs a full GC cycle; if "isemergency", does not call 1118** performs a full GC cycle; if "isemergency", does not call
1101** finalizers (which could change stack positions) 1119** finalizers (which could change stack positions)
1102*/ 1120*/