mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Auto merge of #8705 - jsanders:fix-sleep-ms-deprecations, r=metajack,Wafflespeanut
Use thread::sleep instead of deprecated sleep_ms Similarly, change one instance of `thread::park_timeout_ms`. Fixes #8694 <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8705) <!-- Reviewable:end -->
This commit is contained in:
commit
0f72049363
10 changed files with 65 additions and 25 deletions
|
@ -6,13 +6,15 @@
|
||||||
|
|
||||||
use compositor_task::{CompositorProxy, Msg};
|
use compositor_task::{CompositorProxy, Msg};
|
||||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||||
use std::thread::{Builder, sleep_ms};
|
use std::thread::{self, Builder};
|
||||||
|
use std::u32;
|
||||||
use time;
|
use time;
|
||||||
|
use util::time::duration_from_nanoseconds;
|
||||||
|
|
||||||
/// The amount of time in nanoseconds that we give to the painting thread to paint new tiles upon
|
/// The amount of time in nanoseconds that we give to the painting thread to paint new tiles upon
|
||||||
/// processing a scroll event that caused new tiles to be revealed. When this expires, we give up
|
/// processing a scroll event that caused new tiles to be revealed. When this expires, we give up
|
||||||
/// and composite anyway (showing a "checkerboard") to avoid dropping the frame.
|
/// and composite anyway (showing a "checkerboard") to avoid dropping the frame.
|
||||||
static TIMEOUT: i64 = 12_000_000;
|
static TIMEOUT: u64 = 12_000_000;
|
||||||
|
|
||||||
pub struct ScrollingTimerProxy {
|
pub struct ScrollingTimerProxy {
|
||||||
sender: Sender<ToScrollingTimerMsg>,
|
sender: Sender<ToScrollingTimerMsg>,
|
||||||
|
@ -55,9 +57,9 @@ impl ScrollingTimerProxy {
|
||||||
impl ScrollingTimer {
|
impl ScrollingTimer {
|
||||||
pub fn run(&mut self) {
|
pub fn run(&mut self) {
|
||||||
while let Ok(ToScrollingTimerMsg::ScrollEventProcessedMsg(timestamp)) = self.receiver.recv() {
|
while let Ok(ToScrollingTimerMsg::ScrollEventProcessedMsg(timestamp)) = self.receiver.recv() {
|
||||||
let target = timestamp as i64 + TIMEOUT;
|
let target = timestamp + TIMEOUT;
|
||||||
let delta_ns = target - (time::precise_time_ns() as i64);
|
let delta_ns = target - time::precise_time_ns();
|
||||||
sleep_ms((delta_ns / 1000000) as u32);
|
thread::sleep(duration_from_nanoseconds(delta_ns));
|
||||||
self.compositor_proxy.send(Msg::ScrollTimeout(timestamp));
|
self.compositor_proxy.send(Msg::ScrollTimeout(timestamp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@ use std::sync::Arc;
|
||||||
use std::sync::atomic::{self, AtomicBool};
|
use std::sync::atomic::{self, AtomicBool};
|
||||||
use std::sync::mpsc::{channel, Receiver, Select};
|
use std::sync::mpsc::{channel, Receiver, Select};
|
||||||
use std::thread::{self, spawn, Thread};
|
use std::thread::{self, spawn, Thread};
|
||||||
|
use std::time::Duration;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
|
||||||
/// A quick hack to work around the removal of [`std::old_io::timer::Timer`](
|
/// A quick hack to work around the removal of [`std::old_io::timer::Timer`](
|
||||||
|
@ -37,7 +38,7 @@ impl CancelableOneshotTimer {
|
||||||
let mut park_time = duration;
|
let mut park_time = duration;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
thread::park_timeout_ms(park_time.get() as u32);
|
thread::park_timeout(Duration::from_millis(park_time.get()));
|
||||||
|
|
||||||
if canceled_clone.load(atomic::Ordering::Relaxed) {
|
if canceled_clone.load(atomic::Ordering::Relaxed) {
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -16,7 +16,8 @@ use std::cell::RefCell;
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
use std::sync::mpsc::channel;
|
use std::sync::mpsc::channel;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use std::thread::sleep_ms;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
use util::task;
|
use util::task;
|
||||||
|
|
||||||
pub struct TimelineActor {
|
pub struct TimelineActor {
|
||||||
|
@ -116,7 +117,7 @@ impl Encodable for HighResolutionStamp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: u32 = 200; //ms
|
static DEFAULT_TIMELINE_DATA_PULL_TIMEOUT: u64 = 200; //ms
|
||||||
|
|
||||||
impl TimelineActor {
|
impl TimelineActor {
|
||||||
pub fn new(name: String,
|
pub fn new(name: String,
|
||||||
|
@ -158,7 +159,7 @@ impl TimelineActor {
|
||||||
}
|
}
|
||||||
emitter.send(markers);
|
emitter.send(markers);
|
||||||
|
|
||||||
sleep_ms(DEFAULT_TIMELINE_DATA_PULL_TIMEOUT);
|
thread::sleep(Duration::from_millis(DEFAULT_TIMELINE_DATA_PULL_TIMEOUT));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,8 +11,9 @@ use profile_traits::mem::{ProfilerChan, ProfilerMsg, ReportKind, Reporter, Repor
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::thread::sleep_ms;
|
use std::thread;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
use util::time::duration_from_seconds;
|
||||||
|
|
||||||
pub struct Profiler {
|
pub struct Profiler {
|
||||||
/// The port through which messages are received.
|
/// The port through which messages are received.
|
||||||
|
@ -31,11 +32,10 @@ impl Profiler {
|
||||||
|
|
||||||
// Create the timer thread if a period was provided.
|
// Create the timer thread if a period was provided.
|
||||||
if let Some(period) = period {
|
if let Some(period) = period {
|
||||||
let period_ms = (period * 1000.) as u32;
|
|
||||||
let chan = chan.clone();
|
let chan = chan.clone();
|
||||||
spawn_named("Memory profiler timer".to_owned(), move || {
|
spawn_named("Memory profiler timer".to_owned(), move || {
|
||||||
loop {
|
loop {
|
||||||
sleep_ms(period_ms);
|
thread::sleep(duration_from_seconds(period));
|
||||||
if chan.send(ProfilerMsg::Print).is_err() {
|
if chan.send(ProfilerMsg::Print).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,11 @@ use profile_traits::time::{TimerMetadataReflowType, TimerMetadataFrameType};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::f64;
|
use std::time::Duration;
|
||||||
use std::thread::sleep_ms;
|
use std::{thread, f64};
|
||||||
use std_time::precise_time_ns;
|
use std_time::precise_time_ns;
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
use util::time::duration_from_seconds;
|
||||||
|
|
||||||
pub trait Formattable {
|
pub trait Formattable {
|
||||||
fn format(&self) -> String;
|
fn format(&self) -> String;
|
||||||
|
@ -123,11 +124,10 @@ impl Profiler {
|
||||||
let (chan, port) = ipc::channel().unwrap();
|
let (chan, port) = ipc::channel().unwrap();
|
||||||
match period {
|
match period {
|
||||||
Some(period) => {
|
Some(period) => {
|
||||||
let period = (period * 1000.) as u32;
|
|
||||||
let chan = chan.clone();
|
let chan = chan.clone();
|
||||||
spawn_named("Time profiler timer".to_owned(), move || {
|
spawn_named("Time profiler timer".to_owned(), move || {
|
||||||
loop {
|
loop {
|
||||||
sleep_ms(period);
|
thread::sleep(duration_from_seconds(period));
|
||||||
if chan.send(ProfilerMsg::Print).is_err() {
|
if chan.send(ProfilerMsg::Print).is_err() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ impl Profiler {
|
||||||
loop {
|
loop {
|
||||||
for _ in 0..loop_count {
|
for _ in 0..loop_count {
|
||||||
match run_ap_thread() {
|
match run_ap_thread() {
|
||||||
true => sleep_ms(SLEEP_MS),
|
true => thread::sleep(Duration::from_millis(SLEEP_MS as u64)),
|
||||||
false => return,
|
false => return,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ pub mod task;
|
||||||
pub mod task_state;
|
pub mod task_state;
|
||||||
pub mod taskpool;
|
pub mod taskpool;
|
||||||
pub mod tid;
|
pub mod tid;
|
||||||
|
pub mod time;
|
||||||
pub mod vec;
|
pub mod vec;
|
||||||
pub mod workqueue;
|
pub mod workqueue;
|
||||||
|
|
||||||
|
|
32
components/util/time.rs
Normal file
32
components/util/time.rs
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
use std::time::Duration;
|
||||||
|
use std::{u32, u64};
|
||||||
|
|
||||||
|
pub const NANOS_PER_SEC: u32 = 1_000_000_000;
|
||||||
|
|
||||||
|
pub fn duration_from_seconds(secs: f64) -> Duration {
|
||||||
|
|
||||||
|
// Get number of seconds and check that it fits in a u64.
|
||||||
|
let whole_secs = secs.trunc();
|
||||||
|
assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64);
|
||||||
|
|
||||||
|
// Get number of nanoseconds. This should always fit in a u32, but check anyway.
|
||||||
|
let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc();
|
||||||
|
assert!(nanos >= 0.0 && nanos <= u32::MAX as f64);
|
||||||
|
|
||||||
|
Duration::new(whole_secs as u64, nanos as u32)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn duration_from_nanoseconds(nanos: u64) -> Duration {
|
||||||
|
// Get number of seconds.
|
||||||
|
let secs = nanos / NANOS_PER_SEC as u64;
|
||||||
|
|
||||||
|
// Get number of extra nanoseconds. This should always fit in a u32, but check anyway.
|
||||||
|
let subsec_nanos = nanos % NANOS_PER_SEC as u64;
|
||||||
|
assert!(subsec_nanos <= u32::MAX as u64);
|
||||||
|
|
||||||
|
Duration::new(secs, subsec_nanos as u32)
|
||||||
|
}
|
|
@ -38,7 +38,8 @@ use std::borrow::ToOwned;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
use std::sync::mpsc::Sender;
|
use std::sync::mpsc::Sender;
|
||||||
use std::thread::{self, sleep_ms};
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use util::prefs::{get_pref, reset_all_prefs, reset_pref, set_pref, PrefValue};
|
use util::prefs::{get_pref, reset_all_prefs, reset_pref, set_pref, PrefValue};
|
||||||
use util::task::spawn_named;
|
use util::task::spawn_named;
|
||||||
|
@ -228,7 +229,7 @@ impl Handler {
|
||||||
return Ok(x)
|
return Ok(x)
|
||||||
};
|
};
|
||||||
|
|
||||||
sleep_ms(interval);
|
thread::sleep(Duration::from_millis(interval));
|
||||||
};
|
};
|
||||||
|
|
||||||
Err(WebDriverError::new(ErrorStatus::Timeout,
|
Err(WebDriverError::new(ErrorStatus::Timeout,
|
||||||
|
@ -319,7 +320,7 @@ impl Handler {
|
||||||
let timeout = self.load_timeout;
|
let timeout = self.load_timeout;
|
||||||
let timeout_chan = sender;
|
let timeout_chan = sender;
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
sleep_ms(timeout);
|
thread::sleep(Duration::from_millis(timeout as u64));
|
||||||
let _ = timeout_chan.send(LoadStatus::LoadTimeout);
|
let _ = timeout_chan.send(LoadStatus::LoadTimeout);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -704,7 +705,7 @@ impl Handler {
|
||||||
break;
|
break;
|
||||||
};
|
};
|
||||||
|
|
||||||
sleep_ms(interval)
|
thread::sleep(Duration::from_millis(interval))
|
||||||
}
|
}
|
||||||
|
|
||||||
let img = match img {
|
let img = match img {
|
||||||
|
|
|
@ -298,7 +298,8 @@ impl Window {
|
||||||
|
|
||||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||||
fn handle_next_event(&self) -> bool {
|
fn handle_next_event(&self) -> bool {
|
||||||
use std::thread::sleep_ms;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
// TODO(gw): This is an awful hack to work around the
|
// TODO(gw): This is an awful hack to work around the
|
||||||
// broken way we currently call X11 from multiple threads.
|
// broken way we currently call X11 from multiple threads.
|
||||||
|
@ -324,7 +325,7 @@ impl Window {
|
||||||
self.handle_window_event(event)
|
self.handle_window_event(event)
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
sleep_ms(16);
|
thread::sleep(Duration::from_millis(16));
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
5
tests/reftest.rs
vendored
5
tests/reftest.rs
vendored
|
@ -25,7 +25,8 @@ use std::io::{self, Read, Result, Write};
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::process::{Command};
|
use std::process::{Command};
|
||||||
use std::thread::sleep_ms;
|
use std::thread;
|
||||||
|
use std::time::Duration;
|
||||||
use test::run_tests_console;
|
use test::run_tests_console;
|
||||||
use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn, ShouldPanic};
|
use test::{AutoColor, DynTestName, DynTestFn, TestDesc, TestOpts, TestDescAndFn, ShouldPanic};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -124,7 +125,7 @@ fn run(test_opts: TestOpts, all_tests: Vec<TestDescAndFn>,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Wait for the shell to launch or to fail
|
// Wait for the shell to launch or to fail
|
||||||
sleep_ms(1000);
|
thread::sleep(Duration::from_secs(1));
|
||||||
child.kill().unwrap();
|
child.kill().unwrap();
|
||||||
let output = try!(child.wait_with_output());
|
let output = try!(child.wait_with_output());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue