|
@ -1,5 +1,5 @@ |
|
|
/*
|
|
|
/*
|
|
|
** $Id: lgc.c,v 2.160 2013/09/11 12:47:48 roberto Exp roberto $ |
|
|
** $Id: lgc.c,v 2.161 2013/09/11 13:24:55 roberto Exp roberto $ |
|
|
** Garbage Collector |
|
|
** Garbage Collector |
|
|
** See Copyright Notice in lua.h |
|
|
** See Copyright Notice in lua.h |
|
|
*/ |
|
|
*/ |
|
@ -304,7 +304,7 @@ static void markbeingfnz (global_State *g) { |
|
|
** thread.) |
|
|
** thread.) |
|
|
*/ |
|
|
*/ |
|
|
static void remarkupvals (global_State *g) { |
|
|
static void remarkupvals (global_State *g) { |
|
|
GCObject *thread = hvalue(&g->l_registry)->next; |
|
|
GCObject *thread = g->mainthread->next; |
|
|
for (; thread != NULL; thread = gch(thread)->next) { |
|
|
for (; thread != NULL; thread = gch(thread)->next) { |
|
|
lua_assert(!isblack(thread)); /* threads are never black */ |
|
|
lua_assert(!isblack(thread)); /* threads are never black */ |
|
|
if (!isgray(thread)) { /* dead thread? */ |
|
|
if (!isgray(thread)) { /* dead thread? */ |
|
@ -933,10 +933,9 @@ static void localmarkthread (lua_State *l) { |
|
|
** a thread) |
|
|
** a thread) |
|
|
*/ |
|
|
*/ |
|
|
static void localmark (global_State *g) { |
|
|
static void localmark (global_State *g) { |
|
|
GCObject *thread = hvalue(&g->l_registry)->next; |
|
|
GCObject *thread = obj2gco(g->mainthread); |
|
|
for (; thread != NULL; thread = gch(thread)->next) /* traverse all threads */ |
|
|
for (; thread != NULL; thread = gch(thread)->next) /* traverse all threads */ |
|
|
localmarkthread(gco2th(thread)); |
|
|
localmarkthread(gco2th(thread)); |
|
|
localmarkthread(g->mainthread); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1057,12 +1056,14 @@ void luaC_freeallobjects (lua_State *L) { |
|
|
separatetobefnz(g, 1); /* separate all objects with finalizers */ |
|
|
separatetobefnz(g, 1); /* separate all objects with finalizers */ |
|
|
lua_assert(g->finobj == NULL && g->localfin == NULL); |
|
|
lua_assert(g->finobj == NULL && g->localfin == NULL); |
|
|
callallpendingfinalizers(L, 0); |
|
|
callallpendingfinalizers(L, 0); |
|
|
|
|
|
lua_assert(g->tobefnz == NULL); |
|
|
g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ |
|
|
g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ |
|
|
g->gckind = KGC_NORMAL; |
|
|
g->gckind = KGC_NORMAL; |
|
|
|
|
|
sweepwholelist(L, &g->localgc); |
|
|
sweepwholelist(L, &g->localfin); /* finalizers can create objs. with fins. */ |
|
|
sweepwholelist(L, &g->localfin); /* finalizers can create objs. with fins. */ |
|
|
sweepwholelist(L, &g->finobj); |
|
|
sweepwholelist(L, &g->finobj); |
|
|
sweepwholelist(L, &g->localgc); |
|
|
|
|
|
sweepwholelist(L, &g->allgc); |
|
|
sweepwholelist(L, &g->allgc); |
|
|
|
|
|
sweepwholelist(L, &g->mainthread->next); |
|
|
sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ |
|
|
sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ |
|
|
lua_assert(g->strt.nuse == 0); |
|
|
lua_assert(g->strt.nuse == 0); |
|
|
} |
|
|
} |
|
@ -1163,11 +1164,13 @@ static lu_mem singlestep (lua_State *L) { |
|
|
return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); |
|
|
return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); |
|
|
} |
|
|
} |
|
|
case GCSsweeptobefnz: { |
|
|
case GCSsweeptobefnz: { |
|
|
return sweepstep(L, g, GCSsweepmainth, NULL); |
|
|
return sweepstep(L, g, GCSsweepthreads, &g->mainthread->next); |
|
|
|
|
|
} |
|
|
|
|
|
case GCSsweepthreads: { |
|
|
|
|
|
return sweepstep(L, g, GCSsweepend, NULL); |
|
|
} |
|
|
} |
|
|
case GCSsweepmainth: { /* sweep main thread */ |
|
|
case GCSsweepend: { |
|
|
GCObject *mt = obj2gco(g->mainthread); |
|
|
makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */ |
|
|
sweeplist(L, &mt, 1); |
|
|
|
|
|
checkBuffer(L); |
|
|
checkBuffer(L); |
|
|
g->gcstate = GCSpause; /* finish collection */ |
|
|
g->gcstate = GCSpause; /* finish collection */ |
|
|
return GCSWEEPCOST; |
|
|
return GCSWEEPCOST; |
|
|