aboutsummaryrefslogtreecommitdiff
path: root/src/cancel.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/cancel.h')
-rw-r--r--src/cancel.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/cancel.h b/src/cancel.h
new file mode 100644
index 0000000..3112809
--- /dev/null
+++ b/src/cancel.h
@@ -0,0 +1,57 @@
1#if !defined( __LANES_CANCEL_H__)
2#define __LANES_CANCEL_H__ 1
3
4#include "lua.h"
5#include "lualib.h"
6#include "lauxlib.h"
7
8#include "uniquekey.h"
9#include "macros_and_utils.h"
10
11// ################################################################################################
12
13typedef struct s_Lane Lane; // forward
14
15/*
16 * Lane cancellation request modes
17 */
18enum e_cancel_request
19{
20 CANCEL_NONE, // no pending cancel request
21 CANCEL_SOFT, // user wants the lane to cancel itself manually on cancel_test()
22 CANCEL_HARD // user wants the lane to be interrupted (meaning code won't return from those functions) from inside linda:send/receive calls
23};
24
25typedef enum
26{
27 CR_Timeout,
28 CR_Cancelled,
29 CR_Killed
30} cancel_result;
31
32// crc64/we of string "CANCEL_ERROR" generated at http://www.nitrxgen.net/hashgen/
33static DECLARE_CONST_UNIQUE_KEY(CANCEL_ERROR, 0xe97d41626cc97577); // 'cancel_error' sentinel
34
35// crc64/we of string "CANCEL_TEST_KEY" generated at http://www.nitrxgen.net/hashgen/
36static DECLARE_CONST_UNIQUE_KEY(CANCEL_TEST_KEY, 0xe66f5960c57d133a); // used as registry key
37
38void cancel_hook( lua_State* L, lua_Debug* ar);
39
40cancel_result thread_cancel( lua_State* L, Lane* s, double secs_, bool_t force_, double waitkill_timeout_);
41
42static inline int cancel_error( lua_State* L)
43{
44 STACK_GROW( L, 1);
45 push_unique_key( L, CANCEL_ERROR); // special error value
46 return lua_error( L); // doesn't return
47}
48
49// ################################################################################################
50// ################################################################################################
51
52LUAG_FUNC( cancel_test);
53LUAG_FUNC( thread_cancel);
54
55// ################################################################################################
56
57#endif // __LANES_CANCEL_H__