mirror of
https://github.com/servo/servo.git
synced 2025-07-19 13:23:46 +01:00
Auto merge of #22094 - asajeffrey:magicleap-shutdown, r=paulrouget
Shut down Servo when the ML app quits <!-- Please describe your changes on the following line: --> Shut down servo when shutting down the magic leap app. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes do not require tests because we don't test ML <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- 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/22094) <!-- Reviewable:end -->
This commit is contained in:
commit
e265fcfc3c
2 changed files with 27 additions and 5 deletions
|
@ -47,6 +47,9 @@ use std::os::raw::c_char;
|
|||
use std::os::raw::c_void;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use std::time::Instant;
|
||||
|
||||
#[repr(u32)]
|
||||
pub enum MLLogLevel {
|
||||
|
@ -294,11 +297,30 @@ pub unsafe extern "C" fn navigate_servo(servo: *mut ServoInstance, text: *const
|
|||
}
|
||||
}
|
||||
|
||||
// Some magic numbers for shutdown
|
||||
const SHUTDOWN_DURATION: Duration = Duration::from_secs(10);
|
||||
const SHUTDOWN_POLL_INTERVAL: Duration = Duration::from_millis(100);
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn discard_servo(servo: *mut ServoInstance) {
|
||||
// Servo drop goes here!
|
||||
if !servo.is_null() {
|
||||
Box::from_raw(servo);
|
||||
if let Some(servo) = servo.as_mut() {
|
||||
let mut servo = Box::from_raw(servo);
|
||||
let finish = Instant::now() + SHUTDOWN_DURATION;
|
||||
servo.servo.handle_events(vec![WindowEvent::Quit]);
|
||||
'outer: loop {
|
||||
for (_, msg) in servo.servo.get_events() {
|
||||
if let EmbedderMsg::Shutdown = msg {
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
if Instant::now() > finish {
|
||||
warn!("Incomplete shutdown.");
|
||||
break 'outer;
|
||||
}
|
||||
thread::sleep(SHUTDOWN_POLL_INTERVAL);
|
||||
servo.servo.handle_events(vec![]);
|
||||
}
|
||||
servo.servo.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,8 +59,6 @@ Servo2D::Servo2D() {
|
|||
// Destroy a Servo 2D instance
|
||||
Servo2D::~Servo2D() {
|
||||
ML_LOG(Debug, "Servo2D Destructor.");
|
||||
discard_servo(servo_);
|
||||
servo_ = nullptr;
|
||||
}
|
||||
|
||||
// The prism dimensions
|
||||
|
@ -168,6 +166,8 @@ int Servo2D::init() {
|
|||
|
||||
int Servo2D::deInit() {
|
||||
ML_LOG(Debug, "Servo2D Deinitializing.");
|
||||
discard_servo(servo_);
|
||||
servo_ = nullptr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue