Skip to content

Commit

Permalink
Make _emscripten_run_callback_on_thread asynchronous
Browse files Browse the repository at this point in the history
...fixing a regression introduced in c41f659
"Remove use of legacy proxy API from library_html5.js. NFC (emscripten-core#20370)".

Fixes: emscripten-core#22442

(cherry-picked from 17f1bb7 at
<emscripten-core#22443> "Make
_emscripten_run_callback_on_thread asynchronous")
  • Loading branch information
stbergmann committed Sep 18, 2024
1 parent 7f8a05d commit ef06346
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions system/lib/html5/callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef struct callback_args_t {
static void do_callback(void* arg) {
callback_args_t* args = (callback_args_t*)arg;
args->callback(args->event_type, args->event_data, args->user_data);
free(arg);
}

void _emscripten_run_callback_on_thread(pthread_t t,
Expand All @@ -29,14 +30,13 @@ void _emscripten_run_callback_on_thread(pthread_t t,
void* event_data,
void* user_data) {
em_proxying_queue* q = emscripten_proxy_get_system_queue();
callback_args_t arg = {
.callback = f,
.event_type = event_type,
.event_data = event_data,
.user_data = user_data,
};
callback_args_t* arg = malloc(sizeof(callback_args_t));
arg->callback = f;
arg->event_type = event_type;
arg->event_data = event_data;
arg->user_data = user_data;

if (!emscripten_proxy_sync(q, t, do_callback, &arg)) {
assert(false && "emscripten_proxy_sync failed");
if (!emscripten_proxy_async(q, t, do_callback, arg)) {
assert(false && "emscripten_proxy_async failed");
}
}

0 comments on commit ef06346

Please sign in to comment.