Merge pull request #3040 from xmcclure/debugger-step-recursive
[mono.git] / mono / utils / mono-threads-coop.h
1 /*
2  * mono-threads-coop.h: Cooperative suspend thread helpers
3  *
4  * Author:
5  *      Rodrigo Kumpera (kumpera@gmail.com)
6  *
7  * (C) 2015 Xamarin
8  */
9
10 #ifndef __MONO_THREADS_COOP_H__
11 #define __MONO_THREADS_COOP_H__
12
13 #include <config.h>
14 #include <glib.h>
15
16 #include "checked-build.h"
17 #include "mono-threads.h"
18 #include "mono-threads-api.h"
19
20 G_BEGIN_DECLS
21
22 /* JIT specific interface */
23 extern volatile size_t mono_polling_required;
24
25 /* Runtime consumable API */
26
27 gboolean
28 mono_threads_is_coop_enabled (void);
29
30 /* Internal API */
31
32 void
33 mono_threads_state_poll (void);
34
35 static inline void
36 mono_threads_safepoint (void)
37 {
38         if (G_UNLIKELY (mono_polling_required))
39                 mono_threads_state_poll ();
40 }
41
42 /*
43  * The following are used when detaching a thread. We need to pass the MonoThreadInfo*
44  * as a paramater as the thread info TLS key is being destructed, meaning that
45  * mono_thread_info_current_unchecked will return NULL, which would lead to a
46  * runtime assertion error when trying to switch the state of the current thread.
47  */
48
49 gpointer
50 mono_threads_enter_gc_safe_region_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
51
52 #define MONO_ENTER_GC_SAFE_WITH_INFO(info)      \
53         do {    \
54                 gpointer __gc_safe_dummy;       \
55                 gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region_with_info ((info), &__gc_safe_dummy)
56
57 #define MONO_EXIT_GC_SAFE_WITH_INFO     MONO_EXIT_GC_SAFE
58
59 gpointer
60 mono_threads_enter_gc_unsafe_region_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
61
62 #define MONO_ENTER_GC_UNSAFE_WITH_INFO(info)    \
63         do {    \
64                 gpointer __gc_unsafe_dummy;     \
65                 gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region_with_info ((info), &__gc_unsafe_dummy)
66
67 #define MONO_EXIT_GC_UNSAFE_WITH_INFO   MONO_EXIT_GC_UNSAFE
68
69 gpointer
70 mono_threads_enter_gc_unsafe_region_unbalanced_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
71
72 G_END_DECLS
73
74 #endif