aboutsummaryrefslogtreecommitdiff
path: root/lapi.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-09 14:34:35 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2004-03-09 14:34:35 -0300
commitb876ec61c03e05ea0c4c02d8ad8abb84cf55e87c (patch)
tree62224cadfc7273beecb092f0e4a761e4c4f634e5 /lapi.c
parent898e8a67942186d62aa2cd3dc4ef96fe894788ef (diff)
downloadlua-b876ec61c03e05ea0c4c02d8ad8abb84cf55e87c.tar.gz
lua-b876ec61c03e05ea0c4c02d8ad8abb84cf55e87c.tar.bz2
lua-b876ec61c03e05ea0c4c02d8ad8abb84cf55e87c.zip
new (temporary?) API for garbage collector
Diffstat (limited to 'lapi.c')
-rw-r--r--lapi.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/lapi.c b/lapi.c
index 59129f71..48993abf 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.2 2004/01/15 12:40:26 roberto Exp roberto $ 2** $Id: lapi.c,v 2.3 2004/02/20 16:01:05 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*/
@@ -807,39 +807,34 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) {
807 807
808 808
809/* 809/*
810** Garbage-collection functions 810** Garbage-collection function
811*/ 811*/
812 812
813/* GC values are expressed in Kbytes: #bytes/2^10 */ 813LUA_API int lua_gc (lua_State *L, int what, int data) {
814#define GCscale(x) (cast(int, (x)>>10)) 814 global_State *g = G(L);
815#define GCunscale(x) (cast(lu_mem, x)<<10) 815 switch (what) {
816 816 case LUA_GCSTOP: {
817#define MAX_THRESHOLD (cast(lu_mem, ~0) >> 10) 817 g->GCthreshold = MAXLMEM;
818 818 return 0;
819LUA_API int lua_getgcthreshold (lua_State *L) { 819 }
820 int threshold; 820 case LUA_GCRESTART: {
821 lua_lock(L); 821 g->GCthreshold = g->nblocks;
822 threshold = GCscale(G(L)->GCthreshold); 822 return 0;
823 lua_unlock(L); 823 }
824 return threshold; 824 case LUA_GCCOLLECT: {
825} 825 lua_lock(L);
826 826 luaC_fullgc(L);
827LUA_API int lua_getgccount (lua_State *L) { 827 lua_unlock(L);
828 int count; 828 return 0;
829 lua_lock(L); 829 }
830 count = GCscale(G(L)->nblocks); 830 case LUA_GCCOUNT: {
831 lua_unlock(L); 831 /* GC values are expressed in Kbytes: #bytes/2^10 */
832 return count; 832 return cast(int, g->nblocks >> 10);
833 }
834 default: return -1; /* invalid option */
835 }
833} 836}
834 837
835LUA_API void lua_setgcthreshold (lua_State *L, int newthreshold) {
836 lua_lock(L);
837 if (cast(lu_mem, newthreshold) > MAX_THRESHOLD)
838 newthreshold = cast(int, MAX_THRESHOLD);
839 G(L)->GCthreshold = GCunscale(newthreshold);
840 luaC_checkGC(L);
841 lua_unlock(L);
842}
843 838
844 839
845/* 840/*