mirror of https://github.com/rusefi/lua.git
"to-be-finalized" objects marked and sweeped like all other objects
This commit is contained in:
parent
ed720d09f3
commit
4aaf0ef75c
24
lgc.c
24
lgc.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lgc.c,v 2.77 2010/04/05 14:15:35 roberto Exp roberto $
|
** $Id: lgc.c,v 2.78 2010/04/12 16:07:06 roberto Exp roberto $
|
||||||
** Garbage Collector
|
** Garbage Collector
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -222,8 +222,7 @@ static void markbeingfnz (global_State *g) {
|
||||||
GCObject *o;
|
GCObject *o;
|
||||||
for (o = g->tobefnz; o != NULL; o = gch(o)->next) {
|
for (o = g->tobefnz; o != NULL; o = gch(o)->next) {
|
||||||
lua_assert(testbit(gch(o)->marked, SEPARATED));
|
lua_assert(testbit(gch(o)->marked, SEPARATED));
|
||||||
makewhite(g, o);
|
markobject(g, o);
|
||||||
reallymarkobject(g, o);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -619,7 +618,6 @@ static Udata *udata2finalize (global_State *g) {
|
||||||
g->allgc = o;
|
g->allgc = o;
|
||||||
lua_assert(isfinalized(gch(o)));
|
lua_assert(isfinalized(gch(o)));
|
||||||
resetbit(gch(o)->marked, SEPARATED); /* mark it as such */
|
resetbit(gch(o)->marked, SEPARATED); /* mark it as such */
|
||||||
makewhite(g, o);
|
|
||||||
return rawgco2u(o);
|
return rawgco2u(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -634,15 +632,15 @@ static void GCTM (lua_State *L, int propagateerrors) {
|
||||||
global_State *g = G(L);
|
global_State *g = G(L);
|
||||||
Udata *udata = udata2finalize(g);
|
Udata *udata = udata2finalize(g);
|
||||||
const TValue *tm = gfasttm(g, udata->uv.metatable, TM_GC);
|
const TValue *tm = gfasttm(g, udata->uv.metatable, TM_GC);
|
||||||
if (tm != NULL && ttisfunction(tm)) {
|
if (tm != NULL && ttisfunction(tm)) { /* is there a finalizer? */
|
||||||
int status;
|
int status;
|
||||||
lu_byte oldah = L->allowhook;
|
lu_byte oldah = L->allowhook;
|
||||||
lu_mem oldt = g->GCthreshold;
|
lu_mem oldt = g->GCthreshold;
|
||||||
L->allowhook = 0; /* stop debug hooks during GC tag method */
|
L->allowhook = 0; /* stop debug hooks during GC tag method */
|
||||||
g->GCthreshold = 2 * g->totalbytes; /* avoid GC steps */
|
g->GCthreshold = 2 * g->totalbytes; /* avoid GC steps */
|
||||||
setobj2s(L, L->top, tm);
|
setobj2s(L, L->top, tm); /* push finalizer... */
|
||||||
setuvalue(L, L->top+1, udata);
|
setuvalue(L, L->top+1, udata); /* ... and its argument */
|
||||||
L->top += 2;
|
L->top += 2; /* and (next line) call the finalizer */
|
||||||
status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
|
status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
|
||||||
L->allowhook = oldah; /* restore hooks */
|
L->allowhook = oldah; /* restore hooks */
|
||||||
g->GCthreshold = oldt; /* restore threshold */
|
g->GCthreshold = oldt; /* restore threshold */
|
||||||
|
@ -776,22 +774,24 @@ static l_mem singlestep (lua_State *L) {
|
||||||
case GCSsweepstring: {
|
case GCSsweepstring: {
|
||||||
if (g->sweepstrgc < g->strt.size) {
|
if (g->sweepstrgc < g->strt.size) {
|
||||||
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
|
sweepwholelist(L, &g->strt.hash[g->sweepstrgc++]);
|
||||||
|
return GCSWEEPCOST;
|
||||||
}
|
}
|
||||||
else { /* no more strings to sweep */
|
else { /* no more strings to sweep */
|
||||||
g->sweepgc = &g->udgc; /* prepare to sweep userdata */
|
g->sweepgc = &g->udgc; /* prepare to sweep userdata */
|
||||||
g->gcstate = GCSsweepudata;
|
g->gcstate = GCSsweepudata;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
return GCSWEEPCOST;
|
|
||||||
}
|
}
|
||||||
case GCSsweepudata: {
|
case GCSsweepudata: {
|
||||||
if (*g->sweepgc) {
|
if (*g->sweepgc) {
|
||||||
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
|
||||||
return GCSWEEPMAX*GCSWEEPCOST;
|
return GCSWEEPMAX*GCSWEEPCOST;
|
||||||
}
|
}
|
||||||
else { /* go to next phase */
|
else {
|
||||||
g->sweepgc = &g->allgc;
|
sweepwholelist(L, &g->tobefnz); /* sweep 'to-be-finalized' list */
|
||||||
|
g->sweepgc = &g->allgc; /* go to next phase */
|
||||||
g->gcstate = GCSsweep;
|
g->gcstate = GCSsweep;
|
||||||
return 0;
|
return GCSWEEPCOST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case GCSsweep: {
|
case GCSsweep: {
|
||||||
|
|
Loading…
Reference in New Issue