mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
win32: make sleep_microseconds for backoff just do a win32 Sleep(0)
This commit is contained in:
parent
025ed57c04
commit
5e136d6dd5
2 changed files with 24 additions and 3 deletions
|
@ -66,3 +66,6 @@ getopts = "0.2.11"
|
|||
hyper = { version = "0.7", optional = true }
|
||||
url = {version = "0.5.2", features = ["serde_serialization"]}
|
||||
uuid = "0.1.17"
|
||||
|
||||
[target.x86_64-pc-windows-gnu.dependencies]
|
||||
kernel32-sys = "0.1.4"
|
||||
|
|
|
@ -7,8 +7,13 @@
|
|||
//! Data associated with queues is simply a pair of unsigned integers. It is expected that a
|
||||
//! higher-level API on top of this could allow safe fork-join parallelism.
|
||||
|
||||
#[cfg(windows)]
|
||||
extern crate kernel32;
|
||||
|
||||
use deque::{Abort, BufferPool, Data, Empty, Stealer, Worker};
|
||||
use libc::usleep;
|
||||
#[cfg(not(windows))]
|
||||
use libc::funcs::posix88::unistd::usleep;
|
||||
use rand::{Rng, XorShiftRng, weak_rng};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::mpsc::{Receiver, Sender, channel};
|
||||
|
@ -92,6 +97,20 @@ fn next_power_of_two(mut v: u32) -> u32 {
|
|||
v
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn sleep_microseconds(usec: u32) {
|
||||
unsafe {
|
||||
usleep(usec);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn sleep_microseconds(_: u32) {
|
||||
unsafe {
|
||||
kernel32::Sleep(0);
|
||||
}
|
||||
}
|
||||
|
||||
impl<QueueData: Sync, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
||||
/// The main logic. This function starts up the worker and listens for
|
||||
/// messages.
|
||||
|
@ -151,9 +170,8 @@ impl<QueueData: Sync, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
|||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
usleep(back_off_sleep as u32);
|
||||
}
|
||||
sleep_microseconds(back_off_sleep);
|
||||
|
||||
back_off_sleep += BACKOFF_INCREMENT_IN_US;
|
||||
i = 0
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue