diff options
Diffstat (limited to 'src/cancel.cpp')
-rw-r--r-- | src/cancel.cpp | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index b3e52b6..fe1f3e6 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -39,8 +39,8 @@ THE SOFTWARE. | |||
39 | #include "threading.h" | 39 | #include "threading.h" |
40 | #include "tools.h" | 40 | #include "tools.h" |
41 | 41 | ||
42 | // ################################################################################################ | 42 | // ################################################################################################# |
43 | // ################################################################################################ | 43 | // ################################################################################################# |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * Check if the thread in question ('L') has been signalled for cancel. | 46 | * Check if the thread in question ('L') has been signalled for cancel. |
@@ -58,7 +58,7 @@ THE SOFTWARE. | |||
58 | return lane ? lane->cancel_request : CancelRequest::None; | 58 | return lane ? lane->cancel_request : CancelRequest::None; |
59 | } | 59 | } |
60 | 60 | ||
61 | // ################################################################################################ | 61 | // ################################################################################################# |
62 | 62 | ||
63 | //--- | 63 | //--- |
64 | // bool = cancel_test() | 64 | // bool = cancel_test() |
@@ -66,15 +66,15 @@ THE SOFTWARE. | |||
66 | // Available inside the global namespace of lanes | 66 | // Available inside the global namespace of lanes |
67 | // returns a boolean saying if a cancel request is pending | 67 | // returns a boolean saying if a cancel request is pending |
68 | // | 68 | // |
69 | LUAG_FUNC( cancel_test) | 69 | LUAG_FUNC(cancel_test) |
70 | { | 70 | { |
71 | CancelRequest test{ cancel_test(L) }; | 71 | CancelRequest test{ cancel_test(L) }; |
72 | lua_pushboolean(L, test != CancelRequest::None); | 72 | lua_pushboolean(L, test != CancelRequest::None); |
73 | return 1; | 73 | return 1; |
74 | } | 74 | } |
75 | 75 | ||
76 | // ################################################################################################ | 76 | // ################################################################################################# |
77 | // ################################################################################################ | 77 | // ################################################################################################# |
78 | 78 | ||
79 | [[nodiscard]] static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar) | 79 | [[nodiscard]] static void cancel_hook(lua_State* L, [[maybe_unused]] lua_Debug* ar) |
80 | { | 80 | { |
@@ -86,8 +86,8 @@ LUAG_FUNC( cancel_test) | |||
86 | } | 86 | } |
87 | } | 87 | } |
88 | 88 | ||
89 | // ################################################################################################ | 89 | // ################################################################################################# |
90 | // ################################################################################################ | 90 | // ################################################################################################# |
91 | 91 | ||
92 | //--- | 92 | //--- |
93 | // = thread_cancel( lane_ud [,timeout_secs=0.0] [,wake_lindas_bool=false] ) | 93 | // = thread_cancel( lane_ud [,timeout_secs=0.0] [,wake_lindas_bool=false] ) |
@@ -106,7 +106,7 @@ LUAG_FUNC( cancel_test) | |||
106 | // false if the cancellation timed out, or a kill was needed. | 106 | // false if the cancellation timed out, or a kill was needed. |
107 | // | 107 | // |
108 | 108 | ||
109 | // ################################################################################################ | 109 | // ################################################################################################# |
110 | 110 | ||
111 | [[nodiscard]] static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool wake_lane_) | 111 | [[nodiscard]] static CancelResult thread_cancel_soft(Lane* lane_, lua_Duration duration_, bool wake_lane_) |
112 | { | 112 | { |
@@ -124,7 +124,7 @@ LUAG_FUNC( cancel_test) | |||
124 | return lane_->waitForCompletion(duration_) ? CancelResult::Cancelled : CancelResult::Timeout; | 124 | return lane_->waitForCompletion(duration_) ? CancelResult::Cancelled : CancelResult::Timeout; |
125 | } | 125 | } |
126 | 126 | ||
127 | // ################################################################################################ | 127 | // ################################################################################################# |
128 | 128 | ||
129 | [[nodiscard]] static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool wake_lane_) | 129 | [[nodiscard]] static CancelResult thread_cancel_hard(Lane* lane_, lua_Duration duration_, bool wake_lane_) |
130 | { | 130 | { |
@@ -143,7 +143,7 @@ LUAG_FUNC( cancel_test) | |||
143 | return result; | 143 | return result; |
144 | } | 144 | } |
145 | 145 | ||
146 | // ################################################################################################ | 146 | // ################################################################################################# |
147 | 147 | ||
148 | CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration duration_, bool wake_lane_) | 148 | CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Duration duration_, bool wake_lane_) |
149 | { | 149 | { |
@@ -169,8 +169,8 @@ CancelResult thread_cancel(Lane* lane_, CancelOp op_, int hook_count_, lua_Durat | |||
169 | return thread_cancel_hard(lane_, duration_, wake_lane_); | 169 | return thread_cancel_hard(lane_, duration_, wake_lane_); |
170 | } | 170 | } |
171 | 171 | ||
172 | // ################################################################################################ | 172 | // ################################################################################################# |
173 | // ################################################################################################ | 173 | // ################################################################################################# |
174 | 174 | ||
175 | CancelOp which_cancel_op(char const* op_string_) | 175 | CancelOp which_cancel_op(char const* op_string_) |
176 | { | 176 | { |
@@ -202,7 +202,7 @@ CancelOp which_cancel_op(char const* op_string_) | |||
202 | return op; | 202 | return op; |
203 | } | 203 | } |
204 | 204 | ||
205 | // ################################################################################################ | 205 | // ################################################################################################# |
206 | 206 | ||
207 | [[nodiscard]] static CancelOp which_cancel_op(lua_State* L, int idx_) | 207 | [[nodiscard]] static CancelOp which_cancel_op(lua_State* L, int idx_) |
208 | { | 208 | { |
@@ -220,12 +220,12 @@ CancelOp which_cancel_op(char const* op_string_) | |||
220 | return CancelOp::Hard; | 220 | return CancelOp::Hard; |
221 | } | 221 | } |
222 | 222 | ||
223 | // ################################################################################################ | 223 | // ################################################################################################# |
224 | 224 | ||
225 | // bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, wake_lindas]) | 225 | // bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, wake_lindas]) |
226 | LUAG_FUNC(thread_cancel) | 226 | LUAG_FUNC(thread_cancel) |
227 | { | 227 | { |
228 | Lane* const lane{ lua_toLane(L, 1) }; | 228 | Lane* const lane{ ToLane(L, 1) }; |
229 | CancelOp const op{ which_cancel_op(L, 2) }; // this removes the op string from the stack | 229 | CancelOp const op{ which_cancel_op(L, 2) }; // this removes the op string from the stack |
230 | 230 | ||
231 | int hook_count{ 0 }; | 231 | int hook_count{ 0 }; |
@@ -235,7 +235,7 @@ LUAG_FUNC(thread_cancel) | |||
235 | lua_remove(L, 2); // argument is processed, remove it | 235 | lua_remove(L, 2); // argument is processed, remove it |
236 | if (hook_count < 1) | 236 | if (hook_count < 1) |
237 | { | 237 | { |
238 | return luaL_error(L, "hook count cannot be < 1"); | 238 | return luaL_error(L, "hook count cannot be < 1"); // doesn't return |
239 | } | 239 | } |
240 | } | 240 | } |
241 | 241 | ||
@@ -246,7 +246,7 @@ LUAG_FUNC(thread_cancel) | |||
246 | lua_remove(L, 2); // argument is processed, remove it | 246 | lua_remove(L, 2); // argument is processed, remove it |
247 | if (wait_timeout.count() < 0.0) | 247 | if (wait_timeout.count() < 0.0) |
248 | { | 248 | { |
249 | return luaL_error(L, "cancel timeout cannot be < 0"); | 249 | return luaL_error(L, "cancel timeout cannot be < 0"); // doesn't return |
250 | } | 250 | } |
251 | } | 251 | } |
252 | // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired | 252 | // we wake by default in "hard" mode (remember that hook is hard too), but this can be turned off if desired |
@@ -255,7 +255,7 @@ LUAG_FUNC(thread_cancel) | |||
255 | { | 255 | { |
256 | if (!lua_isboolean(L, 2)) | 256 | if (!lua_isboolean(L, 2)) |
257 | { | 257 | { |
258 | return luaL_error(L, "wake_lindas parameter is not a boolean"); | 258 | return luaL_error(L, "wake_lindas parameter is not a boolean"); // doesn't return |
259 | } | 259 | } |
260 | wake_lane = lua_toboolean(L, 2); | 260 | wake_lane = lua_toboolean(L, 2); |
261 | lua_remove(L, 2); // argument is processed, remove it | 261 | lua_remove(L, 2); // argument is processed, remove it |