[interp] Remove unreachable code (#12411)
[mono-project.git] / mono / utils / mono-threads-wasm.c
blobdbc53ca66e9643bb37433181ce8aab466164d3fb
1 #include "config.h"
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>
13 #include <glib.h>
15 #define round_down(addr, val) ((void*)((addr) & ~((val) - 1)))
17 EMSCRIPTEN_KEEPALIVE
18 static int
19 wasm_get_stack_base (void)
21 return EM_ASM_INT ({
22 return STACK_BASE;
23 });
26 EMSCRIPTEN_KEEPALIVE
27 static int
28 wasm_get_stack_size (void)
30 return EM_ASM_INT ({
31 return TOTAL_STACK;
32 });
36 int
37 mono_thread_info_get_system_max_stack_size (void)
39 return wasm_get_stack_size ();
43 void
44 mono_threads_suspend_init_signals (void)
48 void
49 mono_threads_suspend_init (void)
53 void
54 mono_threads_suspend_register (MonoThreadInfo *info)
58 gboolean
59 mono_threads_suspend_begin_async_resume (MonoThreadInfo *info)
61 return TRUE;
64 void
65 mono_threads_suspend_free (MonoThreadInfo *info)
69 gboolean
70 mono_threads_suspend_begin_async_suspend (MonoThreadInfo *info, gboolean interrupt_kernel)
72 return TRUE;
75 gboolean
76 mono_threads_suspend_check_suspend_result (MonoThreadInfo *info)
78 return TRUE;
81 void
82 mono_threads_suspend_abort_syscall (MonoThreadInfo *info)
86 //----
88 gboolean
89 mono_native_thread_id_equals (MonoNativeThreadId id1, MonoNativeThreadId id2)
91 return id1 == id2;
95 MonoNativeThreadId
96 mono_native_thread_id_get (void)
98 return (MonoNativeThreadId)1;
101 MONO_API gboolean
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;
109 void
110 mono_native_thread_set_name (MonoNativeThreadId tid, const char *name)
112 thread_name = g_strdup (name);
115 gboolean
116 mono_native_thread_join (MonoNativeThreadId tid)
118 g_error ("WASM doesn't support threading");
119 return FALSE;
122 //----
124 gboolean
125 mono_threads_platform_yield (void)
127 return TRUE;
130 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 ();
138 gboolean
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");
142 return FALSE;
145 void mono_threads_platform_init (void)
149 void
150 mono_threads_platform_exit (gsize exit_code)
152 g_error ("WASM doesn't support threading");
155 gboolean
156 mono_threads_platform_in_critical_region (MonoNativeThreadId tid)
158 return FALSE;
161 G_EXTERN_C
162 extern void schedule_background_exec (void);
164 static GSList *jobs;
166 void
167 mono_threads_schedule_background_job (background_job_cb cb)
169 if (!jobs)
170 schedule_background_exec ();
172 if (!g_slist_find (jobs, (gconstpointer)cb))
173 jobs = g_slist_prepend (jobs, (gpointer)cb);
176 G_EXTERN_C
177 EMSCRIPTEN_KEEPALIVE void
178 mono_background_exec (void)
180 GSList *j = jobs, *cur;
181 jobs = NULL;
183 for (cur = j; cur; cur = cur->next) {
184 background_job_cb cb = (background_job_cb)cur->data;
185 cb ();
187 g_slist_free (j);
190 #endif