From d931191901e9c20b15971c70b871cb1680e99ba8 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 18 Feb 2021 16:19:43 -0500 Subject: [PATCH] Smaller threads data structure --- luprex/core/cpp/world.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/luprex/core/cpp/world.cpp b/luprex/core/cpp/world.cpp index 9a33a904..480d171f 100644 --- a/luprex/core/cpp/world.cpp +++ b/luprex/core/cpp/world.cpp @@ -208,8 +208,8 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a // Set up for Lua manipulation. lua_State *L = state(); - LuaVar actor, place, func, tangibles, mt, index, actions, threadtab, thread, threadinfo, message; - LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, threadtab, thread, threadinfo, message); + LuaVar actor, place, func, tangibles, mt, index, actions, thread, threads, message; + LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, thread, threads, message); // Get the actor and place. LS.rawget(tangibles, LuaRegistry, "tangibles"); @@ -251,14 +251,12 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const std::string &a lua_xmove(L, CO, 4); // Store the thread into place's thread table. - LS.rawget(threadtab, mt, "threads"); - if (!LS.istable(threadtab)) { + LS.rawget(threads, mt, "threads"); + if (!LS.istable(threads)) { LS.result(); return; } - LS.set(threadinfo, LuaNewTable); - LS.rawset(threadinfo, "thread", thread); - LS.rawset(threadtab, tid, threadinfo); + LS.rawset(threads, tid, thread); LS.result(); // Push the thread's ID into the runnable thread queue, @@ -273,8 +271,8 @@ void World::enqueue_thread(int64_t tid, int64_t place_id) { void World::run_thread(int64_t tid, int64_t place_id) { lua_State *L = state(); - LuaVar tangibles, place, mt, threads, threadtab, thread; - LuaStack LS(L, tangibles, place, mt, threads, threadtab, thread); + LuaVar tangibles, place, mt, threads, thread; + LuaStack LS(L, tangibles, place, mt, threads, thread); LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(place, tangibles, place_id); @@ -292,17 +290,11 @@ void World::run_thread(int64_t tid, int64_t place_id) { LS.result(); return; } - LS.rawget(threadtab, threads, tid); - if (!LS.istable(threadtab)) { - LS.result(); - return; - } - LS.rawget(thread, threadtab, "thread"); + LS.rawget(thread, threads, tid); if (!LS.isthread(thread)) { LS.result(); return; } - LS.rawset(threadtab, "wake", LuaNil); // Resume the coroutine. lua_State *CO = LS.ckthread(thread);