mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 03:15:11 +00:00
No bug - Update num_cpus to try to fix bustage. r=me
On a CLOSED TREE MozReview-Commit-ID: KxCbwtGxZnO
This commit is contained in:
parent
3d130f41d4
commit
6821b4e553
6
js/src/Cargo.lock
generated
6
js/src/Cargo.lock
generated
@ -25,12 +25,12 @@ version = "0.0.0"
|
||||
dependencies = [
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libz-sys 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.2.1"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -50,6 +50,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
"checksum gcc 0.3.42 (registry+https://github.com/rust-lang/crates.io-index)" = "291055c78f59ca3d84c99026c9501c469413d386bb46be1e1cf1d285cd1db3b0"
|
||||
"checksum libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)" = "38f5c2b18a287cf78b4097db62e20f43cace381dc76ae5c0a3073067f78b7ddc"
|
||||
"checksum libz-sys 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "3fdd64ef8ee652185674455c1d450b83cbc8ad895625d543b5324d923f82e4d8"
|
||||
"checksum num_cpus 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a225d1e2717567599c24f88e49f00856c6e825a12125181ee42c4257e3688d39"
|
||||
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
|
||||
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
|
||||
"checksum vcpkg 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9e0a7d8bed3178a8fb112199d466eeca9ed09a14ba8ad67718179b4fd5487d0b"
|
||||
|
16
third_party/rust/num_cpus-1.6.2/.appveyor.yml
vendored
Normal file
16
third_party/rust/num_cpus-1.6.2/.appveyor.yml
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
environment:
|
||||
matrix:
|
||||
- TARGET: x86_64-pc-windows-msvc
|
||||
- TARGET: i686-pc-windows-msvc
|
||||
- TARGET: x86_64-pc-windows-gnu
|
||||
- TARGET: i686-pc-windows-gnu
|
||||
install:
|
||||
- curl -sSf -o rustup-init.exe https://win.rustup.rs/
|
||||
- rustup-init.exe -y --default-host %TARGET%
|
||||
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
|
||||
- rustc -vV
|
||||
- cargo -vV
|
||||
build: false
|
||||
test_script:
|
||||
- cargo build --verbose
|
||||
- cargo test --verbose
|
1
third_party/rust/num_cpus-1.6.2/.cargo-checksum.json
vendored
Normal file
1
third_party/rust/num_cpus-1.6.2/.cargo-checksum.json
vendored
Normal file
@ -0,0 +1 @@
|
||||
{"files":{".appveyor.yml":"2f3f82a91e82a6c0b601048a5c9cd9b39fa78dfb7172ecfe7ff3d4d010af66d8",".travis.yml":"979eec484d5ceb95a6553860cafa053694613fbafda322e6d159cfab261d99a0","Cargo.toml":"64af5f893e89e09be28f21857fb4238ddc63cf12f012a6f59c1a404db3f96284","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"0593d22d122d4bfec6407115e3907546312976f75473417aaa4c57ecd2095ae6","README.md":"4d586d8185ea43e6472db25ad748da265024869eabdcd62805c2bf3de06c4eb4","src/lib.rs":"295224974716d3ac2cd3d9f65764bae2ec92d94c01f939f62cf3b00974bb3e63"},"package":"aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"}
|
20
third_party/rust/num_cpus-1.6.2/.travis.yml
vendored
Normal file
20
third_party/rust/num_cpus-1.6.2/.travis.yml
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
language: rust
|
||||
rust:
|
||||
- stable
|
||||
- beta
|
||||
- nightly
|
||||
|
||||
sudo: false
|
||||
|
||||
cache:
|
||||
apt: true
|
||||
directories:
|
||||
- target/debug/deps
|
||||
- target/debug/build
|
||||
|
||||
script:
|
||||
- cargo build --verbose
|
||||
- cargo test --verbose
|
||||
|
||||
notifications:
|
||||
email: false
|
24
third_party/rust/num_cpus-1.6.2/Cargo.toml
vendored
Normal file
24
third_party/rust/num_cpus-1.6.2/Cargo.toml
vendored
Normal file
@ -0,0 +1,24 @@
|
||||
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
|
||||
#
|
||||
# When uploading crates to the registry Cargo will automatically
|
||||
# "normalize" Cargo.toml files for maximal compatibility
|
||||
# with all versions of Cargo and also rewrite `path` dependencies
|
||||
# to registry (e.g. crates.io) dependencies
|
||||
#
|
||||
# If you believe there's an error in this file please file an
|
||||
# issue against the rust-lang/cargo repository. If you're
|
||||
# editing this file be aware that the upstream Cargo.toml
|
||||
# will likely look very different (and much more reasonable)
|
||||
|
||||
[package]
|
||||
name = "num_cpus"
|
||||
version = "1.6.2"
|
||||
authors = ["Sean McArthur <sean.monstar@gmail.com>"]
|
||||
description = "Get the number of CPUs on a machine."
|
||||
documentation = "https://docs.rs/num_cpus"
|
||||
keywords = ["cpu", "cpus", "cores"]
|
||||
categories = ["hardware-support"]
|
||||
license = "MIT/Apache-2.0"
|
||||
repository = "https://github.com/seanmonstar/num_cpus"
|
||||
[dependencies.libc]
|
||||
version = "0.2.6"
|
201
third_party/rust/num_cpus-1.6.2/LICENSE-APACHE
vendored
Normal file
201
third_party/rust/num_cpus-1.6.2/LICENSE-APACHE
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
20
third_party/rust/num_cpus-1.6.2/LICENSE-MIT
vendored
Normal file
20
third_party/rust/num_cpus-1.6.2/LICENSE-MIT
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
Copyright (c) 2015
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
42
third_party/rust/num_cpus-1.6.2/README.md
vendored
Normal file
42
third_party/rust/num_cpus-1.6.2/README.md
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
# num_cpus
|
||||
|
||||
[![crates.io](http://meritbadge.herokuapp.com/num_cpus)](https://crates.io/crates/num_cpus)
|
||||
[![Travis CI Status](https://travis-ci.org/seanmonstar/num_cpus.svg?branch=master)](https://travis-ci.org/seanmonstar/num_cpus)
|
||||
[![AppVeyor status](https://ci.appveyor.com/api/projects/status/qn8t6grhko5jwno6?svg=true)](https://ci.appveyor.com/project/seanmonstar/num-cpus)
|
||||
|
||||
[Documentation](https://docs.rs/num_cpus)
|
||||
|
||||
Count the number of CPUs on the current machine.
|
||||
|
||||
## Usage
|
||||
|
||||
Add to Cargo.toml:
|
||||
|
||||
```toml
|
||||
[dependencies]
|
||||
num_cpus = "1.0"
|
||||
```
|
||||
|
||||
In your `main.rs` or `lib.rs`:
|
||||
|
||||
```rust
|
||||
extern crate num_cpus;
|
||||
|
||||
// elsewhere
|
||||
let num = num_cpus::get();
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
Licensed under either of
|
||||
|
||||
* Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
|
||||
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
|
||||
|
||||
at your option.
|
||||
|
||||
### Contribution
|
||||
|
||||
Unless you explicitly state otherwise, any contribution intentionally submitted
|
||||
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any
|
||||
additional terms or conditions.
|
316
third_party/rust/num_cpus-1.6.2/src/lib.rs
vendored
Normal file
316
third_party/rust/num_cpus-1.6.2/src/lib.rs
vendored
Normal file
@ -0,0 +1,316 @@
|
||||
//! # num_cpus
|
||||
//!
|
||||
//! A crate with utilities to determine the number of CPUs available on the
|
||||
//! current system.
|
||||
//!
|
||||
//! ## Example
|
||||
//!
|
||||
//! ```
|
||||
//! let cpus = num_cpus::get();
|
||||
//! ```
|
||||
#![cfg_attr(test, deny(warnings))]
|
||||
#![deny(missing_docs)]
|
||||
#![allow(non_snake_case)]
|
||||
|
||||
#[cfg(not(windows))]
|
||||
extern crate libc;
|
||||
|
||||
/// Returns the number of available CPUs of the current system.
|
||||
///
|
||||
/// # Note
|
||||
///
|
||||
/// This will check sched affinity on Linux.
|
||||
#[inline]
|
||||
pub fn get() -> usize {
|
||||
get_num_cpus()
|
||||
}
|
||||
|
||||
/// Returns the number of physical cores of the current system.
|
||||
///
|
||||
/// If not possible on the particular architecture, returns same as `get()`
|
||||
/// which is the logical CPUs.
|
||||
#[inline]
|
||||
pub fn get_physical() -> usize {
|
||||
get_num_physical_cpus()
|
||||
}
|
||||
|
||||
|
||||
#[cfg(not(any(target_os = "linux", target_os = "windows")))]
|
||||
#[inline]
|
||||
fn get_num_physical_cpus() -> usize {
|
||||
// Not implemented, fallback
|
||||
get_num_cpus()
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn get_num_physical_cpus() -> usize {
|
||||
match get_num_physical_cpus_windows() {
|
||||
Some(num) => num,
|
||||
None => get_num_cpus()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
fn get_num_physical_cpus_windows() -> Option<usize> {
|
||||
// Inspired by https://msdn.microsoft.com/en-us/library/ms683194
|
||||
|
||||
use std::ptr;
|
||||
use std::mem;
|
||||
|
||||
#[allow(non_upper_case_globals)]
|
||||
const RelationProcessorCore: u32 = 0;
|
||||
|
||||
#[repr(C)]
|
||||
#[allow(non_camel_case_types)]
|
||||
struct SYSTEM_LOGICAL_PROCESSOR_INFORMATION {
|
||||
mask: usize,
|
||||
relationship: u32,
|
||||
_unused: [u64; 2]
|
||||
}
|
||||
|
||||
extern "system" {
|
||||
fn GetLogicalProcessorInformation(
|
||||
info: *mut SYSTEM_LOGICAL_PROCESSOR_INFORMATION,
|
||||
length: &mut u32
|
||||
) -> u32;
|
||||
}
|
||||
|
||||
// First we need to determine how much space to reserve.
|
||||
|
||||
// The required size of the buffer, in bytes.
|
||||
let mut needed_size = 0;
|
||||
|
||||
unsafe {
|
||||
GetLogicalProcessorInformation(ptr::null_mut(), &mut needed_size);
|
||||
}
|
||||
|
||||
let struct_size = mem::size_of::<SYSTEM_LOGICAL_PROCESSOR_INFORMATION>() as u32;
|
||||
|
||||
// Could be 0, or some other bogus size.
|
||||
if needed_size == 0 || needed_size < struct_size || needed_size % struct_size != 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let count = needed_size / struct_size;
|
||||
|
||||
// Allocate some memory where we will store the processor info.
|
||||
let mut buf = Vec::with_capacity(count as usize);
|
||||
|
||||
let result;
|
||||
|
||||
unsafe {
|
||||
result = GetLogicalProcessorInformation(buf.as_mut_ptr(), &mut needed_size);
|
||||
}
|
||||
|
||||
// Failed for any reason.
|
||||
if result == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
let count = needed_size / struct_size;
|
||||
|
||||
unsafe {
|
||||
buf.set_len(count as usize);
|
||||
}
|
||||
|
||||
let phys_proc_count = buf.iter()
|
||||
// Only interested in processor packages (physical processors.)
|
||||
.filter(|proc_info| proc_info.relationship == RelationProcessorCore)
|
||||
.count();
|
||||
|
||||
if phys_proc_count == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(phys_proc_count)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn get_num_physical_cpus() -> usize {
|
||||
use std::io::BufReader;
|
||||
use std::io::BufRead;
|
||||
use std::fs::File;
|
||||
use std::collections::HashSet;
|
||||
|
||||
let file = match File::open("/proc/cpuinfo") {
|
||||
Ok(val) => val,
|
||||
Err(_) => {return get_num_cpus()},
|
||||
};
|
||||
let reader = BufReader::new(file);
|
||||
let mut set = HashSet::new();
|
||||
let mut coreid: u32 = 0;
|
||||
let mut physid: u32 = 0;
|
||||
let mut chgcount = 0;
|
||||
for line in reader.lines().filter_map(|result| result.ok()) {
|
||||
let parts: Vec<&str> = line.split(':').map(|s| s.trim()).collect();
|
||||
if parts.len() != 2 {
|
||||
continue
|
||||
}
|
||||
if parts[0] == "core id" || parts[0] == "physical id" {
|
||||
let value = match parts[1].trim().parse() {
|
||||
Ok(val) => val,
|
||||
Err(_) => break,
|
||||
};
|
||||
match parts[0] {
|
||||
"core id" => coreid = value,
|
||||
"physical id" => physid = value,
|
||||
_ => {},
|
||||
}
|
||||
chgcount += 1;
|
||||
}
|
||||
if chgcount == 2 {
|
||||
set.insert((physid, coreid));
|
||||
chgcount = 0;
|
||||
}
|
||||
}
|
||||
let count = set.len();
|
||||
if count == 0 { get_num_cpus() } else { count }
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn get_num_cpus() -> usize {
|
||||
#[repr(C)]
|
||||
struct SYSTEM_INFO {
|
||||
wProcessorArchitecture: u16,
|
||||
wReserved: u16,
|
||||
dwPageSize: u32,
|
||||
lpMinimumApplicationAddress: *mut u8,
|
||||
lpMaximumApplicationAddress: *mut u8,
|
||||
dwActiveProcessorMask: *mut u8,
|
||||
dwNumberOfProcessors: u32,
|
||||
dwProcessorType: u32,
|
||||
dwAllocationGranularity: u32,
|
||||
wProcessorLevel: u16,
|
||||
wProcessorRevision: u16,
|
||||
}
|
||||
|
||||
extern "system" {
|
||||
fn GetSystemInfo(lpSystemInfo: *mut SYSTEM_INFO);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let mut sysinfo: SYSTEM_INFO = std::mem::uninitialized();
|
||||
GetSystemInfo(&mut sysinfo);
|
||||
sysinfo.dwNumberOfProcessors as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "freebsd",
|
||||
target_os = "dragonfly",
|
||||
target_os = "bitrig",
|
||||
target_os = "netbsd"))]
|
||||
fn get_num_cpus() -> usize {
|
||||
let mut cpus: libc::c_uint = 0;
|
||||
let mut cpus_size = std::mem::size_of_val(&cpus);
|
||||
|
||||
unsafe {
|
||||
cpus = libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as libc::c_uint;
|
||||
}
|
||||
if cpus < 1 {
|
||||
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
|
||||
unsafe {
|
||||
libc::sysctl(mib.as_mut_ptr(),
|
||||
2,
|
||||
&mut cpus as *mut _ as *mut _,
|
||||
&mut cpus_size as *mut _ as *mut _,
|
||||
0 as *mut _,
|
||||
0);
|
||||
}
|
||||
if cpus < 1 {
|
||||
cpus = 1;
|
||||
}
|
||||
}
|
||||
cpus as usize
|
||||
}
|
||||
|
||||
#[cfg(target_os = "openbsd")]
|
||||
fn get_num_cpus() -> usize {
|
||||
let mut cpus: libc::c_uint = 0;
|
||||
let mut cpus_size = std::mem::size_of_val(&cpus);
|
||||
let mut mib = [libc::CTL_HW, libc::HW_NCPU, 0, 0];
|
||||
|
||||
unsafe {
|
||||
libc::sysctl(mib.as_mut_ptr(),
|
||||
2,
|
||||
&mut cpus as *mut _ as *mut _,
|
||||
&mut cpus_size as *mut _ as *mut _,
|
||||
0 as *mut _,
|
||||
0);
|
||||
}
|
||||
if cpus < 1 {
|
||||
cpus = 1;
|
||||
}
|
||||
cpus as usize
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn get_num_cpus() -> usize {
|
||||
let mut set: libc::cpu_set_t = unsafe { std::mem::zeroed() };
|
||||
if unsafe { libc::sched_getaffinity(0, std::mem::size_of::<libc::cpu_set_t>(), &mut set) } == 0 {
|
||||
let mut count: u32 = 0;
|
||||
for i in 0..libc::CPU_SETSIZE as usize {
|
||||
if unsafe { libc::CPU_ISSET(i, &set) } {
|
||||
count += 1
|
||||
}
|
||||
}
|
||||
count as usize
|
||||
} else {
|
||||
let cpus = unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) };
|
||||
if cpus < 1 {
|
||||
1
|
||||
} else {
|
||||
cpus as usize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(
|
||||
target_os = "nacl",
|
||||
target_os = "macos",
|
||||
target_os = "ios",
|
||||
target_os = "android",
|
||||
target_os = "solaris",
|
||||
target_os = "fuchsia")
|
||||
)]
|
||||
fn get_num_cpus() -> usize {
|
||||
let cpus = unsafe { libc::sysconf(libc::_SC_NPROCESSORS_ONLN) };
|
||||
if cpus < 1 {
|
||||
1
|
||||
} else {
|
||||
cpus as usize
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "emscripten", target_os = "redox", target_os = "haiku"))]
|
||||
fn get_num_cpus() -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
fn env_var(name: &'static str) -> Option<usize> {
|
||||
::std::env::var(name).ok().map(|val| val.parse().unwrap())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get() {
|
||||
let num = super::get();
|
||||
if let Some(n) = env_var("NUM_CPUS_TEST_GET") {
|
||||
assert_eq!(num, n);
|
||||
} else {
|
||||
assert!(num > 0);
|
||||
assert!(num < 236_451);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_physical() {
|
||||
let num = super::get_physical();
|
||||
if let Some(n) = env_var("NUM_CPUS_TEST_GET_PHYSICAL") {
|
||||
assert_eq!(num, n);
|
||||
} else {
|
||||
assert!(num > 0);
|
||||
assert!(num < 236_451);
|
||||
}
|
||||
}
|
||||
}
|
8
toolkit/library/gtest/rust/Cargo.lock
generated
8
toolkit/library/gtest/rust/Cargo.lock
generated
@ -900,7 +900,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.6.0"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1066,7 +1066,7 @@ dependencies = [
|
||||
"futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1255,7 +1255,7 @@ dependencies = [
|
||||
"nsstring 0.1.0",
|
||||
"num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1640,7 +1640,7 @@ dependencies = [
|
||||
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
|
||||
"checksum num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "21e4df1098d1d797d27ef0c69c178c3fab64941559b290fcae198e0825c9c8b5"
|
||||
"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6"
|
||||
"checksum num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83df569ffd47dbf87f36bead512632f89e90882b8e7a14286d0471daf6b72de9"
|
||||
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
|
||||
"checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba"
|
||||
"checksum ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da12c96037889ae0be29dd2bdd260e5a62a7df24e6466d5a15bb8131c1c200a8"
|
||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||
|
8
toolkit/library/rust/Cargo.lock
generated
8
toolkit/library/rust/Cargo.lock
generated
@ -888,7 +888,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "num_cpus"
|
||||
version = "1.6.0"
|
||||
version = "1.6.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1054,7 +1054,7 @@ dependencies = [
|
||||
"futures 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.17 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -1247,7 +1247,7 @@ dependencies = [
|
||||
"nsstring 0.1.0",
|
||||
"num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1652,7 +1652,7 @@ dependencies = [
|
||||
"checksum nom 1.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b8c256fd9471521bcb84c3cdba98921497f1a331cbc15b8030fc63b82050ce"
|
||||
"checksum num-integer 0.1.33 (registry+https://github.com/rust-lang/crates.io-index)" = "21e4df1098d1d797d27ef0c69c178c3fab64941559b290fcae198e0825c9c8b5"
|
||||
"checksum num-traits 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "1708c0628602a98b52fad936cf3edb9a107af06e52e49fdf0707e884456a6af6"
|
||||
"checksum num_cpus 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "83df569ffd47dbf87f36bead512632f89e90882b8e7a14286d0471daf6b72de9"
|
||||
"checksum num_cpus 1.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "aec53c34f2d0247c5ca5d32cca1478762f301740468ee9ee6dcb7a0dd7a0c584"
|
||||
"checksum odds 0.2.25 (registry+https://github.com/rust-lang/crates.io-index)" = "c3df9b730298cea3a1c3faa90b7e2f9df3a9c400d0936d6015e6165734eefcba"
|
||||
"checksum ordered-float 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "da12c96037889ae0be29dd2bdd260e5a62a7df24e6466d5a15bb8131c1c200a8"
|
||||
"checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37"
|
||||
|
Loading…
Reference in New Issue
Block a user