From 9e8930f02e7a53a41b713c642bcb53b3b61f7cb5 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 13 Nov 2024 10:41:01 +0100 Subject: Cleaning up guano Lane::selfdestruct_next and Universe::selfdestructFirst do not need to be volatile or anything else, all accesses are mutex-protected --- src/lane.cpp | 7 ++++--- src/lane.hpp | 3 ++- src/universe.hpp | 3 ++- 3 files changed, 8 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/lane.cpp b/src/lane.cpp index 4caebcb..2bc3431 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -633,6 +633,8 @@ void Lane::selfdestructAdd() assert(selfdestruct_next == nullptr); selfdestruct_next = U->selfdestructFirst; + assert(selfdestruct_next); + U->selfdestructFirst = this; } @@ -648,7 +650,7 @@ void Lane::selfdestructAdd() // cancel/kill). // if (selfdestruct_next != nullptr) { - Lane* volatile* _ref = static_cast(&U->selfdestructFirst); + Lane** _ref{ &U->selfdestructFirst }; while (*_ref != SELFDESTRUCT_END) { if (*_ref == this) { @@ -659,7 +661,7 @@ void Lane::selfdestructAdd() _found = true; break; } - _ref = static_cast(&((*_ref)->selfdestruct_next)); + _ref = &((*_ref)->selfdestruct_next); } assert(_found); } @@ -846,7 +848,6 @@ static LUAG_FUNC(lane_gc) if (_lane->status.load(std::memory_order_acquire) < Lane::Done) { // still running: will have to be cleaned up later _lane->selfdestructAdd(); - assert(_lane->selfdestruct_next); if (_have_gc_cb) { luaG_pushstring(L_, "selfdestruct"); // L_: ud gc_cb name status lua_call(L_, 2, 0); // L_: ud diff --git a/src/lane.hpp b/src/lane.hpp index 1926824..4f87e2a 100644 --- a/src/lane.hpp +++ b/src/lane.hpp @@ -128,7 +128,8 @@ class Lane // M: sets to false, flags true for cancel request // S: reads to see if cancel is requested - Lane* volatile selfdestruct_next{ nullptr }; + // access is protected by Universe::selfDestructMutex + Lane* selfdestruct_next{ nullptr }; // // M: sets to non-nullptr if facing lane handle '__gc' cycle but the lane // is still running diff --git a/src/universe.hpp b/src/universe.hpp index 18e125f..a45ce86 100644 --- a/src/universe.hpp +++ b/src/universe.hpp @@ -113,7 +113,8 @@ class Universe std::atomic debugspewIndentDepth{ 0 }; #endif // USE_DEBUG_SPEW() - Lane* volatile selfdestructFirst{ nullptr }; + // access is protected by selfDestructMutex + Lane* selfdestructFirst{ nullptr }; // After a lane has removed itself from the chain, it still performs some processing. // The terminal desinit sequence should wait for all such processing to terminate before force-killing threads std::atomic selfdestructingCount{ 0 }; -- cgit v1.2.3-55-g6feb