mirror of
https://github.com/0O0o0oOoO00/Alas.git
synced 2026-05-14 10:59:24 +08:00
fix: move lua state operation to pauser
This commit is contained in:
@@ -59,13 +59,13 @@ static fnset_TimeScaleT get_Time_set_timeScale() {
|
||||
|
||||
LuaStatePauser::LuaStatePauser(lua_State* L) : m_L(L) {}
|
||||
|
||||
void LuaStatePauser::do_when_paused(const std::function<void()>& func) {
|
||||
void LuaStatePauser::do_when_paused(std::function<void()>&& func) {
|
||||
auto _ = std::lock_guard<std::mutex>(m_atomic_pause);
|
||||
ensure_debug_hook();
|
||||
auto lk = std::binary_semaphore(0);
|
||||
|
||||
g_pause_flag.store(&lk);
|
||||
g_lua_state_operation.store(&func);
|
||||
g_lua_state_operation.store(new std::function<void()>(std::move(func)));
|
||||
lk.acquire();
|
||||
SPDLOG_INFO("lua operation finished");
|
||||
}
|
||||
@@ -99,6 +99,7 @@ void LuaStatePauser::debug_hook(lua_State *L, lua_Debug *ar) {
|
||||
SPDLOG_INFO("pause triggered, operate lua state");
|
||||
(*callback)();
|
||||
auto f = g_pause_flag.load();
|
||||
delete g_lua_state_operation.load();
|
||||
g_lua_state_operation.store(nullptr);
|
||||
g_pause_flag.store(nullptr);
|
||||
f->release();
|
||||
|
||||
Reference in New Issue
Block a user