diff options
author | Adam Lerer <alerer@fb.com> | 2015-08-06 02:44:20 +0300 |
---|---|---|
committer | Adam Lerer <alerer@fb.com> | 2015-08-12 18:26:43 +0300 |
commit | a5a407964888298ab640b5c71a4cb5e517e40dfe (patch) | |
tree | c811db699bdd435acabb23c555785258dc4fbc5f /utils.c | |
parent | e2b3cb5fddbe43b4fd13fa40e6b52d64fecebcf9 (diff) |
Fix lua GC to support allocations across multiple threads (e.g. threads sharedserialize)
Diffstat (limited to 'utils.c')
-rw-r--r-- | utils.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -188,6 +188,23 @@ static int torch_getnumcores(lua_State *L) return 1; } +static void luaTorchGCFunction(void *data) +{ + lua_State *L = data; + lua_gc(L, LUA_GCCOLLECT, 0); +} + +static int torch_setheaptracking(lua_State *L) +{ + int enabled = luaT_checkboolean(L,1); + if(enabled) { + THSetGCHandler(luaTorchGCFunction, L); + } else { + THSetGCHandler(NULL, NULL); + } + return 0; +} + static const struct luaL_Reg torch_utils__ [] = { {"getdefaulttensortype", torch_lua_getdefaulttensortype}, {"isatty", torch_isatty}, @@ -209,6 +226,7 @@ static const struct luaL_Reg torch_utils__ [] = { {"pushudata", luaT_lua_pushudata}, {"version", luaT_lua_version}, {"pointer", luaT_lua_pointer}, + {"setheaptracking", torch_setheaptracking}, {NULL, NULL} }; |