diff options
Diffstat (limited to 'src/cancel.cpp')
-rw-r--r-- | src/cancel.cpp | 49 |
1 files changed, 25 insertions, 24 deletions
diff --git a/src/cancel.cpp b/src/cancel.cpp index 07c316a..4667f07 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp | |||
@@ -189,7 +189,7 @@ CancelResult thread_cancel(lua_State* L, Lane* lane_, CancelOp op_, double secs_ | |||
189 | 189 | ||
190 | // signal the linda the wake up the thread so that it can react to the cancel query | 190 | // signal the linda the wake up the thread so that it can react to the cancel query |
191 | // let us hope we never land here with a pointer on a linda that has been destroyed... | 191 | // let us hope we never land here with a pointer on a linda that has been destroyed... |
192 | if (op_ == CO_Soft) | 192 | if (op_ == CancelOp::Soft) |
193 | { | 193 | { |
194 | return thread_cancel_soft(lane_, secs_, force_); | 194 | return thread_cancel_soft(lane_, secs_, force_); |
195 | } | 195 | } |
@@ -203,45 +203,46 @@ CancelResult thread_cancel(lua_State* L, Lane* lane_, CancelOp op_, double secs_ | |||
203 | // > 0: the mask | 203 | // > 0: the mask |
204 | // = 0: soft | 204 | // = 0: soft |
205 | // < 0: hard | 205 | // < 0: hard |
206 | static CancelOp which_op( lua_State* L, int idx_) | 206 | static CancelOp which_op(lua_State* L, int idx_) |
207 | { | 207 | { |
208 | if( lua_type( L, idx_) == LUA_TSTRING) | 208 | if (lua_type(L, idx_) == LUA_TSTRING) |
209 | { | 209 | { |
210 | CancelOp op = CO_Invalid; | 210 | CancelOp op{ CancelOp::Invalid }; |
211 | char const* str = lua_tostring( L, idx_); | 211 | char const* str = lua_tostring(L, idx_); |
212 | if( strcmp( str, "soft") == 0) | 212 | if (strcmp(str, "hard") == 0) |
213 | { | 213 | { |
214 | op = CO_Soft; | 214 | op = CancelOp::Hard; |
215 | } | 215 | } |
216 | else if( strcmp( str, "count") == 0) | 216 | else if (strcmp(str, "soft") == 0) |
217 | { | 217 | { |
218 | op = CO_Count; | 218 | op = CancelOp::Soft; |
219 | } | 219 | } |
220 | else if( strcmp( str, "line") == 0) | 220 | else if (strcmp(str, "call") == 0) |
221 | { | 221 | { |
222 | op = CO_Line; | 222 | op = CancelOp::MaskCall; |
223 | } | 223 | } |
224 | else if( strcmp( str, "call") == 0) | 224 | else if (strcmp(str, "ret") == 0) |
225 | { | 225 | { |
226 | op = CO_Call; | 226 | op = CancelOp::MaskRet; |
227 | } | 227 | } |
228 | else if( strcmp( str, "ret") == 0) | 228 | else if (strcmp(str, "line") == 0) |
229 | { | 229 | { |
230 | op = CO_Ret; | 230 | op = CancelOp::MaskLine; |
231 | } | 231 | } |
232 | else if( strcmp( str, "hard") == 0) | 232 | else if (strcmp(str, "count") == 0) |
233 | { | 233 | { |
234 | op = CO_Hard; | 234 | op = CancelOp::MaskCount; |
235 | } | 235 | } |
236 | lua_remove( L, idx_); // argument is processed, remove it | 236 | lua_remove(L, idx_); // argument is processed, remove it |
237 | if( op == CO_Invalid) | 237 | if (op == CancelOp::Invalid) |
238 | { | 238 | { |
239 | std::ignore = luaL_error( L, "invalid hook option %s", str); | 239 | std::ignore = luaL_error(L, "invalid hook option %s", str); |
240 | } | 240 | } |
241 | return op; | 241 | return op; |
242 | } | 242 | } |
243 | return CO_Hard; | 243 | return CancelOp::Hard; |
244 | } | 244 | } |
245 | |||
245 | // ################################################################################################ | 246 | // ################################################################################################ |
246 | 247 | ||
247 | // bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, force [, forcekill_timeout]]) | 248 | // bool[,reason] = lane_h:cancel( [mode, hookcount] [, timeout] [, force [, forcekill_timeout]]) |
@@ -250,15 +251,15 @@ LUAG_FUNC(thread_cancel) | |||
250 | Lane* const lane{ lua_toLane(L, 1) }; | 251 | Lane* const lane{ lua_toLane(L, 1) }; |
251 | CancelOp const op{ which_op(L, 2) }; // this removes the op string from the stack | 252 | CancelOp const op{ which_op(L, 2) }; // this removes the op string from the stack |
252 | 253 | ||
253 | if (op > 0) // hook is requested | 254 | if (static_cast<int>(op) > static_cast<int>(CancelOp::Soft)) // hook is requested |
254 | { | 255 | { |
255 | int hook_count = (int) lua_tointeger(L, 2); | 256 | int const hook_count{ static_cast<int>(lua_tointeger(L, 2)) }; |
256 | lua_remove(L, 2); // argument is processed, remove it | 257 | lua_remove(L, 2); // argument is processed, remove it |
257 | if (hook_count < 1) | 258 | if (hook_count < 1) |
258 | { | 259 | { |
259 | return luaL_error(L, "hook count cannot be < 1"); | 260 | return luaL_error(L, "hook count cannot be < 1"); |
260 | } | 261 | } |
261 | lua_sethook(lane->L, cancel_hook, op, hook_count); | 262 | lua_sethook(lane->L, cancel_hook, static_cast<int>(op), hook_count); |
262 | } | 263 | } |
263 | 264 | ||
264 | double secs{ 0.0 }; | 265 | double secs{ 0.0 }; |