std: remove sys_common::thread
This commit is contained in:
parent
72fe8a0f00
commit
843cef3035
3 changed files with 22 additions and 24 deletions
|
@ -25,7 +25,6 @@ pub mod fs;
|
||||||
pub mod io;
|
pub mod io;
|
||||||
pub mod lazy_box;
|
pub mod lazy_box;
|
||||||
pub mod process;
|
pub mod process;
|
||||||
pub mod thread;
|
|
||||||
pub mod thread_local_dtor;
|
pub mod thread_local_dtor;
|
||||||
pub mod thread_parking;
|
pub mod thread_parking;
|
||||||
pub mod wstr;
|
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::any::Any;
|
||||||
use crate::cell::{OnceCell, UnsafeCell};
|
use crate::cell::{OnceCell, UnsafeCell};
|
||||||
|
use crate::env;
|
||||||
use crate::ffi::{CStr, CString};
|
use crate::ffi::{CStr, CString};
|
||||||
use crate::fmt;
|
use crate::fmt;
|
||||||
use crate::io;
|
use crate::io;
|
||||||
|
@ -171,9 +172,9 @@ use crate::panicking;
|
||||||
use crate::pin::Pin;
|
use crate::pin::Pin;
|
||||||
use crate::ptr::addr_of_mut;
|
use crate::ptr::addr_of_mut;
|
||||||
use crate::str;
|
use crate::str;
|
||||||
|
use crate::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use crate::sync::Arc;
|
use crate::sync::Arc;
|
||||||
use crate::sys::thread as imp;
|
use crate::sys::thread as imp;
|
||||||
use crate::sys_common::thread;
|
|
||||||
use crate::sys_common::thread_parking::Parker;
|
use crate::sys_common::thread_parking::Parker;
|
||||||
use crate::sys_common::{AsInner, IntoInner};
|
use crate::sys_common::{AsInner, IntoInner};
|
||||||
use crate::time::{Duration, Instant};
|
use crate::time::{Duration, Instant};
|
||||||
|
@ -468,7 +469,23 @@ impl Builder {
|
||||||
{
|
{
|
||||||
let Builder { name, stack_size } = self;
|
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| {
|
let my_thread = Thread::new(name.map(|name| {
|
||||||
CString::new(name).expect("thread name may not contain interior null bytes")
|
CString::new(name).expect("thread name may not contain interior null bytes")
|
||||||
|
@ -1191,17 +1208,17 @@ impl ThreadId {
|
||||||
|
|
||||||
cfg_if::cfg_if! {
|
cfg_if::cfg_if! {
|
||||||
if #[cfg(target_has_atomic = "64")] {
|
if #[cfg(target_has_atomic = "64")] {
|
||||||
use crate::sync::atomic::{AtomicU64, Ordering::Relaxed};
|
use crate::sync::atomic::AtomicU64;
|
||||||
|
|
||||||
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
static COUNTER: AtomicU64 = AtomicU64::new(0);
|
||||||
|
|
||||||
let mut last = COUNTER.load(Relaxed);
|
let mut last = COUNTER.load(Ordering::Relaxed);
|
||||||
loop {
|
loop {
|
||||||
let Some(id) = last.checked_add(1) else {
|
let Some(id) = last.checked_add(1) else {
|
||||||
exhausted();
|
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()),
|
Ok(_) => return ThreadId(NonZero::new(id).unwrap()),
|
||||||
Err(id) => last = id,
|
Err(id) => last = id,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue