mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Auto merge of #11132 - mbrubeck:workqueue-panic, r=larsbergstrom
Fix integer overflow in next_power_of_two This causes a panic (debug) or incorrect results (release) when initializing a work queue with thread_count = 1. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11132) <!-- Reviewable:end -->
This commit is contained in:
commit
695a2559a8
1 changed files with 1 additions and 12 deletions
|
@ -85,17 +85,6 @@ const SPINS_UNTIL_BACKOFF: u32 = 128;
|
|||
const BACKOFF_INCREMENT_IN_US: u32 = 5;
|
||||
const BACKOFFS_UNTIL_CONTROL_CHECK: u32 = 6;
|
||||
|
||||
fn next_power_of_two(mut v: u32) -> u32 {
|
||||
v -= 1;
|
||||
v |= v >> 1;
|
||||
v |= v >> 2;
|
||||
v |= v >> 4;
|
||||
v |= v >> 8;
|
||||
v |= v >> 16;
|
||||
v += 1;
|
||||
v
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn sleep_microseconds(usec: u32) {
|
||||
unsafe {
|
||||
|
@ -114,7 +103,7 @@ impl<QueueData: Sync, WorkData: Send> WorkerThread<QueueData, WorkData> {
|
|||
/// The main logic. This function starts up the worker and listens for
|
||||
/// messages.
|
||||
fn start(&mut self) {
|
||||
let deque_index_mask = next_power_of_two(self.other_deques.len() as u32) - 1;
|
||||
let deque_index_mask = (self.other_deques.len() as u32).next_power_of_two() - 1;
|
||||
loop {
|
||||
// Wait for a start message.
|
||||
let (mut deque, ref_count, queue_data) = match self.port.recv().unwrap() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue