From 86e5fb3ce7fd20694d4a18bb279dfc57d64c2eb7 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 22 Nov 2021 21:00:09 -0600 Subject: [PATCH] factored common code --- core/runtime/common.onyx | 17 +++++++++++++++++ core/runtime/js.onyx | 19 ++----------------- core/runtime/onyx_run.onyx | 19 ++----------------- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/core/runtime/common.onyx b/core/runtime/common.onyx index 997b7bc7..fe4f8fc8 100644 --- a/core/runtime/common.onyx +++ b/core/runtime/common.onyx @@ -54,3 +54,20 @@ __thread_initialize :: macro () { __stdio_init(); } +_thread_start :: (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) { + __tls_base = tls_base; + context.thread_id = id; + + __stack_top = raw_alloc(alloc.heap_allocator, 1 << 20); + __thread_initialize(); + + func(data); + + __flush_stdio(); +} + +_thread_exit :: (id: i32) { + raw_free(alloc.heap_allocator, __tls_base); + + thread.__exited(id); +} diff --git a/core/runtime/js.onyx b/core/runtime/js.onyx index 31a3700d..be24ba77 100644 --- a/core/runtime/js.onyx +++ b/core/runtime/js.onyx @@ -23,21 +23,6 @@ __exit :: (status: i32) -> void #foreign "host" "exit" --- __spawn_thread :: (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) -> bool #foreign "host" "spawn_thread" --- __kill_thread :: (id: i32) -> i32 #foreign "host" "kill_thread" --- - #export "_thread_start" (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) { - __tls_base = tls_base; - context.thread_id = id; - - __stack_top = raw_alloc(alloc.heap_allocator, 1 << 20); - __thread_initialize(); - - func(data); - - __flush_stdio(); - } - - #export "_thread_exit" (id: i32) { - raw_free(alloc.heap_allocator, __tls_base); - - thread.__exited(id); - } + #export "_thread_start" _thread_start + #export "_thread_exit" _thread_exit } diff --git a/core/runtime/onyx_run.onyx b/core/runtime/onyx_run.onyx index 69e6914f..8d924365 100644 --- a/core/runtime/onyx_run.onyx +++ b/core/runtime/onyx_run.onyx @@ -13,21 +13,6 @@ use package wasi __spawn_thread :: (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) -> bool #foreign "env" "spawn_thread" --- __kill_thread :: (id: i32) -> i32 #foreign "env" "kill_thread" --- - #export "_thread_start" (id: i32, tls_base: rawptr, func: (data: rawptr) -> void, data: rawptr) { - __tls_base = tls_base; - context.thread_id = id; - - __stack_top = raw_alloc(alloc.heap_allocator, 1 << 20); - __thread_initialize(); - - func(data); - - __flush_stdio(); - } - - #export "_thread_exit" (id: i32) { - raw_free(alloc.heap_allocator, __tls_base); - - thread.__exited(id); - } + #export "_thread_start" _thread_start + #export "_thread_exit" _thread_exit } -- 2.25.1