aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lgc.c16
-rw-r--r--lstate.c3
-rw-r--r--lstate.h3
3 files changed, 19 insertions, 3 deletions
diff --git a/lgc.c b/lgc.c
index c0ebef05..ff52fa2c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.184 2003/12/03 20:03:07 roberto Exp roberto $ 2** $Id: lgc.c,v 1.185 2003/12/04 17:22:42 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*/
@@ -38,6 +38,7 @@
38 38
39#define isgray(x) (!isblack(x) && !iswhite(x)) 39#define isgray(x) (!isblack(x) && !iswhite(x))
40#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT) 40#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
41#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
41 42
42#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT) 43#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
43 44
@@ -323,6 +324,9 @@ static l_mem propagatemarks (global_State *g, l_mem lim) {
323 case LUA_TTHREAD: { 324 case LUA_TTHREAD: {
324 lua_State *th = gcototh(o); 325 lua_State *th = gcototh(o);
325 g->gray = th->gclist; 326 g->gray = th->gclist;
327 th->gclist = g->grayagain;
328 g->grayagain = o;
329 black2gray(o);
326 traversestack(g, th); 330 traversestack(g, th);
327 break; 331 break;
328 } 332 }
@@ -335,6 +339,11 @@ static l_mem propagatemarks (global_State *g, l_mem lim) {
335 case LUA_TUPVAL: { 339 case LUA_TUPVAL: {
336 UpVal *uv = gcotouv(o); 340 UpVal *uv = gcotouv(o);
337 g->gray = uv->gclist; 341 g->gray = uv->gclist;
342 if (uv->v != &uv->value) { /* open? */
343 uv->gclist = g->grayagain;
344 g->grayagain = o;
345 black2gray(o);
346 }
338 markvalue(g, &uv->value); 347 markvalue(g, &uv->value);
339 break; 348 break;
340 } 349 }
@@ -553,6 +562,10 @@ static void markroot (lua_State *L) {
553 562
554static void atomic (lua_State *L) { 563static void atomic (lua_State *L) {
555 global_State *g = G(L); 564 global_State *g = G(L);
565 lua_assert(g->gray == NULL);
566 g->gray = g->grayagain;
567 g->grayagain = NULL;
568 propagatemarks(g, MAXLMEM);
556 g->GCthreshold = luaC_separateudata(L); /* separate userdata to be preserved */ 569 g->GCthreshold = luaC_separateudata(L); /* separate userdata to be preserved */
557 marktmu(g); /* mark `preserved' userdata */ 570 marktmu(g); /* mark `preserved' userdata */
558 propagatemarks(g, MAXLMEM); /* remark, to propagate `preserveness' */ 571 propagatemarks(g, MAXLMEM); /* remark, to propagate `preserveness' */
@@ -565,6 +578,7 @@ static void atomic (lua_State *L) {
565 g->sweepgc = &g->rootgc->gch.next; 578 g->sweepgc = &g->rootgc->gch.next;
566 g->sweepstrgc = 0; 579 g->sweepstrgc = 0;
567 g->gcstate = GCSsweepstring; 580 g->gcstate = GCSsweepstring;
581 g->grayagain = NULL;
568} 582}
569 583
570 584
diff --git a/lstate.c b/lstate.c
index b52ff66d..e59f1a18 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 1.132 2003/12/03 20:03:07 roberto Exp roberto $ 2** $Id: lstate.c,v 1.133 2003/12/04 17:22:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -172,6 +172,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
172 g->currentwhite = bitmask(WHITE0BIT); 172 g->currentwhite = bitmask(WHITE0BIT);
173 g->firstudata = NULL; 173 g->firstudata = NULL;
174 g->gray = NULL; 174 g->gray = NULL;
175 g->grayagain = NULL;
175 g->weak = NULL; 176 g->weak = NULL;
176 g->tmudata = NULL; 177 g->tmudata = NULL;
177 setnilvalue(gkey(g->dummynode)); 178 setnilvalue(gkey(g->dummynode));
diff --git a/lstate.h b/lstate.h
index c44828b6..4a3ea577 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 1.117 2003/12/03 20:03:07 roberto Exp roberto $ 2** $Id: lstate.h,v 1.118 2003/12/04 17:22:42 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -103,6 +103,7 @@ typedef struct global_State {
103 GCObject **sweepgc; /* position of sweep in `rootgc' */ 103 GCObject **sweepgc; /* position of sweep in `rootgc' */
104 int sweepstrgc; /* position of sweep in `strt' */ 104 int sweepstrgc; /* position of sweep in `strt' */
105 GCObject *gray; /* list of gray objects */ 105 GCObject *gray; /* list of gray objects */
106 GCObject *grayagain; /* list of objects to be traversed atomically */
106 GCObject *weak; /* list of weak tables (to be cleared) */ 107 GCObject *weak; /* list of weak tables (to be cleared) */
107 GCObject *tmudata; /* list of userdata to be GC */ 108 GCObject *tmudata; /* list of userdata to be GC */
108 int gcstate; /* state of garbage collector */ 109 int gcstate; /* state of garbage collector */