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 /lapi.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 'lapi.c')
-rw-r--r-- | lapi.c | 44 |
1 files changed, 24 insertions, 20 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.266 2017/05/11 18:57:46 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.267 2017/05/18 12:34:58 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 | */ |
@@ -1046,17 +1046,12 @@ LUA_API int lua_status (lua_State *L) { | |||
1046 | /* | 1046 | /* |
1047 | ** Garbage-collection function | 1047 | ** Garbage-collection function |
1048 | */ | 1048 | */ |
1049 | 1049 | LUA_API int lua_gc (lua_State *L, int what, ...) { | |
1050 | #if !defined(LUA_GENMAJORMUL) | 1050 | va_list argp; |
1051 | #define LUA_GENMAJORMUL 100 | ||
1052 | #define LUA_GENMINORMUL 5 | ||
1053 | #endif | ||
1054 | |||
1055 | LUA_API int lua_gc (lua_State *L, int what, int data) { | ||
1056 | int res = 0; | 1051 | int res = 0; |
1057 | global_State *g; | 1052 | global_State *g = G(L); |
1058 | lua_lock(L); | 1053 | lua_lock(L); |
1059 | g = G(L); | 1054 | va_start(argp, what); |
1060 | switch (what) { | 1055 | switch (what) { |
1061 | case LUA_GCSTOP: { | 1056 | case LUA_GCSTOP: { |
1062 | g->gcrunning = 0; | 1057 | g->gcrunning = 0; |
@@ -1081,11 +1076,12 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
1081 | break; | 1076 | break; |
1082 | } | 1077 | } |
1083 | case LUA_GCSTEP: { | 1078 | case LUA_GCSTEP: { |
1079 | int data = va_arg(argp, int); | ||
1084 | l_mem debt = 1; /* =1 to signal that it did an actual step */ | 1080 | l_mem debt = 1; /* =1 to signal that it did an actual step */ |
1085 | lu_byte oldrunning = g->gcrunning; | 1081 | lu_byte oldrunning = g->gcrunning; |
1086 | g->gcrunning = 1; /* allow GC to run */ | 1082 | g->gcrunning = 1; /* allow GC to run */ |
1087 | if (data == 0) { | 1083 | if (data == 0) { |
1088 | luaE_setdebt(g, -GCSTEPSIZE); /* to do a "small" step */ | 1084 | luaE_setdebt(g, 0); /* do a basic step */ |
1089 | luaC_step(L); | 1085 | luaC_step(L); |
1090 | } | 1086 | } |
1091 | else { /* add 'data' to total debt */ | 1087 | else { /* add 'data' to total debt */ |
@@ -1099,14 +1095,15 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
1099 | break; | 1095 | break; |
1100 | } | 1096 | } |
1101 | case LUA_GCSETPAUSE: { | 1097 | case LUA_GCSETPAUSE: { |
1102 | res = g->gcpause; | 1098 | int data = va_arg(argp, int); |
1103 | g->gcpause = data; | 1099 | res = g->gcpause + 100; |
1100 | g->gcpause = (data >= 100) ? data - 100 : 0; | ||
1104 | break; | 1101 | break; |
1105 | } | 1102 | } |
1106 | case LUA_GCSETSTEPMUL: { | 1103 | case LUA_GCSETSTEPMUL: { |
1107 | res = g->gcstepmul; | 1104 | int data = va_arg(argp, int); |
1108 | if (data < 40) data = 40; /* avoid ridiculous low values (and 0) */ | 1105 | res = g->gcstepmul * 10; |
1109 | g->gcstepmul = data; | 1106 | g->gcstepmul = data / 10; |
1110 | break; | 1107 | break; |
1111 | } | 1108 | } |
1112 | case LUA_GCISRUNNING: { | 1109 | case LUA_GCISRUNNING: { |
@@ -1114,19 +1111,26 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
1114 | break; | 1111 | break; |
1115 | } | 1112 | } |
1116 | case LUA_GCGEN: { | 1113 | case LUA_GCGEN: { |
1117 | lu_byte aux = data & 0xff; | 1114 | int minormul = va_arg(argp, int); |
1118 | g->genminormul = (aux == 0) ? LUA_GENMINORMUL : aux; | 1115 | int majormul = va_arg(argp, int); |
1119 | aux = (data >> 8) & 0xff; | 1116 | g->genminormul = (minormul == 0) ? LUAI_GENMINORMUL : minormul; |
1120 | g->genmajormul = (aux == 0) ? LUA_GENMAJORMUL : aux; | 1117 | g->genmajormul = (majormul == 0) ? LUAI_GENMAJORMUL : majormul; |
1121 | luaC_changemode(L, KGC_GEN); | 1118 | luaC_changemode(L, KGC_GEN); |
1122 | break; | 1119 | break; |
1123 | } | 1120 | } |
1124 | case LUA_GCINC: { | 1121 | case LUA_GCINC: { |
1122 | int pause = va_arg(argp, int); | ||
1123 | int stepmul = va_arg(argp, int); | ||
1124 | int stepsize = va_arg(argp, int); | ||
1125 | g->gcpause = (pause == 0) ? LUAI_GCPAUSE : pause; | ||
1126 | g->gcstepmul = (stepmul == 0) ? LUAI_GCMUL : stepmul; | ||
1127 | g->gcstepsize = (stepsize == 0) ? LUAI_GCSTEPSIZE : stepsize; | ||
1125 | luaC_changemode(L, KGC_INC); | 1128 | luaC_changemode(L, KGC_INC); |
1126 | break; | 1129 | break; |
1127 | } | 1130 | } |
1128 | default: res = -1; /* invalid option */ | 1131 | default: res = -1; /* invalid option */ |
1129 | } | 1132 | } |
1133 | va_end(argp); | ||
1130 | lua_unlock(L); | 1134 | lua_unlock(L); |
1131 | return res; | 1135 | return res; |
1132 | } | 1136 | } |