Merge pull request #1899 from saper/resgencond
[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 *__blocking_cookie = mono_threads_prepare_blocking ();
26
27 #define MONO_FINISH_BLOCKING \
28         mono_threads_finish_blocking (__blocking_cookie);       \
29 }
30
31 #define MONO_PREPARE_RESET_BLOCKING     \
32 {       \
33         void *__reset_cookie = mono_threads_reset_blocking_start ();
34
35 #define MONO_FINISH_RESET_BLOCKING \
36         mono_threads_reset_blocking_end (__reset_cookie);       \
37 }
38
39 #define MONO_TRY_BLOCKING       \
40 {       \
41         void *__try_block_cookie = mono_threads_try_prepare_blocking ();
42
43 #define MONO_FINISH_TRY_BLOCKING \
44         mono_threads_finish_try_blocking (__try_block_cookie);  \
45 }
46
47 /* Internal API */
48
49 void mono_threads_state_poll (void);
50 void* mono_threads_prepare_blocking (void);
51 void mono_threads_finish_blocking (void* cookie);
52
53 void* mono_threads_reset_blocking_start (void);
54 void mono_threads_reset_blocking_end (void* cookie);
55
56 void* mono_threads_try_prepare_blocking (void);
57 void mono_threads_finish_try_blocking (void* cookie);
58
59 /* JIT specific interface */
60 extern volatile size_t mono_polling_required;
61
62 #else
63
64 #define MONO_SUSPEND_CHECK() do {       } while (0);
65 #define MONO_PREPARE_BLOCKING {
66 #define MONO_FINISH_BLOCKING }
67 #define MONO_PREPARE_RESET_BLOCKING {
68 #define MONO_FINISH_RESET_BLOCKING }
69 #define MONO_TRY_BLOCKING {
70 #define MONO_FINISH_TRY_BLOCKING }
71
72 #endif /* USE_COOP_GC */
73
74
75 #endif