mirror of
https://github.com/lua/lua.git
synced 2024-12-03 23:23:48 +08:00
simpler way to check maximum gc threshold
This commit is contained in:
parent
bcc5f1406b
commit
f1f8f0ca22
14
lapi.c
14
lapi.c
@ -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
|
||||
** 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 */
|
||||
#define GCscalel(x) ((x)>>10)
|
||||
#define GCscale(x) (cast(int, GCscalel(x)))
|
||||
#define GCscale(x) (cast(int, (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) {
|
||||
int threshold;
|
||||
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_lock(L);
|
||||
if (cast(lu_mem, newthreshold) > GCscalel(MAX_LUMEM))
|
||||
G(L)->GCthreshold = MAX_LUMEM;
|
||||
else
|
||||
G(L)->GCthreshold = GCunscale(newthreshold);
|
||||
if (cast(lu_mem, newthreshold) > MAX_THRESHOLD)
|
||||
newthreshold = cast(int, MAX_THRESHOLD);
|
||||
G(L)->GCthreshold = GCunscale(newthreshold);
|
||||
luaC_checkGC(L);
|
||||
lua_unlock(L);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user