diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-14 14:43:14 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2014-02-14 14:43:14 -0200 |
| commit | 1cce3e6842fd76099b1973dabd8504566610f068 (patch) | |
| tree | 1f28b6c3952db089a664877a8cb693e66ec9c243 /lapi.c | |
| parent | 0b04c561f5c08600831f3bb6126b062658d434b1 (diff) | |
| download | lua-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)
Diffstat (limited to 'lapi.c')
| -rw-r--r-- | lapi.c | 22 |
1 files changed, 15 insertions, 7 deletions
| @@ -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 | } |
