diff options
author | pixel <pixel> | 2008-01-23 17:53:12 +0000 |
---|---|---|
committer | pixel <pixel> | 2008-01-23 17:53:12 +0000 |
commit | eead6105a7dcf2cd561b4bd50604c584a4c46cdc (patch) | |
tree | ee6d567f0f444e464d59cd8f64ed42873c5a62c4 | |
parent | b1e8c832653e00107a2b587df398a02999e21a9a (diff) |
Deffering the deletion of the thread to the garbage collector, through the weaken() method, just introduced.
-rw-r--r-- | include/BLua.h | 3 | ||||
-rw-r--r-- | lib/BLua.cc | 14 | ||||
-rw-r--r-- | lib/LuaTask.cc | 4 |
3 files changed, 12 insertions, 9 deletions
diff --git a/include/BLua.h b/include/BLua.h index c57a633..60ca335 100644 --- a/include/BLua.h +++ b/include/BLua.h @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: BLua.h,v 1.41 2007-07-27 10:05:52 pixel Exp $ */ +/* $Id: BLua.h,v 1.42 2008-01-23 17:53:12 pixel Exp $ */ #ifndef __BLUA_H__ #define __BLUA_H__ @@ -112,6 +112,7 @@ class Lua : public Base { Lua * thread(bool saveit = true); Lua * thread(const String &, int nargs = 0, bool saveit = true); Lua * thread(Handle *, int nargs = 0, bool saveit = true); + void weaken(); int yield(int nresults = 0); bool resume(int nargs = 0) throw (GeneralException); bool resume(const String &, int nargs = 0); 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 <stdlib.h> #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 <LuaTask.h> #include <LuaHandle.h> @@ -60,7 +60,7 @@ LuaTask::~LuaTask() { settop(0); } if (destroy_VM) - delete L; + L->weaken(); } LuaTask * LuaTask::gettop() { |