diff options
-rw-r--r-- | src/cancel.cpp | 2 | ||||
-rw-r--r-- | src/deep.h | 3 | ||||
-rw-r--r-- | src/lanes.cpp | 34 | ||||
-rw-r--r-- | src/lanes_private.h | 3 |
4 files changed, 20 insertions, 22 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index a7dc0ec..5bcf79d 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -274,7 +274,7 @@ LUAG_FUNC(thread_cancel) | |||
274 | 274 | ||
275 | case CancelResult::Cancelled: | 275 | case CancelResult::Cancelled: |
276 | lua_pushboolean(L, 1); // true | 276 | lua_pushboolean(L, 1); // true |
277 | push_thread_status(L, lane); // true status | 277 | lane->pushThreadStatus(L); // true status |
278 | break; | 278 | break; |
279 | } | 279 | } |
280 | STACK_CHECK(L, 2); | 280 | STACK_CHECK(L, 2); |
@@ -82,6 +82,3 @@ class DeepFactory | |||
82 | static void DeleteDeepObject(lua_State* L, DeepPrelude* o_); | 82 | static void DeleteDeepObject(lua_State* L, DeepPrelude* o_); |
83 | static char const* PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_); | 83 | static char const* PushDeepProxy(Dest L, DeepPrelude* prelude, int nuv_, LookupMode mode_); |
84 | }; | 84 | }; |
85 | |||
86 | //LANES_API [[nodiscard]] int luaG_newdeepuserdata(Dest L, DeepFactory& factory_, int nuv_); | ||
87 | //LANES_API [[nodiscard]] DeepPrelude* luaG_todeep(lua_State* L, DeepFactory &factory_, int index); | ||
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 | ||
1355 | void push_thread_status(lua_State* L, Lane* lane_) | 1357 | void 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; |
diff --git a/src/lanes_private.h b/src/lanes_private.h index 807359f..c35d618 100644 --- a/src/lanes_private.h +++ b/src/lanes_private.h | |||
@@ -89,6 +89,7 @@ class Lane | |||
89 | 89 | ||
90 | [[nodiscard]] bool waitForCompletion(lua_Duration duration_); | 90 | [[nodiscard]] bool waitForCompletion(lua_Duration duration_); |
91 | void startThread(int priority_); | 91 | void startThread(int priority_); |
92 | void pushThreadStatus(lua_State* L_); | ||
92 | }; | 93 | }; |
93 | 94 | ||
94 | // xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator | 95 | // xxh64 of string "LANE_POINTER_REGKEY" generated at https://www.pelock.com/products/hash-calculator |
@@ -102,5 +103,3 @@ static constexpr RegistryUniqueKey LANE_POINTER_REGKEY{ 0xB3022205633743BCull }; | |||
102 | { | 103 | { |
103 | return *(static_cast<Lane**>(luaL_checkudata(L, i_, "Lane"))); | 104 | return *(static_cast<Lane**>(luaL_checkudata(L, i_, "Lane"))); |
104 | } | 105 | } |
105 | |||
106 | void push_thread_status(lua_State* L, Lane* lane_); | ||