aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cancel.cpp4
-rw-r--r--src/cancel.h17
-rw-r--r--src/lane.cpp17
3 files changed, 19 insertions, 19 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp
index a62fcdf..4f04857 100644
--- a/src/cancel.cpp
+++ b/src/cancel.cpp
@@ -50,7 +50,7 @@ THE SOFTWARE.
50 * Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'raise_cancel_error()' called, 50 * Returns CANCEL_SOFT/HARD if any locks are to be exited, and 'raise_cancel_error()' called,
51 * to make execution of the lane end. 51 * to make execution of the lane end.
52 */ 52 */
53[[nodiscard]] CancelRequest cancel_test(lua_State* const L_) 53[[nodiscard]] CancelRequest CheckCancelRequest(lua_State* const L_)
54{ 54{
55 Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) }; 55 Lane* const _lane{ kLanePointerRegKey.readLightUserDataValue<Lane>(L_) };
56 // 'lane' is nullptr for the original main state (and no-one can cancel that) 56 // 'lane' is nullptr for the original main state (and no-one can cancel that)
@@ -129,7 +129,7 @@ CancelOp WhichCancelOp(std::string_view const& opString_)
129// 129//
130LUAG_FUNC(cancel_test) 130LUAG_FUNC(cancel_test)
131{ 131{
132 CancelRequest _test{ cancel_test(L_) }; 132 CancelRequest _test{ CheckCancelRequest(L_) };
133 lua_pushboolean(L_, _test != CancelRequest::None); 133 lua_pushboolean(L_, _test != CancelRequest::None);
134 return 1; 134 return 1;
135} 135}
diff --git a/src/cancel.h b/src/cancel.h
index 0e4e6d4..93fae4d 100644
--- a/src/cancel.h
+++ b/src/cancel.h
@@ -5,11 +5,7 @@
5 5
6// ################################################################################################# 6// #################################################################################################
7 7
8class Lane; // forward 8// Lane cancellation request modes
9
10/*
11 * Lane cancellation request modes
12 */
13enum class CancelRequest 9enum class CancelRequest
14{ 10{
15 None, // no pending cancel request 11 None, // no pending cancel request
@@ -38,10 +34,14 @@ enum class CancelOp
38// xxh64 of string "kCancelError" generated at https://www.pelock.com/products/hash-calculator 34// xxh64 of string "kCancelError" generated at https://www.pelock.com/products/hash-calculator
39static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel 35static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel
40 36
41[[nodiscard]] CancelRequest cancel_test(lua_State* L_); 37// #################################################################################################
38
39[[nodiscard]] CancelRequest CheckCancelRequest(lua_State* L_);
42[[nodiscard]] CancelOp WhichCancelOp(std::string_view const& opString_); 40[[nodiscard]] CancelOp WhichCancelOp(std::string_view const& opString_);
43 41
44[[noreturn]] static inline void raise_cancel_error(lua_State* L_) 42// #################################################################################################
43
44[[noreturn]] static inline void raise_cancel_error(lua_State* const L_)
45{ 45{
46 STACK_GROW(L_, 1); 46 STACK_GROW(L_, 1);
47 kCancelError.pushKey(L_); // special error value 47 kCancelError.pushKey(L_); // special error value
@@ -49,9 +49,6 @@ static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_er
49} 49}
50 50
51// ################################################################################################# 51// #################################################################################################
52// #################################################################################################
53 52
54LUAG_FUNC(cancel_test); 53LUAG_FUNC(cancel_test);
55LUAG_FUNC(thread_cancel); 54LUAG_FUNC(thread_cancel);
56
57// #################################################################################################
diff --git a/src/lane.cpp b/src/lane.cpp
index 15499fe..9751aeb 100644
--- a/src/lane.cpp
+++ b/src/lane.cpp
@@ -832,13 +832,16 @@ Lane::~Lane()
832 832
833// ################################################################################################# 833// #################################################################################################
834 834
835CancelResult Lane::cancel(CancelOp op_, int hookCount_, std::chrono::time_point<std::chrono::steady_clock> until_, bool wakeLane_) 835CancelResult Lane::cancel(CancelOp const op_, int const hookCount_, std::chrono::time_point<std::chrono::steady_clock> const until_, bool const wakeLane_)
836{ 836{
837 auto _cancel_hook = +[](lua_State* const L_, [[maybe_unused]] lua_Debug* const ar_) { 837 // this is a hook installed with lua_sethook: can't capture anything to be convertible to lua_Hook
838 DEBUGSPEW_CODE(DebugSpew(nullptr) << "cancel_hook" << std::endl); 838 static constexpr lua_Hook _cancelHook{
839 if (cancel_test(L_) != CancelRequest::None) { 839 +[](lua_State* const L_, [[maybe_unused]] lua_Debug* const ar_) {
840 lua_sethook(L_, nullptr, 0, 0); 840 DEBUGSPEW_CODE(DebugSpew(nullptr) << "cancel_hook" << std::endl);
841 raise_cancel_error(L_); 841 if (CheckCancelRequest(L_) != CancelRequest::None) {
842 lua_sethook(L_, nullptr, 0, 0);
843 raise_cancel_error(L_);
844 }
842 } 845 }
843 }; 846 };
844 847
@@ -854,7 +857,7 @@ CancelResult Lane::cancel(CancelOp op_, int hookCount_, std::chrono::time_point<
854 if (op_ == CancelOp::Soft) { 857 if (op_ == CancelOp::Soft) {
855 return cancelSoft(until_, wakeLane_); 858 return cancelSoft(until_, wakeLane_);
856 } else if (static_cast<int>(op_) > static_cast<int>(CancelOp::Soft)) { 859 } else if (static_cast<int>(op_) > static_cast<int>(CancelOp::Soft)) {
857 lua_sethook(L, _cancel_hook, static_cast<int>(op_), hookCount_); 860 lua_sethook(L, _cancelHook, static_cast<int>(op_), hookCount_);
858 } 861 }
859 862
860 return cancelHard(until_, wakeLane_); 863 return cancelHard(until_, wakeLane_);