mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-16 23:34:11 +00:00
Checkpoint
This commit is contained in:
parent
11b6d9e33a
commit
3f34a8e7ec
4 changed files with 14 additions and 31 deletions
|
@ -102,7 +102,7 @@ impl BackgroundExecutor {
|
|||
match future.as_mut().poll(&mut cx) {
|
||||
Poll::Ready(result) => return result,
|
||||
Poll::Pending => {
|
||||
if !self.dispatcher.poll() {
|
||||
if !self.dispatcher.poll(true) {
|
||||
if awoken.swap(false, SeqCst) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ pub trait PlatformDispatcher: Send + Sync {
|
|||
fn dispatch(&self, runnable: Runnable);
|
||||
fn dispatch_on_main_thread(&self, runnable: Runnable);
|
||||
fn dispatch_after(&self, duration: Duration, runnable: Runnable);
|
||||
fn poll(&self) -> bool;
|
||||
fn poll(&self, background_only: bool) -> bool;
|
||||
|
||||
#[cfg(any(test, feature = "test-support"))]
|
||||
fn as_test(&self) -> Option<&TestDispatcher> {
|
||||
|
|
|
@ -68,7 +68,7 @@ impl PlatformDispatcher for MacDispatcher {
|
|||
}
|
||||
}
|
||||
|
||||
fn poll(&self) -> bool {
|
||||
fn poll(&self, _background_only: bool) -> bool {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
@ -77,24 +77,3 @@ extern "C" fn trampoline(runnable: *mut c_void) {
|
|||
let task = unsafe { Runnable::from_raw(runnable as *mut ()) };
|
||||
task.run();
|
||||
}
|
||||
|
||||
// #include <dispatch/dispatch.h>
|
||||
|
||||
// int main(void) {
|
||||
|
||||
// dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
|
||||
// // Do some lengthy background work here...
|
||||
// printf("Background Work\n");
|
||||
|
||||
// dispatch_async(dispatch_get_main_queue(), ^{
|
||||
// // Once done, update your UI on the main queue here.
|
||||
// printf("UI Updated\n");
|
||||
|
||||
// });
|
||||
// });
|
||||
|
||||
// sleep(3); // prevent the program from terminating immediately
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
// ```
|
||||
|
|
|
@ -96,7 +96,7 @@ impl TestDispatcher {
|
|||
}
|
||||
|
||||
pub fn run_until_parked(&self) {
|
||||
while self.poll() {}
|
||||
while self.poll(false) {}
|
||||
}
|
||||
|
||||
pub fn parking_allowed(&self) -> bool {
|
||||
|
@ -160,7 +160,7 @@ impl PlatformDispatcher for TestDispatcher {
|
|||
state.delayed.insert(ix, (next_time, runnable));
|
||||
}
|
||||
|
||||
fn poll(&self) -> bool {
|
||||
fn poll(&self, background_only: bool) -> bool {
|
||||
let mut state = self.state.lock();
|
||||
|
||||
while let Some((deadline, _)) = state.delayed.first() {
|
||||
|
@ -171,11 +171,15 @@ impl PlatformDispatcher for TestDispatcher {
|
|||
state.background.push(runnable);
|
||||
}
|
||||
|
||||
let foreground_len: usize = state
|
||||
.foreground
|
||||
.values()
|
||||
.map(|runnables| runnables.len())
|
||||
.sum();
|
||||
let foreground_len: usize = if background_only {
|
||||
0
|
||||
} else {
|
||||
state
|
||||
.foreground
|
||||
.values()
|
||||
.map(|runnables| runnables.len())
|
||||
.sum()
|
||||
};
|
||||
let background_len = state.background.len();
|
||||
|
||||
if foreground_len == 0 && background_len == 0 {
|
||||
|
|
Loading…
Reference in a new issue