Skip to content

[NFC] Update CallQueue to store function, arg pairs - #15648

Merged
tlively merged 1 commit into
mainfrom
proxying-cleanup-1-callqueue-pairs
Dec 2, 2021
Merged

tlively merged 1 commit into
mainfrom
proxying-cleanup-1-callqueue-pairs

Conversation

@tlively

@tlively tlively commented Nov 29, 2021

Copy link
Copy Markdown
Member

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_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.
@tlively tlively closed this Dec 1, 2021
@tlively tlively reopened this Dec 1, 2021
@tlively
tlively marked this pull request as ready for review December 1, 2021 18:06
@tlively
tlively requested a review from kripken December 1, 2021 18:07
// performed.
pthread_mutex_unlock(&call_queue_lock);
_do_call(q->call_queue[head]);
q->call_queue[head].func(q->call_queue[head].arg);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@kripken
kripken requested a review from juj December 1, 2021 19:23
@tlively
tlively enabled auto-merge (squash) December 2, 2021 17:20
@tlively
tlively merged commit 6449cd9 into main Dec 2, 2021
@tlively
tlively deleted the proxying-cleanup-1-callqueue-pairs branch December 2, 2021 17:40
@juj

juj commented Dec 9, 2021 •

Copy link
Copy Markdown
Collaborator

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.

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?

@tlively

tlively commented Dec 9, 2021

Copy link
Copy Markdown
Member Author

I'm lumping the sig and satellite arguments to those functions in with the em_queued_call mechanism. IMO the implementation is cleaner when the work queue management logic is decoupled from the the em_queued_call logic, including the use of sig arguments to create em_queued_calls internally. By layering the logic, each individual function is simpler.

mmarczell-graphisoft pushed a commit to GRAPHISOFT/emscripten that referenced this pull request Jan 5, 2022
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants