Smaller threads data structure

This commit is contained in:
2021-02-18 16:19:43 -05:00
parent 1dcf0494ef
commit d931191901

View File

@@ -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. // Set up for Lua manipulation.
lua_State *L = state(); lua_State *L = state();
LuaVar 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, threadtab, thread, threadinfo, message); LuaStack LS(L, actor, place, func, tangibles, mt, index, actions, thread, threads, message);
// Get the actor and place. // Get the actor and place.
LS.rawget(tangibles, LuaRegistry, "tangibles"); 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); lua_xmove(L, CO, 4);
// Store the thread into place's thread table. // Store the thread into place's thread table.
LS.rawget(threadtab, mt, "threads"); LS.rawget(threads, mt, "threads");
if (!LS.istable(threadtab)) { if (!LS.istable(threads)) {
LS.result(); LS.result();
return; return;
} }
LS.set(threadinfo, LuaNewTable); LS.rawset(threads, tid, thread);
LS.rawset(threadinfo, "thread", thread);
LS.rawset(threadtab, tid, threadinfo);
LS.result(); LS.result();
// Push the thread's ID into the runnable thread queue, // 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) { void World::run_thread(int64_t tid, int64_t place_id) {
lua_State *L = state(); lua_State *L = state();
LuaVar tangibles, place, mt, threads, threadtab, thread; LuaVar tangibles, place, mt, threads, thread;
LuaStack LS(L, tangibles, place, mt, threads, threadtab, thread); LuaStack LS(L, tangibles, place, mt, threads, thread);
LS.rawget(tangibles, LuaRegistry, "tangibles"); LS.rawget(tangibles, LuaRegistry, "tangibles");
LS.rawget(place, tangibles, place_id); LS.rawget(place, tangibles, place_id);
@@ -292,17 +290,11 @@ void World::run_thread(int64_t tid, int64_t place_id) {
LS.result(); LS.result();
return; return;
} }
LS.rawget(threadtab, threads, tid); LS.rawget(thread, threads, tid);
if (!LS.istable(threadtab)) {
LS.result();
return;
}
LS.rawget(thread, threadtab, "thread");
if (!LS.isthread(thread)) { if (!LS.isthread(thread)) {
LS.result(); LS.result();
return; return;
} }
LS.rawset(threadtab, "wake", LuaNil);
// Resume the coroutine. // Resume the coroutine.
lua_State *CO = LS.ckthread(thread); lua_State *CO = LS.ckthread(thread);