Skip to content

Commit

Permalink
CR
Browse files Browse the repository at this point in the history
  • Loading branch information
hedwigz committed Dec 18, 2024
1 parent ae2357d commit 97dff88
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
42 changes: 22 additions & 20 deletions system/lib/pthread/proxying.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

#include "em_task_queue.h"
#include "thread_mailbox.h"
Expand All @@ -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;
}
Expand Down Expand Up @@ -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*),
Expand Down Expand Up @@ -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(
Expand All @@ -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();
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
4 changes: 0 additions & 4 deletions tools/link.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]

Expand Down

0 comments on commit 97dff88

Please sign in to comment.