[threads] Enable blocking transition with MONO_ENABLE_BLOCKING_TRANSITION env variabl...
[mono.git] / mono / utils / mono-threads-coop.h
index d103f42a5bd7a92469382e295205551e0ef35bbf..9937c78414923cac14359e40f861f57e4ce28396 100644 (file)
@@ -1,5 +1,6 @@
-/*
- * mono-threads-coop.h: Cooperative suspend thread helpers
+/**
+ * \file
+ * Cooperative suspend thread helpers
  *
  * Author:
  *     Rodrigo Kumpera (kumpera@gmail.com)
 #define __MONO_THREADS_COOP_H__
 
 #include <config.h>
+#include <glib.h>
 
-#ifdef USE_COOP_GC
+#include "checked-build.h"
+#include "mono-threads.h"
+#include "mono-threads-api.h"
 
-/* Runtime consumable API */
+G_BEGIN_DECLS
 
-#define MONO_SUSPEND_CHECK() do {      \
-       if (G_UNLIKELY (mono_polling_required)) mono_threads_state_poll ();     \
-} while (0);
+/* JIT specific interface */
+extern volatile size_t mono_polling_required;
 
-#define MONO_PREPARE_BLOCKING  \
-{      \
-       void *__dummy;  \
-       void *__blocking_cookie = mono_threads_prepare_blocking (&__dummy);
+/* Runtime consumable API */
 
-#define MONO_FINISH_BLOCKING \
-       mono_threads_finish_blocking (__blocking_cookie, &__dummy);     \
-}
+gboolean
+mono_threads_is_coop_enabled (void);
 
-#define MONO_PREPARE_RESET_BLOCKING    \
-{      \
-       void *__dummy;  \
-       void *__reset_cookie = mono_threads_reset_blocking_start (&__dummy);
+gboolean
+mono_threads_is_blocking_transition_enabled (void);
 
-#define MONO_FINISH_RESET_BLOCKING \
-       mono_threads_reset_blocking_end (__reset_cookie, &__dummy);     \
-}
+/* Internal API */
 
-#define MONO_TRY_BLOCKING      \
-{      \
-       void *__dummy;  \
-       void *__try_block_cookie = mono_threads_try_prepare_blocking (&__dummy);
+void
+mono_threads_state_poll (void);
 
-#define MONO_FINISH_TRY_BLOCKING \
-       mono_threads_finish_try_blocking (__try_block_cookie, &__dummy);        \
+static inline void
+mono_threads_safepoint (void)
+{
+       if (G_UNLIKELY (mono_polling_required))
+               mono_threads_state_poll ();
 }
 
-/* Internal API */
-
-void mono_threads_state_poll (void);
-void mono_threads_state_poll_stack_data (void* stackdata);
+/*
+ * The following are used when detaching a thread. We need to pass the MonoThreadInfo*
+ * as a paramater as the thread info TLS key is being destructed, meaning that
+ * mono_thread_info_current_unchecked will return NULL, which would lead to a
+ * runtime assertion error when trying to switch the state of the current thread.
+ */
 
-void* mono_threads_prepare_blocking (void* stackdata);
-void mono_threads_finish_blocking (void* cookie, void* stackdata);
+gpointer
+mono_threads_enter_gc_safe_region_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
 
-void* mono_threads_reset_blocking_start (void* stackdata);
-void mono_threads_reset_blocking_end (void* cookie, void* stackdata);
+#define MONO_ENTER_GC_SAFE_WITH_INFO(info)     \
+       do {    \
+               gpointer __gc_safe_dummy;       \
+               gpointer __gc_safe_cookie = mono_threads_enter_gc_safe_region_with_info ((info), &__gc_safe_dummy)
 
-void* mono_threads_try_prepare_blocking (void* stackdata);
-void mono_threads_finish_try_blocking (void* cookie, void* stackdata);
+#define MONO_EXIT_GC_SAFE_WITH_INFO    MONO_EXIT_GC_SAFE
 
-/* JIT specific interface */
-extern volatile size_t mono_polling_required;
+gpointer
+mono_threads_enter_gc_unsafe_region_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
 
-#else
+#define MONO_ENTER_GC_UNSAFE_WITH_INFO(info)   \
+       do {    \
+               gpointer __gc_unsafe_dummy;     \
+               gpointer __gc_unsafe_cookie = mono_threads_enter_gc_unsafe_region_with_info ((info), &__gc_unsafe_dummy)
 
-#define MONO_SUSPEND_CHECK() do {      } while (0);
-#define MONO_PREPARE_BLOCKING {
-#define MONO_FINISH_BLOCKING }
-#define MONO_PREPARE_RESET_BLOCKING {
-#define MONO_FINISH_RESET_BLOCKING }
-#define MONO_TRY_BLOCKING {
-#define MONO_FINISH_TRY_BLOCKING }
+#define MONO_EXIT_GC_UNSAFE_WITH_INFO  MONO_EXIT_GC_UNSAFE
 
-#endif /* USE_COOP_GC */
+gpointer
+mono_threads_enter_gc_unsafe_region_unbalanced_with_info (THREAD_INFO_TYPE *info, gpointer *stackdata);
 
+G_END_DECLS
 
 #endif