mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-16 21:15:18 +03:00
7828c3dd28
https://github.com/rust-lang/rfcs/pull/221 The current terminology of "task failure" often causes problems when writing or speaking about code. You often want to talk about the possibility of an operation that returns a Result "failing", but cannot because of the ambiguity with task failure. Instead, you have to speak of "the failing case" or "when the operation does not succeed" or other circumlocutions. Likewise, we use a "Failure" header in rustdoc to describe when operations may fail the task, but it would often be helpful to separate out a section describing the "Err-producing" case. We have been steadily moving away from task failure and toward Result as an error-handling mechanism, so we should optimize our terminology accordingly: Result-producing functions should be easy to describe. To update your code, rename any call to `fail!` to `panic!` instead. Assuming you have not created your own macro named `panic!`, this will work on UNIX based systems: grep -lZR 'fail!' . | xargs -0 -l sed -i -e 's/fail!/panic!/g' You can of course also do this by hand. [breaking-change]
77 lines
2.9 KiB
Rust
77 lines
2.9 KiB
Rust
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
// file at the top-level directory of this distribution and at
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
// option. This file may not be copied, modified, or distributed
|
|
// except according to those terms.
|
|
|
|
use from_str::FromStr;
|
|
use from_str::from_str;
|
|
use libc::uintptr_t;
|
|
use option::{Some, None, Option};
|
|
use os;
|
|
use str::Str;
|
|
use sync::atomic;
|
|
|
|
/// Dynamically inquire about whether we're running under V.
|
|
/// You should usually not use this unless your test definitely
|
|
/// can't run correctly un-altered. Valgrind is there to help
|
|
/// you notice weirdness in normal, un-doctored code paths!
|
|
pub fn running_on_valgrind() -> bool {
|
|
extern {
|
|
fn rust_running_on_valgrind() -> uintptr_t;
|
|
}
|
|
unsafe { rust_running_on_valgrind() != 0 }
|
|
}
|
|
|
|
/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors
|
|
/// wired into it; this is a hard limit and requires rebuilding valgrind if you
|
|
/// want to go beyond it. Normally this is not a problem, but in some tests, we
|
|
/// produce a lot of threads casually. Making lots of threads alone might not
|
|
/// be a problem _either_, except on OSX, the segments produced for new threads
|
|
/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv
|
|
/// schedulers fork off a separate thread for polling fsevents on OSX, we get a
|
|
/// perfect storm of creating "too many mappings" for valgrind to handle when
|
|
/// running certain stress tests in the runtime.
|
|
pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool {
|
|
(cfg!(target_os="macos")) && running_on_valgrind()
|
|
}
|
|
|
|
pub fn min_stack() -> uint {
|
|
static MIN: atomic::AtomicUint = atomic::INIT_ATOMIC_UINT;
|
|
match MIN.load(atomic::SeqCst) {
|
|
0 => {}
|
|
n => return n - 1,
|
|
}
|
|
let amt = os::getenv("RUST_MIN_STACK").and_then(|s| from_str(s.as_slice()));
|
|
let amt = amt.unwrap_or(2 * 1024 * 1024);
|
|
// 0 is our sentinel value, so ensure that we'll never see 0 after
|
|
// initialization has run
|
|
MIN.store(amt + 1, atomic::SeqCst);
|
|
return amt;
|
|
}
|
|
|
|
/// Get's the number of scheduler threads requested by the environment
|
|
/// either `RUST_THREADS` or `num_cpus`.
|
|
pub fn default_sched_threads() -> uint {
|
|
match os::getenv("RUST_THREADS") {
|
|
Some(nstr) => {
|
|
let opt_n: Option<uint> = FromStr::from_str(nstr.as_slice());
|
|
match opt_n {
|
|
Some(n) if n > 0 => n,
|
|
_ => panic!("`RUST_THREADS` is `{}`, should be a positive integer", nstr)
|
|
}
|
|
}
|
|
None => {
|
|
if limit_thread_creation_due_to_osx_and_valgrind() {
|
|
1
|
|
} else {
|
|
os::num_cpus()
|
|
}
|
|
}
|
|
}
|
|
}
|