aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp55
1 files changed, 29 insertions, 26 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 3d0c70d..2a5ebfd 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -162,7 +162,7 @@ static void securize_debug_threadname(lua_State* L, Lane* lane_)
162} 162}
163 163
164#if ERROR_FULL_STACK 164#if ERROR_FULL_STACK
165static int lane_error(lua_State* L); 165[[nodiscard]] static int lane_error(lua_State* L);
166// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/ 166// crc64/we of string "STACKTRACE_REGKEY" generated at http://www.nitrxgen.net/hashgen/
167static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full }; 167static constexpr UniqueKey STACKTRACE_REGKEY{ 0x534af7d3226a429full };
168#endif // ERROR_FULL_STACK 168#endif // ERROR_FULL_STACK
@@ -188,7 +188,7 @@ static constexpr UniqueKey FINALIZER_REGKEY{ 0x188fccb8bf348e09ull };
188* Returns: true if a table was pushed 188* Returns: true if a table was pushed
189* false if no table found, not created, and nothing pushed 189* false if no table found, not created, and nothing pushed
190*/ 190*/
191static bool push_registry_table( lua_State* L, UniqueKey key, bool create) 191[[nodiscard]] static bool push_registry_table(lua_State* L, UniqueKey key, bool create)
192{ 192{
193 STACK_GROW(L, 3); 193 STACK_GROW(L, 3);
194 STACK_CHECK_START_REL(L, 0); 194 STACK_CHECK_START_REL(L, 0);
@@ -237,7 +237,7 @@ static void tracking_add(Lane* lane_)
237/* 237/*
238 * A free-running lane has ended; remove it from tracking chain 238 * A free-running lane has ended; remove it from tracking chain
239 */ 239 */
240static bool tracking_remove(Lane* lane_) 240[[nodiscard]] static bool tracking_remove(Lane* lane_)
241{ 241{
242 bool found{ false }; 242 bool found{ false };
243 std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs }; 243 std::lock_guard<std::mutex> guard{ lane_->U->tracking_cs };
@@ -277,7 +277,7 @@ Lane::~Lane()
277 if (U->tracking_first != nullptr) 277 if (U->tracking_first != nullptr)
278 { 278 {
279 // Lane was cleaned up, no need to handle at process termination 279 // Lane was cleaned up, no need to handle at process termination
280 tracking_remove(this); 280 std::ignore = tracking_remove(this);
281 } 281 }
282#endif // HAVE_LANE_TRACKING() 282#endif // HAVE_LANE_TRACKING()
283} 283}
@@ -300,10 +300,10 @@ LUAG_FUNC( set_finalizer)
300{ 300{
301 luaL_argcheck(L, lua_isfunction(L, 1), 1, "finalizer should be a function"); 301 luaL_argcheck(L, lua_isfunction(L, 1), 1, "finalizer should be a function");
302 luaL_argcheck(L, lua_gettop( L) == 1, 1, "too many arguments"); 302 luaL_argcheck(L, lua_gettop( L) == 1, 1, "too many arguments");
303 // Get the current finalizer table (if any) 303 // Get the current finalizer table (if any), create one if it doesn't exist
304 push_registry_table(L, FINALIZER_REGKEY, true /*do create if none*/); // finalizer {finalisers} 304 std::ignore = push_registry_table(L, FINALIZER_REGKEY, true); // finalizer {finalisers}
305 STACK_GROW(L, 2); 305 STACK_GROW(L, 2);
306 lua_pushinteger(L, lua_rawlen(L, -1) + 1); // finalizer {finalisers} idx 306 lua_pushinteger(L, lua_rawlen(L, -1) + 1); // finalizer {finalisers} idx
307 lua_pushvalue(L, 1); // finalizer {finalisers} idx finalizer 307 lua_pushvalue(L, 1); // finalizer {finalisers} idx finalizer
308 lua_rawset(L, -3); // finalizer {finalisers} 308 lua_rawset(L, -3); // finalizer {finalisers}
309 lua_pop(L, 2); // 309 lua_pop(L, 2); //
@@ -326,7 +326,7 @@ LUAG_FUNC( set_finalizer)
326// 326//
327static void push_stack_trace( lua_State* L, int rc_, int stk_base_); 327static void push_stack_trace( lua_State* L, int rc_, int stk_base_);
328 328
329static int run_finalizers( lua_State* L, int lua_rc) 329[[nodiscard]] static int run_finalizers(lua_State* L, int lua_rc)
330{ 330{
331 int finalizers_index; 331 int finalizers_index;
332 int n; 332 int n;
@@ -430,7 +430,7 @@ static void selfdestruct_add(Lane* lane_)
430/* 430/*
431 * A free-running lane has ended; remove it from selfdestruct chain 431 * A free-running lane has ended; remove it from selfdestruct chain
432 */ 432 */
433static bool selfdestruct_remove(Lane* lane_) 433[[nodiscard]] static bool selfdestruct_remove(Lane* lane_)
434{ 434{
435 bool found{ false }; 435 bool found{ false };
436 std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs }; 436 std::lock_guard<std::mutex> guard{ lane_->U->selfdestruct_cs };
@@ -465,7 +465,7 @@ static bool selfdestruct_remove(Lane* lane_)
465/* 465/*
466* Process end; cancel any still free-running threads 466* Process end; cancel any still free-running threads
467*/ 467*/
468static int universe_gc( lua_State* L) 468[[nodiscard]] static int universe_gc(lua_State* L)
469{ 469{
470 Universe* const U{ lua_tofulluserdata<Universe>(L, 1) }; 470 Universe* const U{ lua_tofulluserdata<Universe>(L, 1) };
471 lua_Duration const shutdown_timeout{ lua_tonumber(L, lua_upvalueindex(1)) }; 471 lua_Duration const shutdown_timeout{ lua_tonumber(L, lua_upvalueindex(1)) };
@@ -638,7 +638,7 @@ LUAG_FUNC( set_error_reporting)
638 return 0; 638 return 0;
639} 639}
640 640
641static int lane_error(lua_State* L) 641[[nodiscard]] static int lane_error(lua_State* L)
642{ 642{
643 // error message (any type) 643 // error message (any type)
644 STACK_CHECK_START_ABS(L, 1); // some_error 644 STACK_CHECK_START_ABS(L, 1); // some_error
@@ -1176,7 +1176,10 @@ LUAG_FUNC(lane_new)
1176 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode 1176 if (lua_pcall( L2, 1, 1, 0) != LUA_OK) // ret/errcode
1177 { 1177 {
1178 // propagate error to main state if any 1178 // propagate error to main state if any
1179 luaG_inter_move(U, Source{ L2 }, Dest{ L }, 1, LookupMode::LaneBody); // func libs priority globals package required gc_cb [... args ...] n "modname" error 1179 std::ignore = luaG_inter_move(U
1180 , Source{ L2 }, Dest{ L }
1181 , 1, LookupMode::LaneBody
1182 ); // func libs priority globals package required gc_cb [... args ...] n "modname" error
1180 raise_lua_error(L); 1183 raise_lua_error(L);
1181 } 1184 }
1182 // after requiring the module, register the functions it exported in our name<->function database 1185 // after requiring the module, register the functions it exported in our name<->function database
@@ -1209,7 +1212,7 @@ LUAG_FUNC(lane_new)
1209 lua_pushglobaltable(L2); // _G 1212 lua_pushglobaltable(L2); // _G
1210 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v 1213 while( lua_next(L, globals_idx)) // func libs priority globals package required gc_cb [... args ...] k v
1211 { 1214 {
1212 luaG_inter_copy(U, Source{ L }, Dest{ L2 }, 2, LookupMode::LaneBody); // _G k v 1215 std::ignore = luaG_inter_copy(U, Source{ L }, Dest{ L2 }, 2, LookupMode::LaneBody); // _G k v
1213 // assign it in L2's globals table 1216 // assign it in L2's globals table
1214 lua_rawset(L2, -3); // _G 1217 lua_rawset(L2, -3); // _G
1215 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k 1218 lua_pop(L, 1); // func libs priority globals package required gc_cb [... args ...] k
@@ -1290,7 +1293,7 @@ LUAG_FUNC(lane_new)
1290// and the issue of canceling/killing threads at gc is not very nice, either 1293// and the issue of canceling/killing threads at gc is not very nice, either
1291// (would easily cause waits at gc cycle, which we don't want). 1294// (would easily cause waits at gc cycle, which we don't want).
1292// 1295//
1293static int lane_gc(lua_State* L) 1296[[nodiscard]] static int lane_gc(lua_State* L)
1294{ 1297{
1295 bool have_gc_cb{ false }; 1298 bool have_gc_cb{ false };
1296 Lane* const lane{ lua_toLane(L, 1) }; // ud 1299 Lane* const lane{ lua_toLane(L, 1) }; // ud
@@ -1356,7 +1359,7 @@ static int lane_gc(lua_State* L)
1356// / "error" finished at an error, error value is there 1359// / "error" finished at an error, error value is there
1357// / "cancelled" execution cancelled by M (state gone) 1360// / "cancelled" execution cancelled by M (state gone)
1358// 1361//
1359static char const * thread_status_string(Lane* lane_) 1362[[nodiscard]] static char const* thread_status_string(Lane* lane_)
1360{ 1363{
1361 Lane::Status const st{ lane_->m_status }; // read just once (volatile) 1364 Lane::Status const st{ lane_->m_status }; // read just once (volatile)
1362 char const* str = 1365 char const* str =
@@ -1624,20 +1627,20 @@ LUAG_FUNC(threads)
1624 { 1627 {
1625 Lane* lane{ U->tracking_first }; 1628 Lane* lane{ U->tracking_first };
1626 int index = 0; 1629 int index = 0;
1627 lua_newtable(L); // {} 1630 lua_newtable(L); // {}
1628 while (lane != TRACKING_END) 1631 while (lane != TRACKING_END)
1629 { 1632 {
1630 // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other 1633 // insert a { name, status } tuple, so that several lanes with the same name can't clobber each other
1631 lua_newtable(L); // {} {} 1634 lua_newtable(L); // {} {}
1632 lua_pushstring(L, lane->debug_name); // {} {} "name" 1635 lua_pushstring(L, lane->debug_name); // {} {} "name"
1633 lua_setfield(L, -2, "name"); // {} {} 1636 lua_setfield(L, -2, "name"); // {} {}
1634 push_thread_status(L, lane); // {} {} "status" 1637 std::ignore = push_thread_status(L, lane); // {} {} "status"
1635 lua_setfield(L, -2, "status"); // {} {} 1638 lua_setfield(L, -2, "status"); // {} {}
1636 lua_rawseti(L, -2, ++index); // {} 1639 lua_rawseti(L, -2, ++index); // {}
1637 lane = lane->tracking_next; 1640 lane = lane->tracking_next;
1638 } 1641 }
1639 } 1642 }
1640 return lua_gettop(L) - top; // 0 or 1 1643 return lua_gettop(L) - top; // 0 or 1
1641} 1644}
1642#endif // HAVE_LANE_TRACKING() 1645#endif // HAVE_LANE_TRACKING()
1643 1646
@@ -1723,7 +1726,7 @@ LUAG_FUNC(wakeup_conv)
1723 */ 1726 */
1724 1727
1725extern int LG_linda(lua_State* L); 1728extern int LG_linda(lua_State* L);
1726static const struct luaL_Reg lanes_functions[] = 1729static struct luaL_Reg const lanes_functions[] =
1727{ 1730{
1728 { "linda", LG_linda }, 1731 { "linda", LG_linda },
1729 { "now_secs", LG_now_secs }, 1732 { "now_secs", LG_now_secs },
@@ -2022,9 +2025,9 @@ LANES_API int luaopen_lanes_core( lua_State* L)
2022 return 1; 2025 return 1;
2023} 2026}
2024 2027
2025static int default_luaopen_lanes( lua_State* L) 2028[[nodiscard]] static int default_luaopen_lanes(lua_State* L)
2026{ 2029{
2027 int rc = luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0); 2030 int const rc{ luaL_loadfile(L, "lanes.lua") || lua_pcall(L, 0, 1, 0) };
2028 if (rc != LUA_OK) 2031 if (rc != LUA_OK)
2029 { 2032 {
2030 return luaL_error(L, "failed to initialize embedded Lanes"); 2033 return luaL_error(L, "failed to initialize embedded Lanes");