-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use thread::sleep instead of deprecated sleep_ms
Similarly, change one instance of `thread::park_timeout_ms`. Fixes #8694
- Loading branch information
Showing
10 changed files
with
65 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters