-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[wasm-mt] A version of LowLevelLifoSemaphore that uses callbacks on t…
…he 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
- Loading branch information
1 parent
f107b4b
commit dcb34de
Showing
14 changed files
with
878 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.