Merge pull request #1691 from esdrubal/exitevent
[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_threads_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 extern volatile size_t mono_threads_polling_required;
50
51 void mono_threads_state_poll (void);
52 void* mono_threads_prepare_blocking (void);
53 void mono_threads_finish_blocking (void* cookie);
54
55 void* mono_threads_reset_blocking_start (void);
56 void mono_threads_reset_blocking_end (void* cookie);
57
58 void* mono_threads_try_prepare_blocking (void);
59 void mono_threads_finish_try_blocking (void* cookie);
60
61 /* JIT specific interface */
62 extern volatile size_t mono_polling_required ;
63
64 #else
65
66 #define MONO_SUSPEND_CHECK do { } while (0);
67 #define MONO_PREPARE_BLOCKING {
68 #define MONO_FINISH_BLOCKING }
69 #define MONO_PREPARE_RESET_BLOCKING {
70 #define MONO_FINISH_RESET_BLOCKING }
71 #define MONO_TRY_BLOCKING {
72 #define MONO_FINISH_TRY_BLOCKING }
73
74 #endif /* USE_COOP_GC */
75
76
77 #endif