mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Rollup merge of #123807 - joboet:sys_common_thread, r=jhpratt
Remove `sys_common::thread` Part of #117276. The stack size calculation isn't system-specific at all and can just live together with the rest of the spawn logic.
This commit is contained in:
commit
595a284872
@ -25,7 +25,6 @@ pub mod fs;
|
||||
pub mod io;
|
||||
pub mod lazy_box;
|
||||
pub mod process;
|
||||
pub mod thread;
|
||||
pub mod thread_local_dtor;
|
||||
pub mod thread_parking;
|
||||
pub mod wstr;
|
||||
|
@ -1,18 +0,0 @@
|
||||
use crate::env;
|
||||
use crate::sync::atomic::{self, Ordering};
|
||||
use crate::sys::thread as imp;
|
||||
|
||||
pub fn min_stack() -> usize {
|
||||
static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
|
||||
match MIN.load(Ordering::Relaxed) {
|
||||
0 => {}
|
||||
n => return n - 1,
|
||||
}
|
||||
let amt = env::var_os("RUST_MIN_STACK").and_then(|s| s.to_str().and_then(|s| s.parse().ok()));
|
||||
let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
|
||||
|
||||
// 0 is our sentinel value, so ensure that we'll never see 0 after
|
||||
// initialization has run
|
||||
MIN.store(amt + 1, Ordering::Relaxed);
|
||||
amt
|
||||
}
|
@ -160,6 +160,7 @@ mod tests;
|
||||
|
||||
use crate::any::Any;
|
||||
use crate::cell::{OnceCell, UnsafeCell};
|
||||
use crate::env;
|
||||
use crate::ffi::{CStr, CString};
|
||||
use crate::fmt;
|
||||
use crate::io;
|
||||
@ -171,9 +172,9 @@ use crate::panicking;
|
||||
use crate::pin::Pin;
|
||||
use crate::ptr::addr_of_mut;
|
||||
use crate::str;
|
||||
use crate::sync::atomic::{AtomicUsize, Ordering};
|
||||
use crate::sync::Arc;
|
||||
use crate::sys::thread as imp;
|
||||
use crate::sys_common::thread;
|
||||
use crate::sys_common::thread_parking::Parker;
|
||||
use crate::sys_common::{AsInner, IntoInner};
|
||||
use crate::time::{Duration, Instant};
|
||||
@ -468,7 +469,23 @@ impl Builder {
|
||||
{
|
||||
let Builder { name, stack_size } = self;
|
||||
|
||||
let stack_size = stack_size.unwrap_or_else(thread::min_stack);
|
||||
let stack_size = stack_size.unwrap_or_else(|| {
|
||||
static MIN: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
match MIN.load(Ordering::Relaxed) {
|
||||
0 => {}
|
||||
n => return n - 1,
|
||||
}
|
||||
|
||||
let amt = env::var_os("RUST_MIN_STACK")
|
||||
.and_then(|s| s.to_str().and_then(|s| s.parse().ok()))
|
||||
.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
|
||||
|
||||
// 0 is our sentinel value, so ensure that we'll never see 0 after
|
||||
// initialization has run
|
||||
MIN.store(amt + 1, Ordering::Relaxed);
|
||||
amt
|
||||
});
|
||||
|
||||
let my_thread = Thread::new(name.map(|name| {
|
||||
CString::new(name).expect("thread name may not contain interior null bytes")
|
||||
@ -1191,17 +1208,17 @@ impl ThreadId {
|
||||
|
||||
cfg_if::cfg_if! {
|
||||
if #[cfg(target_has_atomic = "64")] {
|
||||
use crate::sync::atomic::{AtomicU64, Ordering::Relaxed};
|
||||
use crate::sync::atomic::AtomicU64;
|
||||
|
||||
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
let mut last = COUNTER.load(Relaxed);
|
||||
let mut last = COUNTER.load(Ordering::Relaxed);
|
||||
loop {
|
||||
let Some(id) = last.checked_add(1) else {
|
||||
exhausted();
|
||||
};
|
||||
|
||||
match COUNTER.compare_exchange_weak(last, id, Relaxed, Relaxed) {
|
||||
match COUNTER.compare_exchange_weak(last, id, Ordering::Relaxed, Ordering::Relaxed) {
|
||||
Ok(_) => return ThreadId(NonZero::new(id).unwrap()),
|
||||
Err(id) => last = id,
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user