[Proxying] Add proxying functions that return promises - #18825
Conversation
|
Current dependencies on/for this PR:
This comment was auto-generated by Graphite. |
1fe81f5 to
4baabe9
Compare
d34407a to
ef868fb
Compare
4baabe9 to
6a5e4e7
Compare
ef868fb to
7fe8414
Compare
6a5e4e7 to
5cb7113
Compare
7fe8414 to
961da1e
Compare
5cb7113 to
da1f95e
Compare
961da1e to
37d81c9
Compare
da1f95e to
289203e
Compare
37d81c9 to
5573a31
Compare
289203e to
2ef3195
Compare
5573a31 to
a2d0ef3
Compare
2ef3195 to
4ccf2ee
Compare
a2d0ef3 to
0fa4fc7
Compare
4ccf2ee to
1f0ecb4
Compare
0fa4fc7 to
a8184bf
Compare
1f0ecb4 to
af490a7
Compare
a8184bf to
c3b5047
Compare
af490a7 to
5415a72
Compare
c3b5047 to
c30ca68
Compare
sbc100
left a comment
There was a problem hiding this comment.
Looks like this needs a rebase?
c30ca68 to
2f1ddd5
Compare
|
@sbc100 this is ready for review. |
| q, target_thread, func, arg, promise, &block->ctx, &block->promise_ctx); | ||
| } | ||
|
|
||
| __attribute__((warn_unused_result)) em_promise_t |
There was a problem hiding this comment.
I don't think you need to (or should) duplicate these attributes in the .c file.
| promise_ctx promise_ctx; | ||
| task task; | ||
| }; | ||
| struct block* block = malloc(sizeof(*block)); |
There was a problem hiding this comment.
Where are these "blocks" freed? I don't see the block pointer escaping this function. Does it rely on ctx being free'd?
There was a problem hiding this comment.
Yes, it relies on ctx being freed, which happens in all the places free_ctx is called.
There was a problem hiding this comment.
Perhaps add a comment on the first eleemnt of the struct? e.g. // This struct is free'd via the ctx pointer so this must be the first element
|
|
||
| em_promise_result_t exit_thread(void** result, void* data, void* value) { | ||
| // TODO: exit the thread directly rather than on the next turn of the event | ||
| // loop. |
There was a problem hiding this comment.
Why is this a TODO?
Could we make this automatic (one day) and have the outstanding promises keep the thread alive and have the resolution of the final outstanding promise take the thread down?
There was a problem hiding this comment.
Trying to exit directly with pthread_exit does not work because that ends up throwing an exception to try to unwind, which in turn ends up rejecting the promise rather than gracefully exiting the thread.
Outstanding promises (at least those created with emscripten_promise_then) do keep the thread alive until their callbacks are executed, so this almost works. The only thing missing is that we don't use callUserCallback in the promise callbacks, so nothing actually checks the runtimeKeepAlive and exits. I'll fix that in a separate PR.
Add `emscripten_proxy_promise` and `emscripten_proxy_promise_with_ctx` that return `em_promise_t` handles to promises that are fulfilled when the proxied work is completed or rejected when the target thread dies before it can complete the work. Do not document these new APIs yet since they depend on the promise API in emscripten/promise.h, which is not yet documented. Similarly, do not add a C++ wrapper yet because emscripten/promise.h does not yet have a C++ API.
0bc125b to
c3c38e7
Compare
…re#18825) Add `emscripten_proxy_promise` and `emscripten_proxy_promise_with_ctx` that return `em_promise_t` handles to promises that are fulfilled when the proxied work is completed or rejected when the target thread dies before it can complete the work. Do not document these new APIs yet since they depend on the promise API in emscripten/promise.h, which is not yet documented. Similarly, do not add a C++ wrapper yet because emscripten/promise.h does not yet have a C++ API.
…re#18825) Add `emscripten_proxy_promise` and `emscripten_proxy_promise_with_ctx` that return `em_promise_t` handles to promises that are fulfilled when the proxied work is completed or rejected when the target thread dies before it can complete the work. Do not document these new APIs yet since they depend on the promise API in emscripten/promise.h, which is not yet documented. Similarly, do not add a C++ wrapper yet because emscripten/promise.h does not yet have a C++ API.

Add
emscripten_proxy_promiseandemscripten_proxy_promise_with_ctxthatreturn
em_promise_thandles to promises that are fulfilled when the proxiedwork is completed or rejected when the target thread dies before it can complete
the work.
Do not document these new APIs yet since they depend on the promise API in
emscripten/promise.h, which is not yet documented. Similarly, do not add a C++
wrapper yet because emscripten/promise.h does not yet have a C++ API.