aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-12-20 16:17:46 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-12-20 16:17:46 -0200
commit737f119187aca3c8f6743ec6e3cfc04e83723180 (patch)
tree4e1bfb4b2bef35dd2acfe2915ab51481cd9ebc16 /lapi.c
parent8980c630bf40e05dad71ded377e3d0f0a17b076c (diff)
downloadlua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.gz
lua-737f119187aca3c8f6743ec6e3cfc04e83723180.tar.bz2
lua-737f119187aca3c8f6743ec6e3cfc04e83723180.zip
better control for GC running or stopped
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lapi.c b/lapi.c
index a1796db3..b4dbc8ed 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.141 2010/11/18 19:15:00 roberto Exp roberto $ 2** $Id: lapi.c,v 2.141 2010/11/26 14:32:31 roberto Exp roberto $
3** Lua API 3** Lua API
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -960,14 +960,16 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
960 g = G(L); 960 g = G(L);
961 switch (what) { 961 switch (what) {
962 case LUA_GCSTOP: { 962 case LUA_GCSTOP: {
963 stopgc(g); 963 g->gcrunning = 0;
964 break; 964 break;
965 } 965 }
966 case LUA_GCRESTART: { 966 case LUA_GCRESTART: {
967 g->GCdebt = 0; 967 g->GCdebt = 0;
968 g->gcrunning = 1;
968 break; 969 break;
969 } 970 }
970 case LUA_GCCOLLECT: { 971 case LUA_GCCOLLECT: {
972 g->gcrunning = 1; /* restart collector if stopped ?? */
971 luaC_fullgc(L, 0); 973 luaC_fullgc(L, 0);
972 break; 974 break;
973 } 975 }
@@ -981,7 +983,8 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
981 break; 983 break;
982 } 984 }
983 case LUA_GCSTEP: { 985 case LUA_GCSTEP: {
984 int stopped = gcstopped(g); 986 int running = g->gcrunning;
987 g->gcrunning = 1; /* allow steps */
985 if (g->gckind == KGC_GEN) { /* generational mode? */ 988 if (g->gckind == KGC_GEN) { /* generational mode? */
986 res = (g->lastmajormem == 0); /* 1 if will do major collection */ 989 res = (g->lastmajormem == 0); /* 1 if will do major collection */
987 luaC_step(L); /* do a single step */ 990 luaC_step(L); /* do a single step */
@@ -995,8 +998,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
995 } 998 }
996 } 999 }
997 } 1000 }
998 if (stopped) /* collector was stopped? */ 1001 g->gcrunning = running; /* restore previous state */
999 stopgc(g); /* keep it that way */
1000 break; 1002 break;
1001 } 1003 }
1002 case LUA_GCSETPAUSE: { 1004 case LUA_GCSETPAUSE: {
@@ -1015,7 +1017,7 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1015 break; 1017 break;
1016 } 1018 }
1017 case LUA_GCISRUNNING: { 1019 case LUA_GCISRUNNING: {
1018 res = !gcstopped(g); 1020 res = g->gcrunning;
1019 break; 1021 break;
1020 } 1022 }
1021 case LUA_GCGEN: { /* change collector to generational mode */ 1023 case LUA_GCGEN: { /* change collector to generational mode */