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