diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-26 16:14:29 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-05-26 16:14:29 -0300 |
| commit | 72d82a296c1430a1d2bb3fac8ed8cbfb97868707 (patch) | |
| tree | 4ea80148c5f1bfd38f0e7ca1cb8ef82e00e7e19c /lbaselib.c | |
| parent | 4804bbd9bbfb89deb8a6c7dc2bc65601a701222b (diff) | |
| download | lua-72d82a296c1430a1d2bb3fac8ed8cbfb97868707.tar.gz lua-72d82a296c1430a1d2bb3fac8ed8cbfb97868707.tar.bz2 lua-72d82a296c1430a1d2bb3fac8ed8cbfb97868707.zip | |
revamping the incremental collector
Some simplifications (not counting bytes, couting only slots visited;
no more 'gcfinnum'); more GC parameters; using vararg in 'lua_gc' to
set parameters in different GC modes
Diffstat (limited to 'lbaselib.c')
| -rw-r--r-- | lbaselib.c | 39 |
1 files changed, 33 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lbaselib.c,v 1.314 2016/09/05 19:06:34 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.315 2017/02/23 21:07:34 roberto Exp roberto $ |
| 3 | ** Basic library | 3 | ** Basic library |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -178,19 +178,46 @@ static int luaB_collectgarbage (lua_State *L) { | |||
| 178 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, | 178 | LUA_GCCOUNT, LUA_GCSTEP, LUA_GCSETPAUSE, LUA_GCSETSTEPMUL, |
| 179 | LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC}; | 179 | LUA_GCISRUNNING, LUA_GCGEN, LUA_GCINC}; |
| 180 | int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; | 180 | int o = optsnum[luaL_checkoption(L, 1, "collect", opts)]; |
| 181 | int ex = (int)luaL_optinteger(L, 2, 0); | ||
| 182 | int res = lua_gc(L, o, ex); | ||
| 183 | switch (o) { | 181 | switch (o) { |
| 184 | case LUA_GCCOUNT: { | 182 | case LUA_GCCOUNT: { |
| 185 | int b = lua_gc(L, LUA_GCCOUNTB, 0); | 183 | int k = lua_gc(L, o); |
| 186 | lua_pushnumber(L, (lua_Number)res + ((lua_Number)b/1024)); | 184 | int b = lua_gc(L, LUA_GCCOUNTB); |
| 185 | lua_pushnumber(L, (lua_Number)k + ((lua_Number)b/1024)); | ||
| 187 | return 1; | 186 | return 1; |
| 188 | } | 187 | } |
| 189 | case LUA_GCSTEP: case LUA_GCISRUNNING: { | 188 | case LUA_GCSTEP: { |
| 189 | int step = (int)luaL_optinteger(L, 2, 0); | ||
| 190 | int res = lua_gc(L, o, step); | ||
| 190 | lua_pushboolean(L, res); | 191 | lua_pushboolean(L, res); |
| 191 | return 1; | 192 | return 1; |
| 192 | } | 193 | } |
| 194 | case LUA_GCSETPAUSE: | ||
| 195 | case LUA_GCSETSTEPMUL: { | ||
| 196 | int p = (int)luaL_optinteger(L, 2, 0); | ||
| 197 | int previous = lua_gc(L, o, p); | ||
| 198 | lua_pushinteger(L, previous); | ||
| 199 | return 1; | ||
| 200 | } | ||
| 201 | case LUA_GCISRUNNING: { | ||
| 202 | int res = lua_gc(L, o); | ||
| 203 | lua_pushboolean(L, res); | ||
| 204 | return 1; | ||
| 205 | } | ||
| 206 | case LUA_GCGEN: { | ||
| 207 | int minormul = (int)luaL_optinteger(L, 2, 0); | ||
| 208 | int majormul = (int)luaL_optinteger(L, 3, 0); | ||
| 209 | lua_gc(L, o, minormul, majormul); | ||
| 210 | return 0; | ||
| 211 | } | ||
| 212 | case LUA_GCINC: { | ||
| 213 | int pause = (int)luaL_optinteger(L, 2, 0); | ||
| 214 | int stepmul = (int)luaL_optinteger(L, 3, 0); | ||
| 215 | int stepsize = (int)luaL_optinteger(L, 4, 0); | ||
| 216 | lua_gc(L, o, pause, stepmul, stepsize); | ||
| 217 | return 0; | ||
| 218 | } | ||
| 193 | default: { | 219 | default: { |
| 220 | int res = lua_gc(L, o); | ||
| 194 | lua_pushinteger(L, res); | 221 | lua_pushinteger(L, res); |
| 195 | return 1; | 222 | return 1; |
| 196 | } | 223 | } |
