aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/lgc.c b/lgc.c
index 515267e7..ea0537df 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.171 2014/02/13 12:11:34 roberto Exp roberto $ 2** $Id: lgc.c,v 2.172 2014/02/13 14:46: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*/
@@ -1060,9 +1060,9 @@ void luaC_runtilstate (lua_State *L, int statesmask) {
1060 1060
1061 1061
1062/* 1062/*
1063** run a few finalizers 1063** run a few (up to 'g->gcfinnum') finalizers
1064*/ 1064*/
1065static int dosomefinalization (lua_State *L) { 1065static int runafewfinalizers (lua_State *L) {
1066 global_State *g = G(L); 1066 global_State *g = G(L);
1067 unsigned int i; 1067 unsigned int i;
1068 lua_assert(!g->tobefnz || g->gcfinnum > 0); 1068 lua_assert(!g->tobefnz || g->gcfinnum > 0);
@@ -1075,19 +1075,26 @@ static int dosomefinalization (lua_State *L) {
1075 1075
1076 1076
1077/* 1077/*
1078** performs a basic GC step 1078** get GC debt and convert it from Kb to 'work units' (avoid zero debt
1079** and overflows)
1079*/ 1080*/
1080void luaC_forcestep (lua_State *L) { 1081static l_mem getdebt (global_State *g) {
1081 global_State *g = G(L);
1082 l_mem debt = g->GCdebt; 1082 l_mem debt = g->GCdebt;
1083 int stepmul = g->gcstepmul; 1083 int stepmul = g->gcstepmul;
1084 if (stepmul < 40) stepmul = 40; /* avoid ridiculous low values (and 0) */
1085 /* convert debt from Kb to 'work units' (avoid zero debt and overflows) */
1086 debt = (debt / STEPMULADJ) + 1; 1084 debt = (debt / STEPMULADJ) + 1;
1087 debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM; 1085 debt = (debt < MAX_LMEM / stepmul) ? debt * stepmul : MAX_LMEM;
1086 return debt;
1087}
1088
1089/*
1090** performs a basic GC step
1091*/
1092void luaC_forcestep (lua_State *L) {
1093 global_State *g = G(L);
1094 l_mem debt = getdebt(g);
1088 do { 1095 do {
1089 if (g->gcstate == GCScallfin && g->tobefnz) { 1096 if (g->gcstate == GCScallfin && g->tobefnz) {
1090 unsigned int n = dosomefinalization(L); 1097 unsigned int n = runafewfinalizers(L);
1091 debt -= (n * GCFINALIZECOST); 1098 debt -= (n * GCFINALIZECOST);
1092 } 1099 }
1093 else { /* perform one single step */ 1100 else { /* perform one single step */
@@ -1098,9 +1105,9 @@ void luaC_forcestep (lua_State *L) {
1098 if (g->gcstate == GCSpause) 1105 if (g->gcstate == GCSpause)
1099 setpause(g, g->GCestimate); /* pause until next cycle */ 1106 setpause(g, g->GCestimate); /* pause until next cycle */
1100 else { 1107 else {
1101 debt = (debt / stepmul) * STEPMULADJ; /* convert 'work units' to Kb */ 1108 debt = (debt / g->gcstepmul) * STEPMULADJ; /* convert 'work units' to Kb */
1102 luaE_setdebt(g, debt); 1109 luaE_setdebt(g, debt);
1103 dosomefinalization(L); 1110 runafewfinalizers(L);
1104 } 1111 }
1105} 1112}
1106 1113