Make block_with_timeout more robust (#11670)

The previous implementation relied on a background thread to wake up the
main thread,
which was prone to priority inversion under heavy load.

In a synthetic test, where we spawn 200 git processes while doing a 5ms
timeout, the old version blocked for 5-80ms, the new version blocks for
5.1-5.4ms.

Release Notes:

- Improved responsiveness of the main thread under high system load
This commit is contained in:
Conrad Irwin 2024-05-10 13:10:02 -06:00 committed by GitHub
parent b34ab6f3a1
commit c73d6502d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 160 additions and 135 deletions

View file

@ -240,8 +240,7 @@ pub trait PlatformDispatcher: Send + Sync {
fn dispatch(&self, runnable: Runnable, label: Option<TaskLabel>);
fn dispatch_on_main_thread(&self, runnable: Runnable);
fn dispatch_after(&self, duration: Duration, runnable: Runnable);
fn tick(&self, background_only: bool) -> bool;
fn park(&self);
fn park(&self, timeout: Option<Duration>) -> bool;
fn unparker(&self) -> Unparker;
#[cfg(any(test, feature = "test-support"))]