aboutsummaryrefslogtreecommitdiff
path: root/src/lanes.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/lanes.cpp')
-rw-r--r--src/lanes.cpp34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index 1f938d4..880c150 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -1337,27 +1337,29 @@ LUAG_FUNC(lane_new)
1337// / "error" finished at an error, error value is there 1337// / "error" finished at an error, error value is there
1338// / "cancelled" execution cancelled by M (state gone) 1338// / "cancelled" execution cancelled by M (state gone)
1339// 1339//
1340[[nodiscard]] static char const* thread_status_string(Lane* lane_) 1340[[nodiscard]] static char const* thread_status_string(Lane::Status status_)
1341{ 1341{
1342 Lane::Status const st{ lane_->m_status }; // read just once (volatile) 1342 char const* const str
1343 char const* str = 1343 {
1344 (st == Lane::Pending) ? "pending" : 1344 (status_ == Lane::Pending) ? "pending" :
1345 (st == Lane::Running) ? "running" : // like in 'co.status()' 1345 (status_ == Lane::Running) ? "running" : // like in 'co.status()'
1346 (st == Lane::Waiting) ? "waiting" : 1346 (status_ == Lane::Waiting) ? "waiting" :
1347 (st == Lane::Done) ? "done" : 1347 (status_ == Lane::Done) ? "done" :
1348 (st == Lane::Error) ? "error" : 1348 (status_ == Lane::Error) ? "error" :
1349 (st == Lane::Cancelled) ? "cancelled" : nullptr; 1349 (status_ == Lane::Cancelled) ? "cancelled" :
1350 nullptr
1351 };
1350 return str; 1352 return str;
1351} 1353}
1352 1354
1353// ################################################################################################# 1355// #################################################################################################
1354 1356
1355void push_thread_status(lua_State* L, Lane* lane_) 1357void Lane::pushThreadStatus(lua_State* L_)
1356{ 1358{
1357 char const* const str{ thread_status_string(lane_) }; 1359 char const* const str{ thread_status_string(m_status) };
1358 LUA_ASSERT(L, str); 1360 LUA_ASSERT(L_, str);
1359 1361
1360 lua_pushstring(L, str); 1362 lua_pushstring(L_, str);
1361} 1363}
1362 1364
1363// ################################################################################################# 1365// #################################################################################################
@@ -1495,7 +1497,7 @@ LUAG_FUNC(thread_index)
1495 // this is an internal error, we probably never get here 1497 // this is an internal error, we probably never get here
1496 lua_settop(L, 0); 1498 lua_settop(L, 0);
1497 lua_pushliteral(L, "Unexpected status: "); 1499 lua_pushliteral(L, "Unexpected status: ");
1498 lua_pushstring(L, thread_status_string(lane)); 1500 lua_pushstring(L, thread_status_string(lane->m_status));
1499 lua_concat(L, 2); 1501 lua_concat(L, 2);
1500 raise_lua_error(L); 1502 raise_lua_error(L);
1501 [[fallthrough]]; // fall through if we are killed, as we got nil, "killed" on the stack 1503 [[fallthrough]]; // fall through if we are killed, as we got nil, "killed" on the stack
@@ -1568,7 +1570,7 @@ LUAG_FUNC(thread_index)
1568 lua_settop(L, 2); // keep only our original arguments on the stack 1570 lua_settop(L, 2); // keep only our original arguments on the stack
1569 if (strcmp( keystr, "status") == 0) 1571 if (strcmp( keystr, "status") == 0)
1570 { 1572 {
1571 push_thread_status(L, lane); // push the string representing the status 1573 lane->pushThreadStatus(L); // push the string representing the status
1572 return 1; 1574 return 1;
1573 } 1575 }
1574 // return UD.metatable[key] 1576 // return UD.metatable[key]
@@ -1616,7 +1618,7 @@ LUAG_FUNC(threads)
1616 lua_newtable(L); // {} {} 1618 lua_newtable(L); // {} {}
1617 lua_pushstring(L, lane->debug_name); // {} {} "name" 1619 lua_pushstring(L, lane->debug_name); // {} {} "name"
1618 lua_setfield(L, -2, "name"); // {} {} 1620 lua_setfield(L, -2, "name"); // {} {}
1619 push_thread_status(L, lane); // {} {} "status" 1621 lane->pushThreadStatus(L); // {} {} "status"
1620 lua_setfield(L, -2, "status"); // {} {} 1622 lua_setfield(L, -2, "status"); // {} {}
1621 lua_rawseti(L, -2, ++index); // {} 1623 lua_rawseti(L, -2, ++index); // {}
1622 lane = lane->tracking_next; 1624 lane = lane->tracking_next;