[runtime] Fix DISABLE_REFLECTION_EMIT build.
[mono.git] / mono / utils / mono-threads-api.h
1 /**
2  * \file
3  * Low level access to thread state.
4  *
5  * Author:
6  *      Rodrigo Kumpera (kumpera@gmail.com)
7  *
8  * (C) 2015 Xamarin
9  */
10
11 #ifndef __MONO_THREADS_API_H__
12 #define __MONO_THREADS_API_H__
13
14 #include <glib.h>
15 #include <mono/utils/mono-publib.h>
16
17 MONO_BEGIN_DECLS
18
19 /*
20 >>>> WARNING WARNING WARNING <<<<
21
22 This API is experimental. It will eventually be required to properly use the rest of the raw-omp embedding API.
23 */
24
25 MONO_API gpointer
26 mono_threads_enter_gc_unsafe_region (gpointer* stackdata);
27
28 MONO_API void
29 mono_threads_exit_gc_unsafe_region (gpointer cookie, gpointer* stackdata);
30
31 MONO_API gpointer
32 mono_threads_enter_gc_unsafe_region_unbalanced (gpointer* stackdata);
33
34 MONO_API void
35 mono_threads_exit_gc_unsafe_region_unbalanced (gpointer cookie, gpointer* stackdata);
36
37 MONO_API void
38 mono_threads_assert_gc_unsafe_region (void);
39
40
41
42 MONO_API gpointer
43 mono_threads_enter_gc_safe_region (gpointer *stackdata);
44
45 MONO_API void
46 mono_threads_exit_gc_safe_region (gpointer cookie, gpointer *stackdata);
47
48 MONO_API gpointer
49 mono_threads_enter_gc_safe_region_unbalanced (gpointer *stackdata);
50
51 MONO_API void
52 mono_threads_exit_gc_safe_region_unbalanced (gpointer cookie, gpointer *stackdata);
53
54 MONO_API void
55 mono_threads_assert_gc_safe_region (void);
56
57 /*
58 Use those macros to limit regions of code that interact with managed memory or use the embedding API.
59 This will put the current thread in GC Unsafe mode.
60
61 For further explanation of what can and can't be done in GC unsafe mode:
62 http://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#gc-unsafe-mode
63 */
64 #define MONO_ENTER_GC_UNSAFE    \
65         do {    \
66                 gpointer __gc_unsafe_dummy;     \
67                 gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region (&__gc_unsafe_dummy)
68
69 #define MONO_EXIT_GC_UNSAFE     \
70                 mono_threads_exit_gc_unsafe_region      (__gc_unsafe_cookie, &__gc_unsafe_dummy);       \
71         } while (0)
72
73 #define MONO_ENTER_GC_UNSAFE_UNBALANCED \
74         do {    \
75                 gpointer __gc_unsafe_unbalanced_dummy;  \
76                 gpointer __gc_unsafe_unbalanced_cookie = mono_threads_enter_gc_unsafe_region_unbalanced (&__gc_unsafe_unbalanced_dummy)
77
78 #define MONO_EXIT_GC_UNSAFE_UNBALANCED  \
79                 mono_threads_exit_gc_unsafe_region_unbalanced   (__gc_unsafe_unbalanced_cookie, &__gc_unsafe_unbalanced_dummy); \
80         } while (0)
81
82 #define MONO_ENTER_GC_SAFE      \
83         do {    \
84                 gpointer __gc_safe_dummy;       \
85                 gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region (&__gc_safe_dummy)
86
87 #define MONO_EXIT_GC_SAFE       \
88                 mono_threads_exit_gc_safe_region (__gc_safe_cookie, &__gc_safe_dummy);  \
89         } while (0)
90
91 #define MONO_ENTER_GC_SAFE_UNBALANCED   \
92         do {    \
93                 gpointer __gc_safe_unbalanced_dummy;    \
94                 gpointer __gc_safe_unbalanced_cookie = mono_threads_enter_gc_safe_region_unbalanced (&__gc_safe_unbalanced_dummy)
95
96 #define MONO_EXIT_GC_SAFE_UNBALANCED    \
97                 mono_threads_exit_gc_safe_region_unbalanced (__gc_safe_unbalanced_cookie, &__gc_safe_unbalanced_dummy); \
98         } while (0)
99
100 MONO_END_DECLS
101
102 #endif /* __MONO_LOGGER_H__ */