From d28c5884688286bf33ab9e432534f06c0dd720d8 Mon Sep 17 00:00:00 2001 From: jyelon Date: Wed, 27 Apr 2022 16:05:45 -0400 Subject: [PATCH] Add an assert check to make sure no threads scheduled in nonauth model --- luprex/core/cpp/world-accessor.cpp | 2 +- luprex/core/cpp/world-core.cpp | 9 +++++++-- luprex/core/cpp/world.hpp | 4 ++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/luprex/core/cpp/world-accessor.cpp b/luprex/core/cpp/world-accessor.cpp index 25436c2c..6bbea6e2 100644 --- a/luprex/core/cpp/world-accessor.cpp +++ b/luprex/core/cpp/world-accessor.cpp @@ -312,7 +312,7 @@ LuaDefine(wait, "nticks", return LS.result(); } else { // in an authoritative model, wait schedules a continuation. - w->thread_sched_.add(w->clock_ + n, w->lthread_thread_id_, w->lthread_place_id_); + w->schedule(w->clock_ + n, w->lthread_thread_id_, w->lthread_place_id_); lua_yield(L, 0); return LS.result(); } diff --git a/luprex/core/cpp/world-core.cpp b/luprex/core/cpp/world-core.cpp index afb3d731..adadb8cb 100644 --- a/luprex/core/cpp/world-core.cpp +++ b/luprex/core/cpp/world-core.cpp @@ -512,7 +512,7 @@ void World::invoke_lua(int64_t actor_id, int64_t place_id, const eng::string &ac LS.rawset(threads, tid, thinfo); LS.result(); - thread_sched_.add(0, tid, place_id); + schedule(0, tid, place_id); run_scheduled_threads(); assert(stack_is_clear()); } @@ -607,7 +607,7 @@ void World::invoke_plan(int64_t actor_id, int64_t place_id, const eng::string &a // Push the thread's ID into the runnable thread queue, // then run the thread queue. - thread_sched_.add(0, tid, place_id); + schedule(0, tid, place_id); run_scheduled_threads(); assert(stack_is_clear()); } @@ -635,6 +635,11 @@ void World::invoke_lua_source(int64_t actor_id, int64_t place_id, const eng::str } } +void World::schedule(int64_t clk, int64_t thid, int64_t plid) { + assert(is_authoritative()); + thread_sched_.add(clk, thid, plid); +} + void World::run_scheduled_threads() { assert(stack_is_clear()); lua_State *L = state(); diff --git a/luprex/core/cpp/world.hpp b/luprex/core/cpp/world.hpp index 8a9a1fbd..fc9dba33 100644 --- a/luprex/core/cpp/world.hpp +++ b/luprex/core/cpp/world.hpp @@ -264,6 +264,10 @@ public: int64_t alloc_id_predictable(); private: + // Add a thread to the scheduler queue. + // + void schedule(int64_t clk, int64_t thid, int64_t plid); + // Store a pointer to a world model into a lua registry. // static void store_global_pointer(lua_State *L, World *w);