aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-22 16:01:38 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-01-22 16:01:38 -0200
commit6fda6a530265268c01a83c31f8fc30e34753bbf1 (patch)
treeb1520902a04904c7ad3fbc703d818e98b5e9461c /lgc.c
parent4ac58853dc820127a11a14ed8bde1fae9458369e (diff)
downloadlua-6fda6a530265268c01a83c31f8fc30e34753bbf1.tar.gz
lua-6fda6a530265268c01a83c31f8fc30e34753bbf1.tar.bz2
lua-6fda6a530265268c01a83c31f8fc30e34753bbf1.zip
support for multiple stacks sharing the same global environment
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c74
1 files changed, 42 insertions, 32 deletions
diff --git a/lgc.c b/lgc.c
index abe78425..db713767 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.76 2001/01/18 15:59:09 roberto Exp roberto $ 2** $Id: lgc.c,v 1.77 2001/01/19 13:20:30 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*/
@@ -47,22 +47,6 @@ static void protomark (Proto *f) {
47} 47}
48 48
49 49
50static void markstack (lua_State *L, GCState *st) {
51 StkId o;
52 for (o=L->stack; o<L->top; o++)
53 markobject(st, o);
54}
55
56
57static void marklock (global_State *G, GCState *st) {
58 int i;
59 for (i=0; i<G->nref; i++) {
60 if (G->refArray[i].st == LOCK)
61 markobject(st, &G->refArray[i].o);
62 }
63}
64
65
66static void markclosure (GCState *st, Closure *cl) { 50static void markclosure (GCState *st, Closure *cl) {
67 if (!ismarked(cl)) { 51 if (!ismarked(cl)) {
68 if (!cl->isC) 52 if (!cl->isC)
@@ -73,14 +57,10 @@ static void markclosure (GCState *st, Closure *cl) {
73} 57}
74 58
75 59
76static void marktagmethods (global_State *G, GCState *st) { 60static void marktable (GCState *st, Hash *h) {
77 int e; 61 if (!ismarked(h)) {
78 for (e=0; e<TM_N; e++) { 62 h->mark = st->tmark; /* chain it in list of marked */
79 int t; 63 st->tmark = h;
80 for (t=0; t<G->ntag; t++) {
81 Closure *cl = luaT_gettm(G, t, e);
82 if (cl) markclosure(st, cl);
83 }
84 } 64 }
85} 65}
86 66
@@ -97,10 +77,7 @@ static void markobject (GCState *st, TObject *o) {
97 markclosure(st, clvalue(o)); 77 markclosure(st, clvalue(o));
98 break; 78 break;
99 case LUA_TTABLE: { 79 case LUA_TTABLE: {
100 if (!ismarked(hvalue(o))) { 80 marktable(st, hvalue(o));
101 hvalue(o)->mark = st->tmark; /* chain it in list of marked */
102 st->tmark = hvalue(o);
103 }
104 break; 81 break;
105 } 82 }
106 default: break; /* numbers, etc */ 83 default: break; /* numbers, etc */
@@ -108,13 +85,46 @@ static void markobject (GCState *st, TObject *o) {
108} 85}
109 86
110 87
88static void markstacks (lua_State *L, GCState *st) {
89 lua_State *L1 = L;
90 do { /* for each thread */
91 StkId o;
92 marktable(st, L1->gt); /* mark table of globals */
93 for (o=L1->stack; o<L1->top; o++)
94 markobject(st, o);
95 lua_assert(L->previous->next == L && L->next->previous == L);
96 L1 = L1->next;
97 } while (L1 != L);
98}
99
100
101static void marklock (global_State *G, GCState *st) {
102 int i;
103 for (i=0; i<G->nref; i++) {
104 if (G->refArray[i].st == LOCK)
105 markobject(st, &G->refArray[i].o);
106 }
107}
108
109
110static void marktagmethods (global_State *G, GCState *st) {
111 int e;
112 for (e=0; e<TM_N; e++) {
113 int t;
114 for (t=0; t<G->ntag; t++) {
115 Closure *cl = luaT_gettm(G, t, e);
116 if (cl) markclosure(st, cl);
117 }
118 }
119}
120
121
111static void markall (lua_State *L) { 122static void markall (lua_State *L) {
112 GCState st; 123 GCState st;
113 st.cmark = NULL; 124 st.cmark = NULL;
114 st.tmark = L->gt; /* put table of globals in mark list */ 125 st.tmark = NULL;
115 L->gt->mark = NULL;
116 marktagmethods(G(L), &st); /* mark tag methods */ 126 marktagmethods(G(L), &st); /* mark tag methods */
117 markstack(L, &st); /* mark stack objects */ 127 markstacks(L, &st); /* mark all stacks */
118 marklock(G(L), &st); /* mark locked objects */ 128 marklock(G(L), &st); /* mark locked objects */
119 for (;;) { /* mark tables and closures */ 129 for (;;) { /* mark tables and closures */
120 if (st.cmark) { 130 if (st.cmark) {