diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-11 11:09:55 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2013-09-11 11:09:55 -0300 |
commit | dd373a8f665e5e22ad3ad75401aa9fe3bbb2afc8 (patch) | |
tree | d475246f43edc6de6e1ebf491b274e9d9a5c1c24 /lgc.c | |
parent | 7061fe1d56f40e9d22a226423079da808fb41f66 (diff) | |
download | lua-dd373a8f665e5e22ad3ad75401aa9fe3bbb2afc8.tar.gz lua-dd373a8f665e5e22ad3ad75401aa9fe3bbb2afc8.tar.bz2 lua-dd373a8f665e5e22ad3ad75401aa9fe3bbb2afc8.zip |
threads are kept in a separated GC list, linked after the main thread
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.160 2013/09/11 12:47:48 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.161 2013/09/11 13:24:55 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 | */ |
@@ -304,7 +304,7 @@ static void markbeingfnz (global_State *g) { | |||
304 | ** thread.) | 304 | ** thread.) |
305 | */ | 305 | */ |
306 | static void remarkupvals (global_State *g) { | 306 | static void remarkupvals (global_State *g) { |
307 | GCObject *thread = hvalue(&g->l_registry)->next; | 307 | GCObject *thread = g->mainthread->next; |
308 | for (; thread != NULL; thread = gch(thread)->next) { | 308 | for (; thread != NULL; thread = gch(thread)->next) { |
309 | lua_assert(!isblack(thread)); /* threads are never black */ | 309 | lua_assert(!isblack(thread)); /* threads are never black */ |
310 | if (!isgray(thread)) { /* dead thread? */ | 310 | if (!isgray(thread)) { /* dead thread? */ |
@@ -933,10 +933,9 @@ static void localmarkthread (lua_State *l) { | |||
933 | ** a thread) | 933 | ** a thread) |
934 | */ | 934 | */ |
935 | static void localmark (global_State *g) { | 935 | static void localmark (global_State *g) { |
936 | GCObject *thread = hvalue(&g->l_registry)->next; | 936 | GCObject *thread = obj2gco(g->mainthread); |
937 | for (; thread != NULL; thread = gch(thread)->next) /* traverse all threads */ | 937 | for (; thread != NULL; thread = gch(thread)->next) /* traverse all threads */ |
938 | localmarkthread(gco2th(thread)); | 938 | localmarkthread(gco2th(thread)); |
939 | localmarkthread(g->mainthread); | ||
940 | } | 939 | } |
941 | 940 | ||
942 | 941 | ||
@@ -1057,12 +1056,14 @@ void luaC_freeallobjects (lua_State *L) { | |||
1057 | separatetobefnz(g, 1); /* separate all objects with finalizers */ | 1056 | separatetobefnz(g, 1); /* separate all objects with finalizers */ |
1058 | lua_assert(g->finobj == NULL && g->localfin == NULL); | 1057 | lua_assert(g->finobj == NULL && g->localfin == NULL); |
1059 | callallpendingfinalizers(L, 0); | 1058 | callallpendingfinalizers(L, 0); |
1059 | lua_assert(g->tobefnz == NULL); | ||
1060 | g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ | 1060 | g->currentwhite = WHITEBITS; /* this "white" makes all objects look dead */ |
1061 | g->gckind = KGC_NORMAL; | 1061 | g->gckind = KGC_NORMAL; |
1062 | sweepwholelist(L, &g->localgc); | ||
1062 | sweepwholelist(L, &g->localfin); /* finalizers can create objs. with fins. */ | 1063 | sweepwholelist(L, &g->localfin); /* finalizers can create objs. with fins. */ |
1063 | sweepwholelist(L, &g->finobj); | 1064 | sweepwholelist(L, &g->finobj); |
1064 | sweepwholelist(L, &g->localgc); | ||
1065 | sweepwholelist(L, &g->allgc); | 1065 | sweepwholelist(L, &g->allgc); |
1066 | sweepwholelist(L, &g->mainthread->next); | ||
1066 | sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ | 1067 | sweepwholelist(L, &g->fixedgc); /* collect fixed objects */ |
1067 | lua_assert(g->strt.nuse == 0); | 1068 | lua_assert(g->strt.nuse == 0); |
1068 | } | 1069 | } |
@@ -1163,11 +1164,13 @@ static lu_mem singlestep (lua_State *L) { | |||
1163 | return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); | 1164 | return sweepstep(L, g, GCSsweeptobefnz, &g->tobefnz); |
1164 | } | 1165 | } |
1165 | case GCSsweeptobefnz: { | 1166 | case GCSsweeptobefnz: { |
1166 | return sweepstep(L, g, GCSsweepmainth, NULL); | 1167 | return sweepstep(L, g, GCSsweepthreads, &g->mainthread->next); |
1168 | } | ||
1169 | case GCSsweepthreads: { | ||
1170 | return sweepstep(L, g, GCSsweepend, NULL); | ||
1167 | } | 1171 | } |
1168 | case GCSsweepmainth: { /* sweep main thread */ | 1172 | case GCSsweepend: { |
1169 | GCObject *mt = obj2gco(g->mainthread); | 1173 | makewhite(g, obj2gco(g->mainthread)); /* sweep main thread */ |
1170 | sweeplist(L, &mt, 1); | ||
1171 | checkBuffer(L); | 1174 | checkBuffer(L); |
1172 | g->gcstate = GCSpause; /* finish collection */ | 1175 | g->gcstate = GCSpause; /* finish collection */ |
1173 | return GCSWEEPCOST; | 1176 | return GCSWEEPCOST; |