aboutsummaryrefslogtreecommitdiff
path: root/src/lane.cpp
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2026-03-05 15:58:11 +0100
committerBenoit Germain <benoit.germain@ubisoft.com>2026-03-05 15:58:11 +0100
commita9f59c675749d870f6d902a11360ad8f3b6bbd58 (patch)
tree0dc66bf435b587927ed021e3a1c8e09b5be426d3 /src/lane.cpp
parent10eb2454a21e9b1f1bd675eed799cb89a7518fa8 (diff)
downloadlanes-a9f59c675749d870f6d902a11360ad8f3b6bbd58.tar.gz
lanes-a9f59c675749d870f6d902a11360ad8f3b6bbd58.tar.bz2
lanes-a9f59c675749d870f6d902a11360ad8f3b6bbd58.zip
Internal improvements
(1) replace RAII/destructor-based error handling in lane_new with lua_pcall (2) validate native thread priorities (3) improve unit test coverage for the latter
Diffstat (limited to 'src/lane.cpp')
-rw-r--r--src/lane.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lane.cpp b/src/lane.cpp
index b23ff78..952b337 100644
--- a/src/lane.cpp
+++ b/src/lane.cpp
@@ -775,6 +775,10 @@ static void lane_main(Lane* const lane_)
775 delete lane_; 775 delete lane_;
776 return; 776 return;
777 } 777 }
778 } else {
779 // some error occurred in lane_new and we don't have anything to do
780 lua_settop(_L, 0); // should already be the case, but I'm paranoid
781 kCancelError.pushKey(_L); // this is our return value, as if we were cancelled right from the start
778 } 782 }
779 783
780 // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them 784 // leave results (1..top) or error message + stack trace (1..2) on the stack - master will copy them
@@ -872,6 +876,13 @@ Lane::Lane(Universe* const U_, lua_State* const L_, ErrorTraceLevel const errorT
872, errorTraceLevel{ errorTraceLevel_ } 876, errorTraceLevel{ errorTraceLevel_ }
873{ 877{
874 STACK_CHECK_START_REL(S, 0); 878 STACK_CHECK_START_REL(S, 0);
879
880 // Store a pointer to ourselves in the lane's registry, for 'cancel_test()' (we do cancel tests at pending send/receive).
881 kLanePointerRegKey.setValue(S,
882 [lane = this](lua_State* L_) { lua_pushlightuserdata(L_, lane); } // S:
883 );
884 STACK_CHECK(S, 0);
885
875 assert(errorTraceLevel == ErrorTraceLevel::Minimal || errorTraceLevel == ErrorTraceLevel::Basic || errorTraceLevel == ErrorTraceLevel::Extended); 886 assert(errorTraceLevel == ErrorTraceLevel::Minimal || errorTraceLevel == ErrorTraceLevel::Basic || errorTraceLevel == ErrorTraceLevel::Extended);
876 kExtendedStackTraceRegKey.setValue(S, [yes = errorTraceLevel == ErrorTraceLevel::Extended ? 1 : 0](lua_State* L_) { lua_pushboolean(L_, yes); }); 887 kExtendedStackTraceRegKey.setValue(S, [yes = errorTraceLevel == ErrorTraceLevel::Extended ? 1 : 0](lua_State* L_) { lua_pushboolean(L_, yes); });
877 U->tracker.tracking_add(this); 888 U->tracker.tracking_add(this);
@@ -1228,6 +1239,21 @@ void Lane::securizeDebugName(lua_State* const L_)
1228} 1239}
1229 1240
1230// ################################################################################################# 1241// #################################################################################################
1242void Lane::signalReady(bool const canRun_)
1243{
1244 if (!canRun_) {
1245 std::lock_guard _guard{ doneMutex };
1246 // this will cause lane_main to skip actual running (because we are not Pending anymore)
1247 status.store(Lane::Running, std::memory_order_release);
1248 }
1249#ifndef __PROSPERO__
1250 ready.count_down();
1251#else // __PROSPERO__
1252 ready.test_and_set();
1253#endif // __PROSPERO__
1254}
1255
1256// #################################################################################################
1231 1257
1232void Lane::startThread(lua_State* const L_, int const priority_, NativePrioFlag native_) 1258void Lane::startThread(lua_State* const L_, int const priority_, NativePrioFlag native_)
1233{ 1259{