aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c68
1 files changed, 34 insertions, 34 deletions
diff --git a/lgc.c b/lgc.c
index 8d273d44..aaa57a07 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.155 2013/08/28 18:30:26 roberto Exp roberto $ 2** $Id: lgc.c,v 2.156 2013/08/29 13:34:16 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*/
@@ -979,12 +979,9 @@ static void setpause (global_State *g, l_mem estimate) {
979} 979}
980 980
981 981
982#define sweepphases (bitmask(GCSsweepudata) | bitmask(GCSsweep))
983
984
985/* 982/*
986** enter first sweep phase and prepare pointers for other sweep phases. 983** Enter first sweep phase.
987** The calls to 'sweeptolive' make pointers point to an object inside 984** The call to 'sweeptolive' makes pointer point to an object inside
988** the list (instead of to the header), so that the real sweep do not 985** the list (instead of to the header), so that the real sweep do not
989** need to skip objects created between "now" and the start of the real 986** need to skip objects created between "now" and the start of the real
990** sweep. 987** sweep.
@@ -993,11 +990,9 @@ static void setpause (global_State *g, l_mem estimate) {
993static int entersweep (lua_State *L) { 990static int entersweep (lua_State *L) {
994 global_State *g = G(L); 991 global_State *g = G(L);
995 int n = 0; 992 int n = 0;
996 g->gcstate = GCSsweepudata; 993 g->gcstate = GCSsweeplocal;
997 lua_assert(g->sweepgc == NULL && g->sweepfin == NULL); 994 lua_assert(g->sweepgc == NULL);
998 /* prepare to sweep finalizable objects and regular objects */ 995 g->sweepgc = sweeptolive(L, &g->localgc, &n);
999 g->sweepfin = sweeptolive(L, &g->finobj, &n);
1000 g->sweepgc = sweeptolive(L, &g->allgc, &n);
1001 return n; 996 return n;
1002} 997}
1003 998
@@ -1068,6 +1063,20 @@ static l_mem atomic (lua_State *L) {
1068} 1063}
1069 1064
1070 1065
1066static lu_mem sweepstep (lua_State *L, global_State *g,
1067 int nextstate, GCObject **nextlist) {
1068 if (g->sweepgc) { /* is there still something to sweep? */
1069 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX);
1070 return (GCSWEEPMAX * GCSWEEPCOST);
1071 }
1072 else { /* next phase */
1073 g->gcstate = nextstate;
1074 g->sweepgc = nextlist;
1075 return 0;
1076 }
1077}
1078
1079
1071static lu_mem singlestep (lua_State *L) { 1080static lu_mem singlestep (lua_State *L) {
1072 global_State *g = G(L); 1081 global_State *g = G(L);
1073 switch (g->gcstate) { 1082 switch (g->gcstate) {
@@ -1096,30 +1105,21 @@ static lu_mem singlestep (lua_State *L) {
1096 sw = entersweep(L); 1105 sw = entersweep(L);
1097 return work + sw * GCSWEEPCOST; 1106 return work + sw * GCSWEEPCOST;
1098 } 1107 }
1099 case GCSsweepudata: { 1108 case GCSsweeplocal: {
1100 if (g->sweepfin) { 1109 return sweepstep(L, g, GCSsweepfin, &g->finobj);
1101 g->sweepfin = sweeplist(L, g->sweepfin, GCSWEEPMAX);
1102 return GCSWEEPMAX*GCSWEEPCOST;
1103 }
1104 else {
1105 sweepwholelist(L, &g->localgc);
1106 g->gcstate = GCSsweep;
1107 return GCLOCALPAUSE / 4; /* some magic for now */
1108 }
1109 } 1110 }
1110 case GCSsweep: { 1111 case GCSsweepfin: {
1111 if (g->sweepgc) { 1112 return sweepstep(L, g, GCSsweepall, &g->allgc);
1112 g->sweepgc = sweeplist(L, g->sweepgc, GCSWEEPMAX); 1113 }
1113 return GCSWEEPMAX*GCSWEEPCOST; 1114 case GCSsweepall: {
1114 } 1115 return sweepstep(L, g, GCSsweepmainth, NULL);
1115 else { 1116 }
1116 /* sweep main thread */ 1117 case GCSsweepmainth: { /* sweep main thread */
1117 GCObject *mt = obj2gco(g->mainthread); 1118 GCObject *mt = obj2gco(g->mainthread);
1118 sweeplist(L, &mt, 1); 1119 sweeplist(L, &mt, 1);
1119 checkBuffer(L); 1120 checkBuffer(L);
1120 g->gcstate = GCSpause; /* finish collection */ 1121 g->gcstate = GCSpause; /* finish collection */
1121 return GCSWEEPCOST; 1122 return GCSWEEPCOST;
1122 }
1123 } 1123 }
1124 default: lua_assert(0); return 0; 1124 default: lua_assert(0); return 0;
1125 } 1125 }