aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c30
1 files changed, 17 insertions, 13 deletions
diff --git a/lapi.c b/lapi.c
index 0cde72cc..d6d7a8db 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1145,7 +1145,7 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1145 } 1145 }
1146 case LUA_GCRESTART: { 1146 case LUA_GCRESTART: {
1147 luaE_setdebt(g, 0); 1147 luaE_setdebt(g, 0);
1148 g->gcstp = 0; /* (GCSTPGC must be already zero here) */ 1148 g->gcstp = 0; /* (bit GCSTPGC must be zero here) */
1149 break; 1149 break;
1150 } 1150 }
1151 case LUA_GCCOLLECT: { 1151 case LUA_GCCOLLECT: {
@@ -1162,21 +1162,25 @@ LUA_API int lua_gc (lua_State *L, int what, ...) {
1162 break; 1162 break;
1163 } 1163 }
1164 case LUA_GCSTEP: { 1164 case LUA_GCSTEP: {
1165 int data = va_arg(argp, int); 1165 int todo = va_arg(argp, int); /* work to be done */
1166 l_obj debt = 1; /* =1 to signal that it did an actual step */ 1166 int didsomething = 0;
1167 lu_byte oldstp = g->gcstp; 1167 lu_byte oldstp = g->gcstp;
1168 g->gcstp = 0; /* allow GC to run (GCSTPGC must be zero here) */ 1168 g->gcstp = 0; /* allow GC to run (bit GCSTPGC must be zero here) */
1169 if (data == 0) { 1169 if (todo == 0)
1170 luaE_setdebt(g, 0); /* do a basic step */ 1170 todo = 1 << g->gcstepsize; /* standard step size */
1171 luaC_step(L); 1171 while (todo + g->GCdebt > 0) { /* enough to run a step? */
1172 } 1172 todo += g->GCdebt; /* decrement 'todo' (debt is usually negative) */
1173 else { /* add 'data' to total debt */ 1173 luaC_step(L); /* run one basic step */
1174 debt = data + g->GCdebt; 1174 didsomething = 1;
1175 luaE_setdebt(g, debt); 1175 if (g->gckind == KGC_GEN) /* minor collections? */
1176 luaC_checkGC(L); 1176 todo = 0; /* doesn't make sense to repeat in this case */
1177 else if (g->gcstate == GCSpause)
1178 break; /* don't run more than one cycle */
1177 } 1179 }
1180 /* add remaining 'todo' to total debt */
1181 luaE_setdebt(g, todo + g->GCdebt);
1178 g->gcstp = oldstp; /* restore previous state */ 1182 g->gcstp = oldstp; /* restore previous state */
1179 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */ 1183 if (didsomething && g->gcstate == GCSpause) /* end of cycle? */
1180 res = 1; /* signal it */ 1184 res = 1; /* signal it */
1181 break; 1185 break;
1182 } 1186 }