summaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-04-17 14:35:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-04-17 14:35:54 -0300
commitbeee01b170c5fea9ed4527b28b9221d2df1baaba (patch)
tree82263b6e128ffe09fe3da63de16c626522320dfc /lgc.c
parent6473f965ca699719b3b9908008f15da48cc2e6f1 (diff)
downloadlua-beee01b170c5fea9ed4527b28b9221d2df1baaba.tar.gz
lua-beee01b170c5fea9ed4527b28b9221d2df1baaba.tar.bz2
lua-beee01b170c5fea9ed4527b28b9221d2df1baaba.zip
re-implementation of refs through weak tables
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/lgc.c b/lgc.c
index a7f96f8c..0237b88c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.95 2001/03/26 14:31:49 roberto Exp roberto $ 2** $Id: lgc.c,v 1.96 2001/04/11 14:42:41 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*/
@@ -111,15 +111,6 @@ static void markstacks (lua_State *L, GCState *st) {
111} 111}
112 112
113 113
114static void marklock (global_State *G, GCState *st) {
115 int i;
116 for (i=0; i<G->nref; i++) {
117 if (G->refArray[i].st == LOCK)
118 markobject(st, &G->refArray[i].o);
119 }
120}
121
122
123static void marktagmethods (global_State *G, GCState *st) { 114static void marktagmethods (global_State *G, GCState *st) {
124 int t; 115 int t;
125 for (t=0; t<G->ntag; t++) { 116 for (t=0; t<G->ntag; t++) {
@@ -176,8 +167,9 @@ static void markall (lua_State *L) {
176 st.tmark = NULL; 167 st.tmark = NULL;
177 marktagmethods(G(L), &st); /* mark tag methods */ 168 marktagmethods(G(L), &st); /* mark tag methods */
178 markstacks(L, &st); /* mark all stacks */ 169 markstacks(L, &st); /* mark all stacks */
179 marklock(G(L), &st); /* mark locked objects */
180 marktable(&st, G(L)->type2tag); 170 marktable(&st, G(L)->type2tag);
171 marktable(&st, G(L)->registry);
172 marktable(&st, G(L)->weakregistry);
181 for (;;) { /* mark tables and closures */ 173 for (;;) { /* mark tables and closures */
182 if (st.cmark) { 174 if (st.cmark) {
183 Closure *f = st.cmark; /* get first closure from list */ 175 Closure *f = st.cmark; /* get first closure from list */
@@ -208,26 +200,6 @@ static int hasmark (const TObject *o) {
208} 200}
209 201
210 202
211/* macro for internal debugging; check if a link of free refs is valid */
212#define VALIDLINK(L, st,n) (NONEXT <= (st) && (st) < (n))
213
214static void invalidaterefs (global_State *G) {
215 int n = G->nref;
216 int i;
217 for (i=0; i<n; i++) {
218 struct Ref *r = &G->refArray[i];
219 if (r->st == HOLD && !hasmark(&r->o))
220 r->st = COLLECTED;
221 lua_assert((r->st == LOCK && hasmark(&r->o)) ||
222 (r->st == HOLD && hasmark(&r->o)) ||
223 r->st == COLLECTED ||
224 r->st == NONEXT ||
225 (r->st < n && VALIDLINK(L, G->refArray[r->st].st, n)));
226 }
227 lua_assert(VALIDLINK(L, G->refFree, n));
228}
229
230
231static void invalidatetable (Hash *h) { 203static void invalidatetable (Hash *h) {
232 int i; 204 int i;
233 for (i=0; i<h->size; i++) { 205 for (i=0; i<h->size; i++) {
@@ -408,7 +380,6 @@ void luaC_collect (lua_State *L, int all) {
408 380
409void luaC_collectgarbage (lua_State *L) { 381void luaC_collectgarbage (lua_State *L) {
410 markall(L); 382 markall(L);
411 invalidaterefs(G(L)); /* check unlocked references */
412 invalidatetables(G(L)); 383 invalidatetables(G(L));
413 luaC_collect(L, 0); 384 luaC_collect(L, 0);
414 checkMbuffer(L); 385 checkMbuffer(L);