aboutsummaryrefslogtreecommitdiff
path: root/src/cancel.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/cancel.hpp')
-rw-r--r--src/cancel.hpp60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/cancel.hpp b/src/cancel.hpp
new file mode 100644
index 0000000..7230169
--- /dev/null
+++ b/src/cancel.hpp
@@ -0,0 +1,60 @@
1#pragma once
2
3#include "macros_and_utils.hpp"
4#include "uniquekey.hpp"
5
6// #################################################################################################
7
8// Lane cancellation request modes
9enum class CancelRequest
10{
11 None, // no pending cancel request
12 // TODO: add a Wake mode: user wants to wake the waiting lindas (in effect resulting in a timeout before the initial operation duration)
13 Soft, // user wants the lane to cancel itself manually on cancel_test()
14 Hard // user wants the lane to be interrupted (meaning code won't return from those functions) from inside linda:send/receive calls
15};
16
17enum class CancelResult
18{
19 Timeout,
20 Cancelled
21};
22
23enum class CancelOp
24{
25 Invalid = -2,
26 Hard = -1,
27 Soft = 0,
28 MaskCall = LUA_MASKCALL,
29 MaskRet = LUA_MASKRET,
30 MaskLine = LUA_MASKLINE,
31 MaskCount = LUA_MASKCOUNT,
32 MaskAll = LUA_MASKCALL | LUA_MASKRET | LUA_MASKLINE | LUA_MASKCOUNT
33};
34
35inline auto operator<=>(CancelOp const a_, CancelOp const b_)
36{
37 return static_cast<std::underlying_type_t<CancelOp>>(a_) <=> static_cast<std::underlying_type_t<CancelOp>>(b_);
38}
39
40// xxh64 of string "kCancelError" generated at https://www.pelock.com/products/hash-calculator
41static constexpr UniqueKey kCancelError{ 0x0630345FEF912746ull, "lanes.cancel_error" }; // 'raise_cancel_error' sentinel
42
43// #################################################################################################
44
45[[nodiscard]] CancelRequest CheckCancelRequest(lua_State* L_);
46[[nodiscard]] CancelOp WhichCancelOp(std::string_view const& opString_);
47
48// #################################################################################################
49
50[[noreturn]] static inline void raise_cancel_error(lua_State* const L_)
51{
52 STACK_GROW(L_, 1);
53 kCancelError.pushKey(L_); // special error value
54 raise_lua_error(L_);
55}
56
57// #################################################################################################
58
59LUAG_FUNC(cancel_test);
60LUAG_FUNC(lane_cancel);