diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-10-27 18:06:43 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-10-27 18:06:43 -0600 |
commit | 9e94ecf99cff7c57275ab39c7b11870e55756d63 (patch) | |
tree | 53fd41d7defa2b32a83612700c39ba2a848cdd28 | |
parent | 005cfed6e99069e0d7f50414db7aab32411872a8 (diff) | |
parent | 293969cb7d0a97ad61f580d2e3f5f73b39740f71 (diff) | |
download | servo-9e94ecf99cff7c57275ab39c7b11870e55756d63.tar.gz servo-9e94ecf99cff7c57275ab39c7b11870e55756d63.zip |
auto merge of #3820 : cgaebel/servo/rebase-lalehs-patch, r=pcwalton
I addressed all but one of the code review comments, which was a request
for documentation on where a number came from (which I'm not qualified to
answer), and rebased this on to latest master.
xref: #3505 cc: @LalehB @larsbergstrom
r? @pcwalton
-rw-r--r-- | components/util/workqueue.rs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/components/util/workqueue.rs b/components/util/workqueue.rs index 3a0b3e32f91..8708d8585a6 100644 --- a/components/util/workqueue.rs +++ b/components/util/workqueue.rs @@ -16,6 +16,7 @@ use std::rand::weak_rng; use std::sync::atomics::{AtomicUint, SeqCst}; use std::sync::deque::{Abort, BufferPool, Data, Empty, Stealer, Worker}; use std::task::TaskBuilder; +use libc::funcs::posix88::unistd::usleep; /// A unit of work. /// @@ -70,7 +71,9 @@ struct WorkerThread<QueueData, WorkData> { rng: XorShiftRng, } -static SPIN_COUNT: uint = 1000; +static SPIN_COUNT: u32 = 128; +static SPINS_UNTIL_BACKOFF: u32 = 100; +static BACKOFF_INCREMENT_IN_US: u32 = 5; impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { /// The main logic. This function starts up the worker and listens for @@ -84,6 +87,8 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { ExitMsg => return, }; + let mut back_off_sleep = 0 as u32; + // We're off! // // FIXME(pcwalton): Can't use labeled break or continue cross-crate due to a Rust bug. @@ -107,10 +112,18 @@ impl<QueueData: Send, WorkData: Send> WorkerThread<QueueData, WorkData> { } Data(work) => { work_unit = work; + back_off_sleep = 0 as u32; break } } + if i > SPINS_UNTIL_BACKOFF { + unsafe { + usleep(back_off_sleep as u32); + } + back_off_sleep += BACKOFF_INCREMENT_IN_US; + } + if i == SPIN_COUNT { match self.port.try_recv() { Ok(StopMsg) => { |