Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove sys_common::thread #123807

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion library/std/src/sys_common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 0 additions & 18 deletions library/std/src/sys_common/thread.rs

This file was deleted.

27 changes: 22 additions & 5 deletions library/std/src/thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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};
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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,
}
Expand Down
Loading