Skip to content

Remove unused (and unusable) emscripten_sync_run_in_main_thread API. #18580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions site/source/docs/api_reference/wasm_workers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ In order to enable flexible synchronous execution of code on other threads, and
APIs for example for MEMFS filesystem and Offscreen Framebuffer (WebGL emulated from a Worker) features,
main browser thread and each pthread have a system-backed "proxy message queue" to receive messages.

This enables user code to call API functions ``emscripten_sync_run_in_main_thread*()``,
``emscripten_sync_run_in_main_runtime_thread()``, ``emscripten_async_run_in_main_runtime_thread()``,
``emscripten_dispatch_to_thread()``, etc. from ``emscripten/threading.h`` to perform proxied calls.
This enables user code to call API functions, ``emscripten_sync_run_in_main_runtime_thread()``,
``emscripten_async_run_in_main_runtime_thread()``, ``emscripten_dispatch_to_thread()``, etc. from
``emscripten/threading.h`` to perform proxied calls.

Wasm Workers do not provide this functionality. If needed, such messaging should be implemented manually
by users via regular multithreaded synchronized programming techniques (mutexes, futexes, semaphores, etc.)
Expand Down
1 change: 0 additions & 1 deletion src/struct_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,6 @@
"file": "emscripten/threading.h",
"defines": [
"EM_PROXIED_RESIZE_OFFSCREENCANVAS",
"EM_QUEUED_JS_CALL_MAX_ARGS",
"EM_FUNC_SIG_V",
"EM_FUNC_SIG_VI",
"EM_FUNC_SIG_VII",
Expand Down
6 changes: 6 additions & 0 deletions src/struct_info_internal.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@
"SIGCANCEL"
]
},
{
"file": "threading_internal.h",
"defines": [
"EM_QUEUED_JS_CALL_MAX_ARGS"
]
},
{
"file": "dynlink.h",
"structs": {
Expand Down
11 changes: 0 additions & 11 deletions system/include/emscripten/threading.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,8 @@ int emscripten_futex_wait(volatile void/*uint32_t*/ *addr, uint32_t val, double
// INT_MAX to wake all waiters on that location.
int emscripten_futex_wake(volatile void/*uint32_t*/ *addr, int count);

// Proxied JS function can support a few more arguments than proxied C/C++
// functions, because the dispatch is variadic and signature independent.
#define EM_QUEUED_JS_CALL_MAX_ARGS 20

typedef struct em_queued_call em_queued_call;

void emscripten_sync_run_in_main_thread(em_queued_call *call);
void *emscripten_sync_run_in_main_thread_0(int function);
void *emscripten_sync_run_in_main_thread_1(int function, void *arg1);
void *emscripten_sync_run_in_main_thread_2(int function, void *arg1, void *arg2);
void *emscripten_sync_run_in_main_thread_3(int function, void *arg1, void *arg2, void *arg3);
void *emscripten_sync_run_in_main_thread_7(int function, void *arg1, void *arg2, void *arg3, void *arg4, void *arg5, void *arg6, void *arg7);

// Encode function signatures into a single uint32_t integer.
// N.B. This encoding scheme is internal to the implementation, and can change
// in the future. Do not depend on the exact numbers in this scheme.
Expand Down
96 changes: 3 additions & 93 deletions system/lib/pthread/library_pthread.c
Original file line number Diff line number Diff line change
Expand Up @@ -395,103 +395,13 @@ void emscripten_async_run_in_main_thread(em_queued_call* call) {
do_dispatch_to_thread(emscripten_main_browser_thread_id(), call);
}

void emscripten_sync_run_in_main_thread(em_queued_call* call) {
static void sync_run_in_main_thread(em_queued_call* call) {
emscripten_async_run_in_main_thread(call);

// Enter to wait for the operation to complete.
emscripten_wait_for_call_v(call, INFINITY);
}

void* emscripten_sync_run_in_main_thread_0(int function) {
em_queued_call q = {function};
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_1(int function, void* arg1) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_2(
int function, void* arg1, void* arg2) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_3(
int function, void* arg1, void* arg2, void* arg3) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.args[2].vp = arg3;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_4(
int function, void* arg1, void* arg2, void* arg3, void* arg4) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.args[2].vp = arg3;
q.args[3].vp = arg4;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_5(
int function, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.args[2].vp = arg3;
q.args[3].vp = arg4;
q.args[4].vp = arg5;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_6(
int function, void* arg1, void* arg2, void* arg3, void* arg4, void* arg5, void* arg6) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.args[2].vp = arg3;
q.args[3].vp = arg4;
q.args[4].vp = arg5;
q.args[5].vp = arg6;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void* emscripten_sync_run_in_main_thread_7(int function, void* arg1,
void* arg2, void* arg3, void* arg4, void* arg5, void* arg6, void* arg7) {
em_queued_call q = {function};
q.args[0].vp = arg1;
q.args[1].vp = arg2;
q.args[2].vp = arg3;
q.args[3].vp = arg4;
q.args[4].vp = arg5;
q.args[5].vp = arg6;
q.args[6].vp = arg7;
q.returnValue.vp = 0;
emscripten_sync_run_in_main_thread(&q);
return q.returnValue.vp;
}

void emscripten_current_thread_process_queued_calls() {
emscripten_proxy_execute_queue(emscripten_proxy_get_system_queue());
}
Expand All @@ -508,7 +418,7 @@ int emscripten_sync_run_in_main_runtime_thread_(EM_FUNC_SIGNATURE sig, void* fun
va_start(args, func_ptr);
init_em_queued_call_args(&q, sig, args);
va_end(args);
emscripten_sync_run_in_main_thread(&q);
sync_run_in_main_thread(&q);
return q.returnValue.i;
}

Expand Down Expand Up @@ -537,7 +447,7 @@ double emscripten_run_in_main_runtime_thread_js(int index, int num_args, int64_t
}

if (sync) {
emscripten_sync_run_in_main_thread(&q);
sync_run_in_main_thread(&q);
// TODO: support BigInt return values somehow.
return q.returnValue.d;
} else {
Expand Down
5 changes: 5 additions & 0 deletions system/lib/pthread/threading_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ typedef union em_variant_val
char *cp;
} em_variant_val;

// Proxied JS function can support a few more arguments than proxied C/C++
// functions, because the dispatch is variadic and signature independent.
#define EM_QUEUED_JS_CALL_MAX_ARGS 20

// Proxied C/C++ functions support at most this many arguments. Dispatch is
// static/strongly typed by signature.
#define EM_QUEUED_CALL_MAX_ARGS 11

typedef struct em_queued_call
{
int functionEnum;
Expand Down