From eead6105a7dcf2cd561b4bd50604c584a4c46cdc Mon Sep 17 00:00:00 2001 From: pixel Date: Wed, 23 Jan 2008 17:53:12 +0000 Subject: Deffering the deletion of the thread to the garbage collector, through the weaken() method, just introduced. --- lib/BLua.cc | 14 ++++++++------ lib/LuaTask.cc | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/BLua.cc b/lib/BLua.cc index aab4578..76a0c6d 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.cc,v 1.56 2008-01-15 17:01:03 pixel Exp $ */ +/* $Id: BLua.cc,v 1.57 2008-01-23 17:53:12 pixel Exp $ */ #include #include "BLua.h" @@ -459,11 +459,8 @@ Lua * Lua::spawn_from_thread(lua_State * __L) { L->father = Father(); } -Lua::~Lua() { - if (!_is_thread) { -// lua_setgcthreshold(L, 0); - lua_close(L); - } else { +void Lua::weaken() { + if (_is_thread) { push(); // -1 = nil push("BLUA_THREADS"); // -2 = nil, -1 = "BLUA_THREADS" copy(); // -3 = nil, -2 = "BLUA_THREADS", -1 = "BLUA_THREADS" @@ -474,7 +471,12 @@ Lua::~Lua() { settable(LUA_REGISTRYINDEX); // -1 = thread pop(); } +} +Lua::~Lua() { + weaken(); + if (!_is_thread) + lua_close(L); L = 0; } diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc index 12f1db5..7b1e045 100644 --- a/lib/LuaTask.cc +++ b/lib/LuaTask.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaTask.cc,v 1.26 2008-01-23 17:41:10 pixel Exp $ */ +/* $Id: LuaTask.cc,v 1.27 2008-01-23 17:53:12 pixel Exp $ */ #include #include @@ -60,7 +60,7 @@ LuaTask::~LuaTask() { settop(0); } if (destroy_VM) - delete L; + L->weaken(); } LuaTask * LuaTask::gettop() { -- cgit v1.2.3