diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-30 11:15:23 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2004-06-30 11:15:23 -0300 |
| commit | 96917ff42a7867e72629d6cd39c818df4c250b91 (patch) | |
| tree | 1f6268e8709692e64ae69dfd88891a903d51749c | |
| parent | a6179adf12d78e7e1fedee42440127f3e1786f3d (diff) | |
| download | lua-96917ff42a7867e72629d6cd39c818df4c250b91.tar.gz lua-96917ff42a7867e72629d6cd39c818df4c250b91.tar.bz2 lua-96917ff42a7867e72629d6cd39c818df4c250b91.zip | |
"step" option in lua_gc also need to lock Lua.
| -rw-r--r-- | lapi.c | 23 |
1 files changed, 13 insertions, 10 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lapi.c,v 2.11 2004/06/04 15:30:53 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.12 2004/06/08 14:31:00 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 | */ |
| @@ -820,25 +820,26 @@ LUA_API int lua_dump (lua_State *L, lua_Chunkwriter writer, void *data) { | |||
| 820 | */ | 820 | */ |
| 821 | 821 | ||
| 822 | LUA_API int lua_gc (lua_State *L, int what, int data) { | 822 | LUA_API int lua_gc (lua_State *L, int what, int data) { |
| 823 | global_State *g = G(L); | 823 | int res = 0; |
| 824 | global_State *g; | ||
| 825 | lua_lock(L); | ||
| 826 | g = G(L); | ||
| 824 | switch (what) { | 827 | switch (what) { |
| 825 | case LUA_GCSTOP: { | 828 | case LUA_GCSTOP: { |
| 826 | g->GCthreshold = MAXLMEM; | 829 | g->GCthreshold = MAXLMEM; |
| 827 | return 0; | 830 | break; |
| 828 | } | 831 | } |
| 829 | case LUA_GCRESTART: { | 832 | case LUA_GCRESTART: { |
| 830 | g->GCthreshold = g->nblocks; | 833 | g->GCthreshold = g->nblocks; |
| 831 | return 0; | 834 | break; |
| 832 | } | 835 | } |
| 833 | case LUA_GCCOLLECT: { | 836 | case LUA_GCCOLLECT: { |
| 834 | lua_lock(L); | ||
| 835 | luaC_fullgc(L); | 837 | luaC_fullgc(L); |
| 836 | lua_unlock(L); | 838 | break; |
| 837 | return 0; | ||
| 838 | } | 839 | } |
| 839 | case LUA_GCCOUNT: { | 840 | case LUA_GCCOUNT: { |
| 840 | /* GC values are expressed in Kbytes: #bytes/2^10 */ | 841 | /* GC values are expressed in Kbytes: #bytes/2^10 */ |
| 841 | return cast(int, g->nblocks >> 10); | 842 | res = cast(int, g->nblocks >> 10); |
| 842 | } | 843 | } |
| 843 | case LUA_GCSTEP: { | 844 | case LUA_GCSTEP: { |
| 844 | lu_mem a = (cast(lu_mem, data) << 10); | 845 | lu_mem a = (cast(lu_mem, data) << 10); |
| @@ -847,10 +848,12 @@ LUA_API int lua_gc (lua_State *L, int what, int data) { | |||
| 847 | else | 848 | else |
| 848 | g->GCthreshold = 0; | 849 | g->GCthreshold = 0; |
| 849 | luaC_step(L); | 850 | luaC_step(L); |
| 850 | return 0; | 851 | break; |
| 851 | } | 852 | } |
| 852 | default: return -1; /* invalid option */ | 853 | default: res = -1; /* invalid option */ |
| 853 | } | 854 | } |
| 855 | lua_unlock(L); | ||
| 856 | return res; | ||
| 854 | } | 857 | } |
| 855 | 858 | ||
| 856 | 859 | ||
