mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #18777 - mateon1:perf/headless-event-poll, r=jdm
Improved headless Servo performance Now the main thread doesn't waste 100% CPU, polling for events. --- - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #18770 (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because: I verified Servo works correctly in headless mode, and the linked issue is gone. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18777) <!-- Reviewable:end -->
This commit is contained in:
commit
54f6e87939
1 changed files with 9 additions and 1 deletions
|
@ -39,6 +39,8 @@ use std::mem;
|
|||
use std::os::raw::c_void;
|
||||
use std::ptr;
|
||||
use std::rc::Rc;
|
||||
use std::thread;
|
||||
use std::time;
|
||||
use style_traits::DevicePixel;
|
||||
use style_traits::cursor::Cursor;
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -684,7 +686,13 @@ impl Window {
|
|||
close_event = self.handle_window_event(event) || close_event;
|
||||
}
|
||||
}
|
||||
WindowKind::Headless(..) => {}
|
||||
WindowKind::Headless(..) => {
|
||||
// Sleep the main thread to avoid using 100% CPU
|
||||
// This can be done better, see comments in #18777
|
||||
if events.is_empty() {
|
||||
thread::sleep(time::Duration::from_millis(5));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
close_event = self.handle_next_event();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue