3 * Low level access to thread state.
6 * Rodrigo Kumpera (kumpera@gmail.com)
11 #ifndef __MONO_THREADS_API_H__
12 #define __MONO_THREADS_API_H__
15 #include <mono/utils/mono-publib.h>
16 #include <mono/utils/mono-compiler.h>
21 >>>> WARNING WARNING WARNING <<<<
23 This API is experimental. It will eventually be required to properly use the rest of the raw-omp embedding API.
26 typedef struct _MonoStackData
{
27 gpointer stackpointer
;
28 const char *function_name
;
31 // FIXME an ifdef to change __func__ to empty or further minimization.
32 #define MONO_STACKDATA(x) MonoStackData x = { &x, __func__ }
34 static inline const char*
35 mono_stackdata_get_function_name (const MonoStackData
*stackdata
)
37 return stackdata
->function_name
;
40 static inline gpointer
41 mono_stackdata_get_stackpointer (const MonoStackData
*stackdata
)
43 return stackdata
->stackpointer
;
46 MONO_API MONO_RT_EXTERNAL_ONLY gpointer
47 mono_threads_enter_gc_unsafe_region (gpointer
* stackdata
);
50 mono_threads_enter_gc_unsafe_region_internal (MonoStackData
*stackdata
);
52 MONO_API MONO_RT_EXTERNAL_ONLY
void
53 mono_threads_exit_gc_unsafe_region (gpointer cookie
, gpointer
* stackdata
);
56 mono_threads_exit_gc_unsafe_region_internal (gpointer cookie
, MonoStackData
*stackdata
);
59 mono_threads_enter_gc_unsafe_region_unbalanced (gpointer
* stackdata
);
62 mono_threads_enter_gc_unsafe_region_unbalanced_internal (MonoStackData
*stackdata
);
65 mono_threads_exit_gc_unsafe_region_unbalanced (gpointer cookie
, gpointer
* stackdata
);
68 mono_threads_exit_gc_unsafe_region_unbalanced_internal (gpointer cookie
, MonoStackData
*stackdata
);
70 MONO_API MONO_RT_EXTERNAL_ONLY
void
71 mono_threads_assert_gc_unsafe_region (void);
73 MONO_API MONO_RT_EXTERNAL_ONLY gpointer
74 mono_threads_enter_gc_safe_region (gpointer
*stackdata
);
76 MONO_PROFILER_API gpointer
77 mono_threads_enter_gc_safe_region_internal (MonoStackData
*stackdata
);
79 MONO_API MONO_RT_EXTERNAL_ONLY
void
80 mono_threads_exit_gc_safe_region (gpointer cookie
, gpointer
*stackdata
);
82 MONO_PROFILER_API
void
83 mono_threads_exit_gc_safe_region_internal (gpointer cookie
, MonoStackData
*stackdata
);
86 mono_threads_enter_gc_safe_region_unbalanced (gpointer
*stackdata
);
89 mono_threads_enter_gc_safe_region_unbalanced_internal (MonoStackData
*stackdata
);
92 mono_threads_exit_gc_safe_region_unbalanced (gpointer cookie
, gpointer
*stackdata
);
95 mono_threads_exit_gc_safe_region_unbalanced_internal (gpointer cookie
, MonoStackData
*stackdata
);
98 mono_threads_assert_gc_safe_region (void);
101 Use those macros to limit regions of code that interact with managed memory or use the embedding API.
102 This will put the current thread in GC Unsafe mode.
104 For further explanation of what can and can't be done in GC unsafe mode:
105 http://www.mono-project.com/docs/advanced/runtime/docs/coop-suspend/#gc-unsafe-mode
107 #define MONO_ENTER_GC_UNSAFE \
109 MONO_STACKDATA (__gc_unsafe_dummy); \
110 gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region_internal (&__gc_unsafe_dummy)
112 #define MONO_EXIT_GC_UNSAFE \
113 mono_threads_exit_gc_unsafe_region_internal (__gc_unsafe_cookie, &__gc_unsafe_dummy); \
116 #define MONO_ENTER_GC_UNSAFE_UNBALANCED \
118 MONO_STACKDATA (__gc_unsafe_unbalanced_dummy); \
119 gpointer __gc_unsafe_unbalanced_cookie = mono_threads_enter_gc_unsafe_region_unbalanced_internal (&__gc_unsafe_unbalanced_dummy)
121 #define MONO_EXIT_GC_UNSAFE_UNBALANCED \
122 mono_threads_exit_gc_unsafe_region_unbalanced_internal (__gc_unsafe_unbalanced_cookie, &__gc_unsafe_unbalanced_dummy); \
125 #define MONO_ENTER_GC_SAFE \
127 MONO_STACKDATA (__gc_safe_dummy); \
128 gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region_internal (&__gc_safe_dummy)
130 #define MONO_EXIT_GC_SAFE \
131 mono_threads_exit_gc_safe_region_internal (__gc_safe_cookie, &__gc_safe_dummy); \
134 #define MONO_ENTER_GC_SAFE_UNBALANCED \
136 MONO_STACKDATA (__gc_safe_unbalanced_dummy); \
137 gpointer __gc_safe_unbalanced_cookie = mono_threads_enter_gc_safe_region_unbalanced_internal (&__gc_safe_unbalanced_dummy)
139 #define MONO_EXIT_GC_SAFE_UNBALANCED \
140 mono_threads_exit_gc_safe_region_unbalanced_internal (__gc_safe_unbalanced_cookie, &__gc_safe_unbalanced_dummy); \
144 mono_threads_enter_no_safepoints_region (const char *func
);
147 mono_threads_exit_no_safepoints_region (const char *func
);
149 #define MONO_ENTER_NO_SAFEPOINTS \
152 if (mono_threads_are_safepoints_enabled ()) \
153 mono_threads_enter_no_safepoints_region (__func__); \
156 #define MONO_EXIT_NO_SAFEPOINTS \
157 if (mono_threads_are_safepoints_enabled ()) \
158 mono_threads_exit_no_safepoints_region (__func__); \
163 #endif /* __MONO_LOGGER_H__ */