Skip to content

Use global TLS variable in proxying.c. NFC #24596

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
Jun 17, 2025
Merged
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
11 changes: 6 additions & 5 deletions system/lib/pthread/proxying.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ static em_task_queue* get_or_add_tasks_for_thread(em_proxying_queue* q,
return tasks;
}

static _Thread_local bool executing_system_queue = false;

void emscripten_proxy_execute_queue(em_proxying_queue* q) {
assert(q != NULL);
assert(pthread_self());
Expand All @@ -114,13 +116,12 @@ void emscripten_proxy_execute_queue(em_proxying_queue* q) {
// pthread_lock call below that executes the system queue. The per-task_queue
// recursion lock can't catch these recursions because it can only be checked
// after the lock has been acquired.
static _Thread_local int executing_system_queue = 0;
int is_system_queue = q == &system_proxying_queue;
bool is_system_queue = q == &system_proxying_queue;
if (is_system_queue) {
if (executing_system_queue) {
return;
}
executing_system_queue = 1;
executing_system_queue = true;
}

pthread_mutex_lock(&q->mutex);
Expand All @@ -133,7 +134,7 @@ void emscripten_proxy_execute_queue(em_proxying_queue* q) {
}

if (is_system_queue) {
executing_system_queue = 0;
executing_system_queue = false;
}
}

Expand Down Expand Up @@ -607,7 +608,7 @@ double _emscripten_run_on_main_thread_js(int func_index,
void* em_asm_addr,
int num_args,
double* buffer,
int sync) {
bool sync) {
proxied_js_func_t f = {
.funcIndex = func_index,
.emAsmAddr = em_asm_addr,
Expand Down