Making sure mono_marshal_free is used instead of g_free in mono_string_builder_to_utf8
[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 */
49 #define MONO_BEGIN_GC_UNSAFE    \
50         do {    \
51                 gpointer __dummy;       \
52                 gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region (&__dummy)    \
53
54 #define MONO_END_GC_UNSAFE      \
55                 mono_threads_exit_gc_unsafe_region      (__gc_unsafe_cookie, &__dummy); \
56         } while (0)
57
58 #define MONO_BEGIN_GC_SAFE      \
59         do {    \
60                 gpointer __dummy;       \
61                 gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region (&__dummy)        \
62
63 #define MONO_END_GC_SAFE        \
64                 mono_threads_exit_gc_safe_region (__gc_safe_cookie, &__dummy);  \
65         } while (0)
66
67 MONO_END_DECLS
68
69 #endif /* __MONO_LOGGER_H__ */