aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-12 15:43:13 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2001-06-12 15:43:13 -0300
commit89e8303f4ea5f1041f3633db7948e7aef17b5226 (patch)
treed3f6853fd3bc177c4ba728aa71051cd29ba57c89 /lgc.c
parent89c301d180ef4ef3887fbf54fe2fd43a5c8d183a (diff)
downloadlua-89e8303f4ea5f1041f3633db7948e7aef17b5226.tar.gz
lua-89e8303f4ea5f1041f3633db7948e7aef17b5226.tar.bz2
lua-89e8303f4ea5f1041f3633db7948e7aef17b5226.zip
more robust treatment of GC tag methods (now they can create new
objects while running...)
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c29
1 files changed, 7 insertions, 22 deletions
diff --git a/lgc.c b/lgc.c
index e7d533d3..d3c9490c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 1.101 2001/06/07 15:01:21 roberto Exp roberto $ 2** $Id: lgc.c,v 1.102 2001/06/08 19:01:38 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*/
@@ -18,18 +18,6 @@
18#include "ltm.h" 18#include "ltm.h"
19 19
20 20
21/*
22** optional lock for GC
23** (when Lua calls GC tag methods it unlocks the regular lock)
24*/
25#ifndef lua_lockgc
26#define lua_lockgc(L) {
27#endif
28
29#ifndef lua_unlockgc
30#define lua_unlockgc(L) }
31#endif
32
33 21
34typedef struct GCState { 22typedef struct GCState {
35 Hash *tmark; /* list of marked tables to be visited */ 23 Hash *tmark; /* list of marked tables to be visited */
@@ -281,7 +269,7 @@ static void collecttable (lua_State *L) {
281} 269}
282 270
283 271
284static void collectudata (lua_State *L) { 272void luaC_collectudata (lua_State *L) {
285 Udata **p = &G(L)->rootudata; 273 Udata **p = &G(L)->rootudata;
286 Udata *next; 274 Udata *next;
287 while ((next = *p) != NULL) { 275 while ((next = *p) != NULL) {
@@ -351,9 +339,8 @@ static void callgcTM (lua_State *L, const TObject *obj) {
351} 339}
352 340
353 341
354static void callgcTMudata (lua_State *L) { 342void luaC_callgcTMudata (lua_State *L) {
355 int tag; 343 int tag;
356 G(L)->GCthreshold = 2*G(L)->nblocks; /* avoid GC during tag methods */
357 for (tag=G(L)->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */ 344 for (tag=G(L)->ntag-1; tag>=0; tag--) { /* for each tag (in reverse order) */
358 Udata *udata; 345 Udata *udata;
359 while ((udata = G(L)->TMtable[tag].collected) != NULL) { 346 while ((udata = G(L)->TMtable[tag].collected) != NULL) {
@@ -368,14 +355,14 @@ static void callgcTMudata (lua_State *L) {
368 355
369 356
370void luaC_collect (lua_State *L, int all) { 357void luaC_collect (lua_State *L, int all) {
371 lua_lockgc(L); 358 luaC_collectudata(L);
372 collectudata(L);
373 callgcTMudata(L);
374 collectstrings(L, all); 359 collectstrings(L, all);
375 collecttable(L); 360 collecttable(L);
376 collectproto(L); 361 collectproto(L);
377 collectclosure(L); 362 collectclosure(L);
378 lua_unlockgc(L); 363 checkMbuffer(L);
364 G(L)->GCthreshold = 2*G(L)->nblocks; /* set new threshold */
365 luaC_callgcTMudata(L);
379} 366}
380 367
381 368
@@ -383,8 +370,6 @@ void luaC_collectgarbage (lua_State *L) {
383 markall(L); 370 markall(L);
384 invalidatetables(G(L)); 371 invalidatetables(G(L));
385 luaC_collect(L, 0); 372 luaC_collect(L, 0);
386 checkMbuffer(L);
387 G(L)->GCthreshold = 2*G(L)->nblocks; /* set new threshold */
388 callgcTM(L, &luaO_nilobject); 373 callgcTM(L, &luaO_nilobject);
389} 374}
390 375