From 97dff881c135f52ee8c73dd52c613793d4ba1e1a Mon Sep 17 00:00:00 2001 From: Amit Shani Date: Wed, 18 Dec 2024 22:36:56 +0200 Subject: [PATCH] CR --- system/lib/pthread/proxying.c | 42 ++++++++++++++++++----------------- tools/link.py | 4 ---- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/system/lib/pthread/proxying.c b/system/lib/pthread/proxying.c index dee9535dfc213..ba2ec7fff43a2 100644 --- a/system/lib/pthread/proxying.c +++ b/system/lib/pthread/proxying.c @@ -13,7 +13,6 @@ #include #include #include -#include #include "em_task_queue.h" #include "thread_mailbox.h" @@ -36,17 +35,6 @@ static em_proxying_queue system_proxying_queue = { .capacity = 0, }; -typedef struct proxied_js_func_t { - int funcIndex; - void* emAsmAddr; - pthread_t callingThread; - int numArgs; - double* argBuffer; - double result; - bool owned; - em_proxying_ctx * ctx; -} proxied_js_func_t; - em_proxying_queue* emscripten_proxy_get_system_queue(void) { return &system_proxying_queue; } @@ -409,13 +397,6 @@ static void call_then_finish_task(em_proxying_ctx* ctx, void* arg) { emscripten_proxy_finish(ctx); } -static void call_proxied_js_task_with_ctx(em_proxying_ctx* ctx, void* arg) { - task* t = arg; - proxied_js_func_t* p = t->arg; - p->ctx = ctx; - t->func(t->arg); -} - int emscripten_proxy_sync(em_proxying_queue* q, pthread_t target_thread, void (*func)(void*), @@ -602,6 +583,19 @@ em_promise_t emscripten_proxy_promise(em_proxying_queue* q, &block->promise_ctx); } +typedef struct proxied_js_func_t { + int funcIndex; + void* emAsmAddr; + pthread_t callingThread; + int numArgs; + double* argBuffer; + double result; + bool owned; + // Only used when the underlying js func is async. + // Can be null when the function is sync. + em_proxying_ctx * ctx; +} proxied_js_func_t; + static void run_js_func(void* arg) { proxied_js_func_t* f = (proxied_js_func_t*)arg; f->result = _emscripten_receive_on_main_thread_js( @@ -624,6 +618,7 @@ double _emscripten_run_on_main_thread_js(int func_index, .numArgs = num_args, .argBuffer = buffer, .owned = false, + .ctx = NULL, }; em_proxying_queue* q = emscripten_proxy_get_system_queue(); @@ -652,6 +647,13 @@ double _emscripten_run_on_main_thread_js(int func_index, return 0; } +static void call_proxied_js_task_with_ctx(em_proxying_ctx* ctx, void* arg) { + task* t = arg; + proxied_js_func_t* p = t->arg; + p->ctx = ctx; + t->func(t->arg); +} + double _emscripten_await_on_main_thread_js(int func_index, void* em_asm_addr, int num_args, @@ -681,4 +683,4 @@ void _emscripten_proxy_promise_finish(em_proxying_ctx* ctx, void* res) { proxied_js_func_t* func = (proxied_js_func_t*)t->arg; func->result = (double)(intptr_t)res; emscripten_proxy_finish(ctx); -} \ No newline at end of file +} diff --git a/tools/link.py b/tools/link.py index dfbbd09c17e33..132708c730721 100644 --- a/tools/link.py +++ b/tools/link.py @@ -499,10 +499,6 @@ def setup_pthreads(): settings.REQUIRED_EXPORTS += [ '_emscripten_thread_free_data', '_emscripten_thread_crashed', - 'emscripten_main_runtime_thread_id', - 'emscripten_main_thread_process_queued_calls', - '_emscripten_run_on_main_thread_js', - '_emscripten_await_on_main_thread_js', '_emscripten_proxy_promise_finish', ]