[wasm] Add threading, dl and hwcap support for wasm.
[mono.git] / mono / utils / mono-threads.h
index 63cad57d86825aeaf3e3b15d60737fe9d5b252c2..ffa9de63a66e5468d8cd5fe58989202cb73755b1 100644 (file)
@@ -109,7 +109,9 @@ and reduce the number of casts drastically.
 /* If this is defined, use the signals backed on Mach. Debug only as signals can't be made usable on OSX. */
 // #define USE_SIGNALS_ON_MACH
 
-#if defined (_POSIX_VERSION)
+#ifdef HOST_WASM
+#define USE_WASM_BACKEND
+#elif defined (_POSIX_VERSION)
 #if defined (__MACH__) && !defined (USE_SIGNALS_ON_MACH)
 #define USE_MACH_BACKEND
 #else
@@ -219,28 +221,35 @@ typedef struct {
 
        /* Stack mark for targets that explicitly require one */
        gpointer stack_mark;
+
+       /* GCHandle to MonoInternalThread */
+       guint32 internal_thread_gchandle;
+
+       /*
+        * Used by the sampling code in mini-posix.c to ensure that a thread has
+        * handled a sampling signal before sending another one.
+        */
+       gint32 profiler_signal_ack;
 } MonoThreadInfo;
 
 typedef struct {
-       void* (*thread_register)(THREAD_INFO_TYPE *info, void *baseaddr);
-       /*
-       This callback is called with @info still on the thread list.
-       This call is made while holding the suspend lock, so don't do callbacks.
-       SMR remains functional as its small_id has not been reclaimed.
-       */
-       void (*thread_unregister)(THREAD_INFO_TYPE *info);
+       void* (*thread_attach)(THREAD_INFO_TYPE *info);
        /*
-       This callback is called right before thread_unregister. This is called
+       This callback is called right before thread_detach_with_lock. This is called
        without any locks held so it's the place for complicated cleanup.
 
-       The thread must remain operational between this call and thread_unregister.
-       It must be possible to successfully suspend it after thread_unregister completes.
+       The thread must remain operational between this call and thread_detach_with_lock.
+       It must be possible to successfully suspend it after thread_detach completes.
        */
        void (*thread_detach)(THREAD_INFO_TYPE *info);
-       void (*thread_attach)(THREAD_INFO_TYPE *info);
-       gboolean (*mono_method_is_critical) (void *method);
+       /*
+       This callback is called with @info still on the thread list.
+       This call is made while holding the suspend lock, so don't do callbacks.
+       SMR remains functional as its small_id has not been reclaimed.
+       */
+       void (*thread_detach_with_lock)(THREAD_INFO_TYPE *info);
        gboolean (*ip_in_critical_region) (MonoDomain *domain, gpointer ip);
-       gboolean (*mono_thread_in_critical_region) (THREAD_INFO_TYPE *info);
+       gboolean (*thread_in_critical_region) (THREAD_INFO_TYPE *info);
 } MonoThreadInfoCallbacks;
 
 typedef struct {
@@ -299,26 +308,38 @@ mono_thread_info_set_tid (THREAD_INFO_TYPE *info, MonoNativeThreadId tid)
  * a single block with info from both camps. 
  */
 void
-mono_threads_init (MonoThreadInfoCallbacks *callbacks, size_t thread_info_size);
+mono_thread_info_init (size_t thread_info_size);
+
+void
+mono_thread_info_callbacks_init (MonoThreadInfoCallbacks *callbacks);
 
 void
-mono_threads_signals_init (void);
+mono_thread_info_signals_init (void);
 
 void
-mono_threads_runtime_init (MonoThreadInfoRuntimeCallbacks *callbacks);
+mono_thread_info_runtime_init (MonoThreadInfoRuntimeCallbacks *callbacks);
 
 MonoThreadInfoRuntimeCallbacks *
 mono_threads_get_runtime_callbacks (void);
 
-int
+MONO_API int
 mono_thread_info_register_small_id (void);
 
 THREAD_INFO_TYPE *
-mono_thread_info_attach (void *baseptr);
+mono_thread_info_attach (void);
 
 MONO_API void
 mono_thread_info_detach (void);
 
+gboolean
+mono_thread_info_try_get_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 *gchandle);
+
+void
+mono_thread_info_set_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 gchandle);
+
+void
+mono_thread_info_unset_internal_thread_gchandle (THREAD_INFO_TYPE *info);
+
 gboolean
 mono_thread_info_is_exiting (void);
 
@@ -328,7 +349,7 @@ mono_thread_info_current (void);
 THREAD_INFO_TYPE*
 mono_thread_info_current_unchecked (void);
 
-int
+MONO_API int
 mono_thread_info_get_small_id (void);
 
 MonoLinkedListSet*