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