summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-14 14:43:14 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2014-02-14 14:43:14 -0200
commit1cce3e6842fd76099b1973dabd8504566610f068 (patch)
tree1f28b6c3952db089a664877a8cb693e66ec9c243
parent0b04c561f5c08600831f3bb6126b062658d434b1 (diff)
downloadlua-1cce3e6842fd76099b1973dabd8504566610f068.tar.gz
lua-1cce3e6842fd76099b1973dabd8504566610f068.tar.bz2
lua-1cce3e6842fd76099b1973dabd8504566610f068.zip
change in the way 'collectgarbage("step", size)' interprets 'size'
(mimicking the way the GC itself behaves when Lua allocates 'size' Kbytes)
-rw-r--r--lapi.c22
-rw-r--r--lgc.c22
-rw-r--r--lgc.h3
3 files changed, 23 insertions, 24 deletions
diff --git a/lapi.c b/lapi.c
index d5765cc9..cb38ffba 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.194 2014/02/13 12:11:34 roberto Exp roberto $ 2** $Id: lapi.c,v 2.195 2014/02/13 17:25:20 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*/
@@ -1070,12 +1070,20 @@ LUA_API int lua_gc (lua_State *L, int what, int data) {
1070 break; 1070 break;
1071 } 1071 }
1072 case LUA_GCSTEP: { 1072 case LUA_GCSTEP: {
1073 lu_mem debt = cast(lu_mem, data) * 1024 - GCSTEPSIZE; 1073 l_mem debt = 1; /* =1 to signal that it did an actual step */
1074 if (g->gcrunning) 1074 int oldrunning = g->gcrunning;
1075 debt += g->GCdebt; /* include current debt */ 1075 g->gcrunning = 1; /* force GC to run */
1076 luaE_setdebt(g, debt); 1076 if (data == 0) {
1077 luaC_forcestep(L); 1077 luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */
1078 if (g->gcstate == GCSpause) /* end of cycle? */ 1078 luaC_step(L);
1079 }
1080 else { /* add 'data' to total debt */
1081 debt = cast(l_mem, data) * 1024 + g->GCdebt;
1082 luaE_setdebt(g, debt);
1083 luaC_checkGC(L);
1084 }
1085 g->gcrunning = oldrunning; /* restore previous state */
1086 if (debt > 0 && g->gcstate == GCSpause) /* end of cycle? */
1079 res = 1; /* signal it */ 1087 res = 1; /* signal it */
1080 break; 1088 break;
1081 } 1089 }
diff --git a/lgc.c b/lgc.c
index ea0537df..5c365e32 100644
--- a/lgc.c
+++ b/lgc.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.c,v 2.172 2014/02/13 14:46:38 roberto Exp roberto $ 2** $Id: lgc.c,v 2.173 2014/02/13 17:25:20 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*/
@@ -1087,11 +1087,15 @@ static l_mem getdebt (global_State *g) {
1087} 1087}
1088 1088
1089/* 1089/*
1090** performs a basic GC step 1090** performs a basic GC step when collector is running
1091*/ 1091*/
1092void luaC_forcestep (lua_State *L) { 1092void luaC_step (lua_State *L) {
1093 global_State *g = G(L); 1093 global_State *g = G(L);
1094 l_mem debt = getdebt(g); 1094 l_mem debt = getdebt(g);
1095 if (!g->gcrunning) { /* not running? */
1096 luaE_setdebt(g, -GCSTEPSIZE * 10); /* avoid being called too often */
1097 return;
1098 }
1095 do { 1099 do {
1096 if (g->gcstate == GCScallfin && g->tobefnz) { 1100 if (g->gcstate == GCScallfin && g->tobefnz) {
1097 unsigned int n = runafewfinalizers(L); 1101 unsigned int n = runafewfinalizers(L);
@@ -1113,18 +1117,6 @@ void luaC_forcestep (lua_State *L) {
1113 1117
1114 1118
1115/* 1119/*
1116** performs a basic GC step when collector is running
1117*/
1118void luaC_step (lua_State *L) {
1119 if (!G(L)->gcrunning)
1120 luaE_setdebt(G(L), -GCSTEPSIZE); /* avoid being called too often */
1121 else
1122 luaC_forcestep(L);
1123}
1124
1125
1126
1127/*
1128** performs a full GC cycle; if "isemergency", does not call 1120** performs a full GC cycle; if "isemergency", does not call
1129** finalizers (which could change stack positions) 1121** finalizers (which could change stack positions)
1130*/ 1122*/
diff --git a/lgc.h b/lgc.h
index a9e497c7..0e24d2c3 100644
--- a/lgc.h
+++ b/lgc.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lgc.h,v 2.78 2014/02/13 12:11:34 roberto Exp roberto $ 2** $Id: lgc.h,v 2.79 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*/
@@ -126,7 +126,6 @@
126LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o); 126LUAI_FUNC void luaC_fix (lua_State *L, GCObject *o);
127LUAI_FUNC void luaC_freeallobjects (lua_State *L); 127LUAI_FUNC void luaC_freeallobjects (lua_State *L);
128LUAI_FUNC void luaC_step (lua_State *L); 128LUAI_FUNC void luaC_step (lua_State *L);
129LUAI_FUNC void luaC_forcestep (lua_State *L);
130LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask); 129LUAI_FUNC void luaC_runtilstate (lua_State *L, int statesmask);
131LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); 130LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency);
132LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz); 131LUAI_FUNC GCObject *luaC_newobj (lua_State *L, int tt, size_t sz);