[coop] New local handles implementation.
[mono.git] / mono / utils / mono-threads.h
index 1019dda1884e4c078e4f9de583e74a339c223bfc..7f304295fcd4c42e86fb15374e443921c29381b4 100644 (file)
@@ -14,8 +14,6 @@
 #include <mono/utils/mono-stack-unwinding.h>
 #include <mono/utils/mono-linked-list-set.h>
 #include <mono/utils/mono-tls.h>
-#include <mono/utils/mono-threads-coop.h>
-#include <mono/utils/mono-threads-api.h>
 #include <mono/utils/mono-coop-semaphore.h>
 
 #include <mono/io-layer/io-layer.h>
@@ -164,13 +162,6 @@ enum {
        ASYNC_SUSPEND_STATE_INDEX = 1,
 };
 
-/*
- * This enum tells which async thread service corresponds to which bit.
- */
-typedef enum {
-       MONO_SERVICE_REQUEST_SAMPLE = 1,
-} MonoAsyncJob;
-
 typedef struct _MonoThreadInfoInterruptToken MonoThreadInfoInterruptToken;
 
 typedef struct {
@@ -198,10 +189,11 @@ typedef struct {
 #if defined(USE_POSIX_BACKEND)
        MonoSemType finish_resume_semaphore;
        gboolean syscall_break_signal;
-       gboolean suspend_can_continue;
        int signal;
 #endif
 
+       gboolean suspend_can_continue;
+
        /* This memory pool is used by coop GC to save stack data roots between GC unsafe regions */
        GByteArray *stackdata;
 
@@ -241,18 +233,15 @@ typedef struct {
        /* Set when the thread is started, or in _wapi_thread_duplicate () */
        HANDLE handle;
 
-       /* Asynchronous service request. This flag is meant to be consumed by the multiplexing signal handlers to discover what sort of work they need to do.
-        * Use the mono_threads_add_async_job and mono_threads_consume_async_jobs APIs to modify this flag.
-        * In the future the signaling should be part of the API, but for now, it's only for massaging the bits.
-        */
-       volatile gint32 service_requests;
-
        void *jit_data;
 
        MonoThreadInfoInterruptToken *interrupt_token;
 
-       /* MonoHandleArena for coop handles */
-       gpointer handle_arena;
+       /* HandleStack for coop handles */
+       gpointer handle_stack;
+
+       /* Stack mark for targets that explicitly require one */
+       gpointer stack_mark;
 } MonoThreadInfo;
 
 typedef struct {
@@ -346,7 +335,7 @@ mono_thread_info_register_small_id (void);
 THREAD_INFO_TYPE *
 mono_thread_info_attach (void *baseptr);
 
-void
+MONO_API void
 mono_thread_info_detach (void);
 
 gboolean
@@ -370,9 +359,6 @@ mono_thread_info_lookup (MonoNativeThreadId id);
 gboolean
 mono_thread_info_resume (MonoNativeThreadId tid);
 
-void
-mono_thread_info_set_name (MonoNativeThreadId tid, const char *name);
-
 void
 mono_thread_info_safe_suspend_and_run (MonoNativeThreadId id, gboolean interrupt_kernel, MonoSuspendThreadCallback callback, gpointer user_data);
 
@@ -466,17 +452,6 @@ mono_threads_get_max_stack_size (void);
 HANDLE
 mono_threads_open_thread_handle (HANDLE handle, MonoNativeThreadId tid);
 
-/*
-This is the async job submission/consumption API.
-XXX: This is a PROVISIONAL API only meant to be used by the statistical profiler.
-If you want to use/extend it anywhere else, understand that you'll have to do some API design work to better fit this puppy.
-*/
-gboolean
-mono_threads_add_async_job (THREAD_INFO_TYPE *info, MonoAsyncJob job);
-
-MonoAsyncJob
-mono_threads_consume_async_jobs (void);
-
 MONO_API void
 mono_threads_attach_tools_thread (void);
 
@@ -542,12 +517,11 @@ void mono_threads_core_exit (int exit_code);
 void mono_threads_core_unregister (THREAD_INFO_TYPE *info);
 HANDLE mono_threads_core_open_handle (void);
 HANDLE mono_threads_core_open_thread_handle (HANDLE handle, MonoNativeThreadId tid);
-void mono_threads_core_set_name (MonoNativeThreadId tid, const char *name);
 
 void mono_threads_coop_begin_global_suspend (void);
 void mono_threads_coop_end_global_suspend (void);
 
-MonoNativeThreadId
+MONO_API MonoNativeThreadId
 mono_native_thread_id_get (void);
 
 gboolean
@@ -556,6 +530,9 @@ mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2);
 gboolean
 mono_native_thread_create (MonoNativeThreadId *tid, gpointer func, gpointer arg);
 
+MONO_API void
+mono_native_thread_set_name (MonoNativeThreadId tid, const char *name);
+
 /*Mach specific internals */
 void mono_threads_init_dead_letter (void);
 void mono_threads_install_dead_letter (void);
@@ -604,7 +581,6 @@ typedef enum {
 } MonoDoBlockingResult;
 
 typedef enum {
-       DoneBlockingAborted, //blocking was aborted and not properly restored, poll the state
        DoneBlockingOk, //exited blocking fine
        DoneBlockingWait, //thread should end suspended
 } MonoDoneBlockingResult;
@@ -612,9 +588,9 @@ typedef enum {
 
 typedef enum {
        AbortBlockingIgnore, //Ignore
-       AbortBlockingIgnoreAndPoll, //Ignore and pool
+       AbortBlockingIgnoreAndPoll, //Ignore and poll
        AbortBlockingOk, //Abort worked
-       AbortBlockingOkAndPool, //Abort worked, but pool before
+       AbortBlockingWait, //Abort worked, but should wait for resume
 } MonoAbortBlockingResult;
 
 
@@ -625,13 +601,15 @@ MonoRequestAsyncSuspendResult mono_threads_transition_request_async_suspension (
 MonoSelfSupendResult mono_threads_transition_state_poll (THREAD_INFO_TYPE *info);
 MonoResumeResult mono_threads_transition_request_resume (THREAD_INFO_TYPE* info);
 gboolean mono_threads_transition_finish_async_suspend (THREAD_INFO_TYPE* info);
-void mono_threads_transition_async_suspend_compensation (THREAD_INFO_TYPE* info);
 MonoDoBlockingResult mono_threads_transition_do_blocking (THREAD_INFO_TYPE* info);
 MonoDoneBlockingResult mono_threads_transition_done_blocking (THREAD_INFO_TYPE* info);
 MonoAbortBlockingResult mono_threads_transition_abort_blocking (THREAD_INFO_TYPE* info);
 
 MonoThreadUnwindState* mono_thread_info_get_suspend_state (THREAD_INFO_TYPE *info);
 
+gpointer
+mono_threads_enter_gc_unsafe_region_cookie (void);
+
 
 void mono_thread_info_wait_for_resume (THREAD_INFO_TYPE *info);
 /* Advanced suspend API, used for suspending multiple threads as once. */
@@ -645,12 +623,12 @@ gboolean mono_thread_info_in_critical_location (THREAD_INFO_TYPE *info);
 gboolean mono_thread_info_begin_suspend (THREAD_INFO_TYPE *info);
 gboolean mono_thread_info_begin_resume (THREAD_INFO_TYPE *info);
 
-gboolean
-mono_thread_info_check_suspend_result (THREAD_INFO_TYPE *info);
-
 void mono_threads_add_to_pending_operation_set (THREAD_INFO_TYPE* info); //XXX rename to something to reflect the fact that this is used for both suspend and resume
 gboolean mono_threads_wait_pending_operations (void);
 void mono_threads_begin_global_suspend (void);
 void mono_threads_end_global_suspend (void);
 
+gboolean
+mono_thread_info_is_current (THREAD_INFO_TYPE *info);
+
 #endif /* __MONO_THREADS_H__ */