3 #include <mono/utils/mono-threads.h>
4 #include <mono/utils/mono-mmap.h>
7 #if defined (USE_WASM_BACKEND)
9 #include <mono/utils/mono-threads.h>
10 #include <mono/utils/mono-mmap.h>
12 #include <emscripten.h>
15 #define round_down(addr, val) ((void*)((addr) & ~((val) - 1)))
19 wasm_get_stack_base (void)
28 wasm_get_stack_size (void)
37 mono_thread_info_get_system_max_stack_size (void)
39 return wasm_get_stack_size ();
44 mono_threads_suspend_init_signals (void)
49 mono_threads_suspend_init (void)
54 mono_threads_suspend_register (MonoThreadInfo
*info
)
59 mono_threads_suspend_begin_async_resume (MonoThreadInfo
*info
)
65 mono_threads_suspend_free (MonoThreadInfo
*info
)
70 mono_threads_suspend_begin_async_suspend (MonoThreadInfo
*info
, gboolean interrupt_kernel
)
76 mono_threads_suspend_check_suspend_result (MonoThreadInfo
*info
)
82 mono_threads_suspend_abort_syscall (MonoThreadInfo
*info
)
89 mono_native_thread_id_equals (MonoNativeThreadId id1
, MonoNativeThreadId id2
)
96 mono_native_thread_id_get (void)
98 return (MonoNativeThreadId
)1;
102 mono_native_thread_create (MonoNativeThreadId
*tid
, gpointer func
, gpointer arg
)
104 g_error ("WASM doesn't support threading");
107 static const char *thread_name
;
110 mono_native_thread_set_name (MonoNativeThreadId tid
, const char *name
)
112 thread_name
= g_strdup (name
);
116 mono_native_thread_join (MonoNativeThreadId tid
)
118 g_error ("WASM doesn't support threading");
125 mono_threads_platform_yield (void)
131 mono_threads_platform_get_stack_bounds (guint8
**staddr
, size_t *stsize
)
133 *staddr
= (guint8
*)wasm_get_stack_base ();
134 *stsize
= wasm_get_stack_size ();
139 mono_thread_platform_create_thread (MonoThreadStart thread_fn
, gpointer thread_data
, gsize
* const stack_size
, MonoNativeThreadId
*tid
)
141 g_warning ("WASM doesn't support threading");
145 void mono_threads_platform_init (void)
150 mono_threads_platform_exit (gsize exit_code
)
152 g_error ("WASM doesn't support threading");
156 mono_threads_platform_in_critical_region (MonoNativeThreadId tid
)
162 extern void schedule_background_exec (void);
167 mono_threads_schedule_background_job (background_job_cb cb
)
170 schedule_background_exec ();
172 if (!g_slist_find (jobs
, (gconstpointer
)cb
))
173 jobs
= g_slist_prepend (jobs
, (gpointer
)cb
);
177 EMSCRIPTEN_KEEPALIVE
void
178 mono_background_exec (void)
180 GSList
*j
= jobs
, *cur
;
183 for (cur
= j
; cur
; cur
= cur
->next
) {
184 background_job_cb cb
= (background_job_cb
)cur
->data
;