simpler way to check maximum gc threshold

This commit is contained in:
Roberto Ierusalimschy
2003-04-28 16:58:06 -03:00
parent bcc5f1406b
commit f1f8f0ca22

14
lapi.c
View File

@@ -1,5 +1,5 @@
/* /*
** $Id: lapi.c,v 1.234 2003/04/03 13:35:34 roberto Exp roberto $ ** $Id: lapi.c,v 1.235 2003/04/07 14:36:08 roberto Exp roberto $
** Lua API ** Lua API
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@@ -759,10 +759,11 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
*/ */
/* GC values are expressed in Kbytes: #bytes/2^10 */ /* GC values are expressed in Kbytes: #bytes/2^10 */
#define GCscalel(x) ((x)>>10) #define GCscale(x) (cast(int, (x)>>10))
#define GCscale(x) (cast(int, GCscalel(x)))
#define GCunscale(x) (cast(lu_mem, x)<<10) #define GCunscale(x) (cast(lu_mem, x)<<10)
#define MAX_THRESHOLD (cast(lu_mem, ~0) >> 10)
LUA_API int lua_getgcthreshold (lua_State *L) { LUA_API int lua_getgcthreshold (lua_State *L) {
int threshold; int threshold;
lua_lock(L); lua_lock(L);
@@ -781,10 +782,9 @@ LUA_API int lua_getgccount (lua_State *L) {
LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) { LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
lua_lock(L); lua_lock(L);
if (cast(lu_mem, newthreshold) > GCscalel(MAX_LUMEM)) if (cast(lu_mem, newthreshold) > MAX_THRESHOLD)
G(L)->GCthreshold = MAX_LUMEM; newthreshold = cast(int, MAX_THRESHOLD);
else G(L)->GCthreshold = GCunscale(newthreshold);
G(L)->GCthreshold = GCunscale(newthreshold);
luaC_checkGC(L); luaC_checkGC(L);
lua_unlock(L); lua_unlock(L);
} }