Merge pull request #2998 from lateralusX/jlorenss/win-x64-full-aot-support
[mono.git] / mono / utils / mono-threads-api.h
1 /*
2  * mono-threads-api.h: Low level access to thread state.
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * (C) 2015 Xamarin
8  */
9
10 #ifndef __MONO_THREADS_API_H__
11 #define __MONO_THREADS_API_H__
12
13 #include <mono/utils/mono-publib.h>
14 MONO_BEGIN_DECLS
15
16 /*
17 >>>> WARNING WARNING WARNING <<<<
18
19 This API is experimental. It will eventually be required to properly use the rest of the raw-omp embedding API.
20 */
21
22 /* Don't use those directly, use the MONO_(BEGIN|END)_EFRAME */
23 MONO_API gpointer
24 mono_threads_enter_gc_unsafe_region (gpointer* stackdata);
25
26 MONO_API void
27 mono_threads_exit_gc_unsafe_region (gpointer cookie, gpointer* stackdata);
28
29 MONO_API void
30 mono_threads_assert_gc_unsafe_region (void);
31
32 MONO_API gpointer
33 mono_threads_enter_gc_safe_region (gpointer *stackdata);
34
35 MONO_API void
36 mono_threads_exit_gc_safe_region (gpointer cookie, gpointer *stackdata);
37
38 MONO_API void
39 mono_threads_assert_gc_safe_region (void);
40
41 /*
42 Use those macros to limit regions of code that interact with managed memory or use the embedding API.
43 This will put the current thread in GC Unsafe mode.
44
45 For further explanation of what can and can't be done in GC unsafe mode:
46 http://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#gc-unsafe-mode
47 */
48 #define MONO_ENTER_GC_UNSAFE    \
49         do {    \
50                 gpointer __gc_unsafe_dummy;     \
51                 gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region (&__gc_unsafe_dummy)  \
52
53 #define MONO_EXIT_GC_UNSAFE     \
54                 mono_threads_exit_gc_unsafe_region      (__gc_unsafe_cookie, &__gc_unsafe_dummy);       \
55         } while (0)
56
57 #define MONO_ENTER_GC_SAFE      \
58         do {    \
59                 gpointer __gc_safe_dummy;       \
60                 gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region (&__gc_safe_dummy)        \
61
62 #define MONO_EXIT_GC_SAFE       \
63                 mono_threads_exit_gc_safe_region (__gc_safe_cookie, &__gc_safe_dummy);  \
64         } while (0)
65
66 MONO_END_DECLS
67
68 #endif /* __MONO_LOGGER_H__ */