Merge pull request #1678 from esdrubal/tzindst
[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 /* Internal API */
39
40 extern volatile size_t mono_threads_polling_required;
41
42 void mono_threads_state_poll (void);
43 void* mono_threads_prepare_blocking (void);
44 void mono_threads_finish_blocking (void* cookie);
45
46 void* mono_threads_reset_blocking_start (void);
47 void mono_threads_reset_blocking_end (void* cookie);
48
49 #else
50
51 #define MONO_SUSPEND_CHECK do { } while (0);
52 #define MONO_PREPARE_BLOCKING {
53 #define MONO_FINISH_BLOCKING }
54 #define MONO_PREPARE_RESET_BLOCKING {
55 #define MONO_FINISH_RESET_BLOCKING }
56
57 #endif /* USE_COOP_GC */
58
59
60 #endif