[runtime] Reworked coop GC stack handling in platforms with restricted access to...
[mono.git] / mono / utils / mono-threads-coop.h
1 /*
2  * mono-threads-coop.h: Cooperative suspend thread helpers
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * (C) 2015 Xamarin
8  */
9
10 #ifndef __MONO_THREADS_COOP_H__
11 #define __MONO_THREADS_COOP_H__
12
13 #include <config.h>
14
15 #ifdef USE_COOP_GC
16
17 /* Runtime consumable API */
18
19 #define MONO_SUSPEND_CHECK() do {       \
20         if (G_UNLIKELY (mono_polling_required)) mono_threads_state_poll ();     \
21 } while (0);
22
23 #define MONO_PREPARE_BLOCKING   \
24 {       \
25         void *__dummy;  \
26         void *__blocking_cookie = mono_threads_prepare_blocking (&__dummy);
27
28 #define MONO_FINISH_BLOCKING \
29         mono_threads_finish_blocking (__blocking_cookie, &__dummy);     \
30 }
31
32 #define MONO_PREPARE_RESET_BLOCKING     \
33 {       \
34         void *__dummy;  \
35         void *__reset_cookie = mono_threads_reset_blocking_start (&__dummy);
36
37 #define MONO_FINISH_RESET_BLOCKING \
38         mono_threads_reset_blocking_end (__reset_cookie, &__dummy);     \
39 }
40
41 #define MONO_TRY_BLOCKING       \
42 {       \
43         void *__dummy;  \
44         void *__try_block_cookie = mono_threads_try_prepare_blocking (&__dummy);
45
46 #define MONO_FINISH_TRY_BLOCKING \
47         mono_threads_finish_try_blocking (__try_block_cookie, &__dummy);        \
48 }
49
50 /* Internal API */
51
52 void mono_threads_state_poll (void);
53 void mono_threads_state_poll_stack_data (void* stackdata);
54
55 void* mono_threads_prepare_blocking (void* stackdata);
56 void mono_threads_finish_blocking (void* cookie, void* stackdata);
57
58 void* mono_threads_reset_blocking_start (void* stackdata);
59 void mono_threads_reset_blocking_end (void* cookie, void* stackdata);
60
61 void* mono_threads_try_prepare_blocking (void* stackdata);
62 void mono_threads_finish_try_blocking (void* cookie, void* stackdata);
63
64 /* JIT specific interface */
65 extern volatile size_t mono_polling_required;
66
67 #else
68
69 #define MONO_SUSPEND_CHECK() do {       } while (0);
70 #define MONO_PREPARE_BLOCKING {
71 #define MONO_FINISH_BLOCKING }
72 #define MONO_PREPARE_RESET_BLOCKING {
73 #define MONO_FINISH_RESET_BLOCKING }
74 #define MONO_TRY_BLOCKING {
75 #define MONO_FINISH_TRY_BLOCKING }
76
77 #endif /* USE_COOP_GC */
78
79
80 #endif