You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[wasm-mt] A version of LowLevelLifoSemaphore that uses callbacks on the browser (#84491)
This is part of #84489 - landing support for async JS interop on threadpool threads in multi-threaded WebAssembly.
This PR adds two things:
1. A new unmanaged `LifoSemaphoreAsyncWait` semaphore that can use Emscripten's ability to push C calls from one thread to another in order to implement a callback-based semaphore - when a thread wants to wait, it sets up a success callback and a timeout callback, and then can return to the JS event loop. When the semaphore is released, Emscripten will trigger the callback to run on the waiting thread. If the wait times out, the timeout callback will run.
2. A new managed `LowLevelLifoAsyncWaitSemaphore` that doesn't have the normal `Wait()` function, and instead needs to use the callback-based `PrepareAsyncWait()` function. Also refactored `LowLevelLifoSemaphore` to pull out a common `LowLevelLifoSemaphoreBase` class to share with the async wait version.
* [wasm-mt][mono] Add new LifoSemaphoreAsyncWait C primitive
Add a new kind of LifoSemaphore that has a callback-based wait
function, instead of a blocking wait using Emscripten's ability to
send work from one webworker to another in C.
This will allow us to wait for a semaphore from the JS event loop in a
web worker.
* [wasm-mt][mono] split LowLevelLifoSemaphore into two kinds
A normal LowLevelLifoSemaphore that can do a synchronous wait
and another that can do a callback-based wait from the JS event loop
* Add LowLevelLifoSemaphoreBase
Move the counts to the base class
Move Release to the base class, make ReleaseCore abstract
* make a new LowLevelLifoAsyncWaitSemaphore for wasm-mt
* Revert unintentional package-lock.json changes
* fix possible null dereference
* use a separate icall for async wait InitInternal
instead of magic constants that are otherwise not needed in managed
* remove dead code; fixup comments
* LowLevelLifoSemaphore: decrement timeoutMs if we lost InterlockedCompareExchange
When a thread wakes after waiting for a semaphore to be released, if
it raced with another thread that is also trying to update the
semaphore counts and loses, it has to go back to waiting again.
In that case, decrement the remaining timeout by the elapsed wait time
so that the next wait is shorter.
* better timeout decrement code
* move timeoutMs == 0 check to PrepareAsyncWaitCore
make PrepareAsyncWaitCore static and remove a redundant argument
0 commit comments