2 * mono-threads-coop.h: Cooperative suspend thread helpers
5 * Rodrigo Kumpera (kumpera@gmail.com)
10 #ifndef __MONO_THREADS_COOP_H__
11 #define __MONO_THREADS_COOP_H__
16 #include "checked-build.h"
17 #include "mono-threads-api.h"
21 /* JIT specific interface */
22 extern volatile size_t mono_polling_required;
24 /* Runtime consumable API */
26 static gboolean G_GNUC_UNUSED
27 mono_threads_is_coop_enabled (void)
29 #if defined(USE_COOP_GC)
32 static gboolean is_coop_enabled = -1;
33 if (G_UNLIKELY (is_coop_enabled == -1))
34 is_coop_enabled = g_getenv ("MONO_ENABLE_COOP") != NULL ? TRUE : FALSE;
35 return is_coop_enabled;
42 mono_threads_state_poll (void);
45 mono_threads_safepoint (void)
47 if (G_UNLIKELY (mono_polling_required))
48 mono_threads_state_poll ();
52 * The following are used for wrappers and trampolines as their
53 * calls might be unbalanced, due to exception unwinding.
57 mono_threads_enter_gc_safe_region_unbalanced (gpointer *stackdata);
60 mono_threads_exit_gc_safe_region_unbalanced (gpointer cookie, gpointer *stackdata);
63 mono_threads_enter_gc_unsafe_region_unbalanced (gpointer *stackdata);
66 mono_threads_exit_gc_unsafe_region_unbalanced (gpointer cookie, gpointer *stackdata);
68 #define MONO_ENTER_GC_UNSAFE_UNBALANCED \
71 gpointer __reset_cookie = mono_threads_enter_gc_unsafe_region_unbalanced (&__dummy)
73 #define MONO_EXIT_GC_UNSAFE_UNBALANCED \
74 mono_threads_exit_gc_unsafe_region_unbalanced (__reset_cookie, &__dummy); \