From 38a4b6b252dd46dc00e1871886e35c196ed1f245 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Fri, 17 May 2024 10:26:39 +0200 Subject: Lane::close() --- src/lane.cpp | 11 ++++------- src/lane.h | 1 + 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/lane.cpp b/src/lane.cpp index 57e3454..7165e85 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -190,8 +190,7 @@ LUAG_FUNC(thread_join) LUA_ASSERT(L_, false); _ret = 0; } - lua_close(_L2); - _lane->L = nullptr; + _lane->close(); STACK_CHECK(L_, _ret); return _ret; } @@ -683,8 +682,7 @@ static void lane_main(Lane* lane_) lane_->waiting_on = nullptr; // just in case if (selfdestruct_remove(lane_)) { // check and remove (under lock!) // We're a free-running thread and no-one's there to clean us up. - lua_close(lane_->L); - lane_->L = nullptr; // just in case + lane_->close(); lane_->U->selfdestructMutex.lock(); // done with lua_close(), terminal shutdown sequence may proceed lane_->U->selfdestructingCount.fetch_sub(1, std::memory_order_release); @@ -752,9 +750,8 @@ static void lane_main(Lane* lane_) return 0; } else if (_lane->L) { // no longer accessing the Lua VM: we can close right now - lua_close(_lane->L); - _lane->L = nullptr; - // just in case, but s will be freed soon so... + _lane->close(); + // just in case, but _lane will be freed soon so... _lane->debugName = ""; } diff --git a/src/lane.h b/src/lane.h index 4094279..c0b5246 100644 --- a/src/lane.h +++ b/src/lane.h @@ -119,6 +119,7 @@ class Lane ~Lane(); void changeDebugName(int nameIdx_); + void close() { lua_State* _L{ L }; L = nullptr; lua_close(_L); } void pushThreadStatus(lua_State* L_) const; void securizeDebugName(lua_State* L_); void startThread(int priority_); -- cgit v1.2.3-55-g6feb