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