Repository navigation
[NFC] Update CallQueue to store function, arg pairs - #15648
Conversation
This is the first step toward decoupling the logic for proxying work to threads from the logic for creation and dispatch of `em_queued_call` objects, which couple a dynamically typed function pointer with its arguments. Decoupling these pieces will allow for more general proxying that is not required to use the `em_queued_call` mechanism and will simplify the code.
| // performed. | ||
| pthread_mutex_unlock(&call_queue_lock); | ||
| _do_call(q->call_queue[head]); | ||
| q->call_queue[head].func(q->call_queue[head].arg); |
There was a problem hiding this comment.
It worries me a little to do two subsequent reads here without holding the call queue lock. I think it should be safe as a single one was apparently safe to do before, and I think that is the case because this is the only place that removes things from the call queue - other threads only add, and they add after the head. Is that right?
There was a problem hiding this comment.
Yes, I think that's right. Notably the call queue head has not been updated yet, so any other thread trying to add things will see this as an occupied slot and will not write to it.
Can you elaborate on these two points? The em_queued_call object is/was not necessary to be accessed by end users already before this PR. The family of functions emscripten_sync_run_in_main_runtime_thread(sig, func_ptr, ...);
emscripten_async_run_in_main_runtime_thread(sig, func_ptr, ...);
emscripten_async_waitable_run_in_main_runtime_thread(sig, func_ptr, ...);
emscripten_dispatch_to_thread(target_thread, sig, func_ptr, satellite, ...);
emscripten_dispatch_to_thread_async(target_thread, sig, func_ptr, satellite, ...);should already offer a general API, and it does not have em_queued_call in it? (em_queued_call was originally placed as a public header for advanced users, but it might as well be an internal implementation detail) This PR (and the other related PRs) looks like it is not simplifying much, but adding more complexity? I admit I am currently a bit hazy on the benefit/need for this refactor, would like to understand the rationale behind this better? |
|
I'm lumping the |
…15648) This is the first step toward decoupling the logic for proxying work to threads from the logic for creation and dispatch of `em_queued_call` objects, which couple a dynamically typed function pointer with its arguments. Decoupling these pieces will allow for more general proxying that is not required to use the `em_queued_call` mechanism and will simplify the code.
This is the first step toward decoupling the logic for proxying work to threads
from the logic for creation and dispatch of
em_queued_callobjects, whichcouple a dynamically typed function pointer with its arguments. Decoupling these
pieces will allow for more general proxying that is not required to use the
em_queued_callmechanism and will simplify the code.