From 6177a3c6b5a05ac2c64978ccf3ca11de9793505b Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Thu, 13 Jun 2024 12:18:27 +0200 Subject: A small step toward making clang happy --- deep_test/deep_test.vcxproj | 63 +++++++++++++++++++++++++++++++++++++++++++++ src/_pch.h | 5 +++- src/compat.h | 6 ++--- src/intercopycontext.cpp | 2 +- src/lane.cpp | 35 +++++++++++++------------ src/lane.h | 4 +++ src/lanes.cpp | 9 +++++++ 7 files changed, 102 insertions(+), 22 deletions(-) diff --git a/deep_test/deep_test.vcxproj b/deep_test/deep_test.vcxproj index 298594e..0316d6f 100644 --- a/deep_test/deep_test.vcxproj +++ b/deep_test/deep_test.vcxproj @@ -1,6 +1,10 @@ + + Debug 5.1 + Prospero + Debug 5.1 Win32 @@ -9,6 +13,10 @@ Debug 5.1 x64 + + Debug 5.2 + Prospero + Debug 5.2 Win32 @@ -17,10 +25,18 @@ Debug 5.2 x64 + + Debug 5.3 + Prospero + Debug 5.3 Win32 + + Debug 5.4 + Prospero + Debug 5.4 Win32 @@ -29,6 +45,10 @@ Debug 5.4 x64 + + Debug LuaJIT 2.0.5 + Prospero + Debug LuaJIT 2.0.5 Win32 @@ -37,6 +57,10 @@ Debug LuaJIT 2.0.5 x64 + + Debug LuaJIT 2.1.0-beta3 + Prospero + Debug LuaJIT 2.1.0-beta3 Win32 @@ -45,6 +69,10 @@ Debug LuaJIT 2.1.0-beta3 x64 + + Debug MoonJIT + Prospero + Debug MoonJIT Win32 @@ -53,6 +81,10 @@ Debug MoonJIT x64 + + Release 5.3 + Prospero + Release 5.3 Win32 @@ -65,6 +97,10 @@ Release 5.3 x64 + + Release 5.4 + Prospero + Release 5.4 Win32 @@ -193,6 +229,33 @@ true MultiByte + + Clang + + + Clang + + + Clang + + + Clang + + + Clang + + + Clang + + + Clang + + + Clang + + + Clang + diff --git a/src/_pch.h b/src/_pch.h index a7de846..6dc0cb5 100644 --- a/src/_pch.h +++ b/src/_pch.h @@ -6,15 +6,18 @@ #include #include #include +#include #include #include #include +#ifndef __PROSPERO__ #include +#endif // __PROSPERO__ #include #include #include #include -#include +//#include #include #include #include diff --git a/src/compat.h b/src/compat.h index 6458307..3b0ebf4 100644 --- a/src/compat.h +++ b/src/compat.h @@ -166,7 +166,7 @@ struct Wrap // ################################################################################################# template -struct Wrap::type> +struct Wrap> { static inline int lua_dump(lua_State* L_, lua_Writer writer_, void* data_, int strip_) { @@ -200,7 +200,7 @@ struct Wrap::type> // ################################################################################################# template -struct Wrap::type> +struct Wrap> { static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) { @@ -235,7 +235,7 @@ struct Wrap::type> // ################################################################################################# template -struct Wrap::type> +struct Wrap> { static inline int lua_dump(lua_State* const L_, lua_Writer const writer_, void* const data_, [[maybe_unused]] int const strip_) { diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 8c9a026..190e15e 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -101,7 +101,7 @@ THE SOFTWARE. lua_rawget(L1, -2); // L1: ... v ... {} "f.q.n" } std::string_view _fqn{ luaG_tostring(L1, -1) }; - DEBUGSPEW_CODE(DebugSpew(Universe::Get(L1)) << "function [C] " << _fqn << std::endl); + DEBUGSPEW_CODE(DebugSpew(U) << "function [C] " << _fqn << std::endl); // popping doesn't invalidate the pointer since this is an interned string gotten from the lookup database lua_pop(L1, (mode == LookupMode::FromKeeper) ? 1 : 2); // L1: ... v ... STACK_CHECK(L1, 0); diff --git a/src/lane.cpp b/src/lane.cpp index 6f4935e..c2cbbac 100644 --- a/src/lane.cpp +++ b/src/lane.cpp @@ -671,17 +671,23 @@ static void PrepareLaneHelpers(Lane* lane_) // ################################################################################################# -static void lane_main(Lane* lane_) +static void lane_main(Lane* const lane_) { - lua_State* const _L{ lane_->L }; // wait until the launching thread has finished preparing L +#ifndef __PROSPERO__ lane_->ready.wait(); +#else // __PROSPERO__ + while (!lane_->ready._My_flag) { + std::this_thread::yield(); + } +#endif // __PROSPERO__ + + lua_State* const _L{ lane_->L }; LuaError _rc{ LuaError::ERRRUN }; if (lane_->status == Lane::Pending) { // nothing wrong happened during preparation, we can work // At this point, the lane function and arguments are on the stack, possibly preceded by the error handler int const _errorHandlerCount{ lane_->errorTraceLevel == Lane::Minimal ? 0 : 1}; int const _nargs{ lua_gettop(_L) - 1 - _errorHandlerCount }; - DEBUGSPEW_CODE(Universe* _U = Universe::Get(_L)); lane_->status = Lane::Running; // Pending -> Running PrepareLaneHelpers(lane_); @@ -695,11 +701,11 @@ static void lane_main(Lane* lane_) // in case of error and if it exists, fetch stack trace from registry and push it push_stack_trace(_L, lane_->errorTraceLevel, _rc, 1); // L: retvals|error [trace] - DEBUGSPEW_CODE(DebugSpew(_U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : luaG_typename(_L, 1)) << ")" << std::endl); + DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " body: " << GetErrcodeName(_rc) << " (" << (kCancelError.equals(_L, 1) ? "cancelled" : luaG_typename(_L, 1)) << ")" << std::endl); // Call finalizers, if the script has set them up. // LuaError const _rc2{ run_finalizers(_L, lane_->errorTraceLevel, _rc) }; - DEBUGSPEW_CODE(DebugSpew(_U) << "Lane " << _L << " finalizer: " << GetErrcodeName(_rc2) << std::endl); + DEBUGSPEW_CODE(DebugSpew(lane_->U) << "Lane " << _L << " finalizer: " << GetErrcodeName(_rc2) << std::endl); if (_rc2 != LuaError::OK) { // Error within a finalizer! // the finalizer generated an error, and left its own error message [and stack trace] on the stack _rc = _rc2; // we're overruling the earlier script error or normal return @@ -716,21 +722,16 @@ static void lane_main(Lane* lane_) // we destroy our jthread member from inside the thread body, so we have to detach so that we don't try to join, as this doesn't seem a good idea lane_->thread.detach(); delete lane_; - lane_ = nullptr; + return; } } - if (lane_) { - // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them - Lane::Status const _st{ (_rc == LuaError::OK) ? Lane::Done : kCancelError.equals(_L, 1) ? Lane::Cancelled : Lane::Error }; - - { - // 'doneMutex' protects the -> Done|Error|Cancelled state change - std::lock_guard _guard{ lane_->doneMutex }; - lane_->status = _st; - lane_->doneCondVar.notify_one(); // wake up master (while 'lane_->doneMutex' is on) - } - } + // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them + Lane::Status const _st{ (_rc == LuaError::OK) ? Lane::Done : kCancelError.equals(_L, 1) ? Lane::Cancelled : Lane::Error }; + // 'doneMutex' protects the -> Done|Error|Cancelled state change + std::lock_guard _guard{ lane_->doneMutex }; + lane_->status = _st; + lane_->doneCondVar.notify_one(); // wake up master (while 'lane_->doneMutex' is on) } // ################################################################################################# diff --git a/src/lane.h b/src/lane.h index eb70153..836b1b3 100644 --- a/src/lane.h +++ b/src/lane.h @@ -69,8 +69,12 @@ class Lane // the thread std::jthread thread; +#ifndef __PROSPERO__ // a latch to wait for the lua_State to be ready std::latch ready{ 1 }; +#else // __PROSPERO__ + std::atomic_flag ready{}; +#endif // __PROSPERO__ // to wait for stop requests through thread's stop_source std::mutex doneMutex; std::condition_variable doneCondVar; // use condition_variable_any if waiting for a stop_token diff --git a/src/lanes.cpp b/src/lanes.cpp index 8b693c3..7196b72 100644 --- a/src/lanes.cpp +++ b/src/lanes.cpp @@ -308,7 +308,11 @@ LUAG_FUNC(lane_new) lane->status = Lane::Running; } // unblock the thread so that it can terminate gracefully +#ifndef __PROSPERO__ lane->ready.count_down(); +#else // __PROSPERO__ + lane->ready.test_and_set(); +#endif // __PROSPERO__ } } @@ -366,7 +370,12 @@ LUAG_FUNC(lane_new) void success() { prepareUserData(); + // unblock the thread so that it can terminate gracefully +#ifndef __PROSPERO__ lane->ready.count_down(); +#else // __PROSPERO__ + lane->ready.test_and_set(); +#endif // __PROSPERO__ lane = nullptr; } } _onExit{ L_, _lane}; -- cgit v1.2.3-55-g6feb