Skip to content

Commit 843cef3

Browse files
committed
std: remove sys_common::thread
1 parent 72fe8a0 commit 843cef3

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

Diff for: library/std/src/sys_common/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub mod fs;
2525
pub mod io;
2626
pub mod lazy_box;
2727
pub mod process;
28-
pub mod thread;
2928
pub mod thread_local_dtor;
3029
pub mod thread_parking;
3130
pub mod wstr;

Diff for: library/std/src/sys_common/thread.rs

-18
This file was deleted.

Diff for: library/std/src/thread/mod.rs

+22-5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ mod tests;
160160

161161
use crate::any::Any;
162162
use crate::cell::{OnceCell, UnsafeCell};
163+
use crate::env;
163164
use crate::ffi::{CStr, CString};
164165
use crate::fmt;
165166
use crate::io;
@@ -171,9 +172,9 @@ use crate::panicking;
171172
use crate::pin::Pin;
172173
use crate::ptr::addr_of_mut;
173174
use crate::str;
175+
use crate::sync::atomic::{AtomicUsize, Ordering};
174176
use crate::sync::Arc;
175177
use crate::sys::thread as imp;
176-
use crate::sys_common::thread;
177178
use crate::sys_common::thread_parking::Parker;
178179
use crate::sys_common::{AsInner, IntoInner};
179180
use crate::time::{Duration, Instant};
@@ -468,7 +469,23 @@ impl Builder {
468469
{
469470
let Builder { name, stack_size } = self;
470471

471-
let stack_size = stack_size.unwrap_or_else(thread::min_stack);
472+
let stack_size = stack_size.unwrap_or_else(|| {
473+
static MIN: AtomicUsize = AtomicUsize::new(0);
474+
475+
match MIN.load(Ordering::Relaxed) {
476+
0 => {}
477+
n => return n - 1,
478+
}
479+
480+
let amt = env::var_os("RUST_MIN_STACK")
481+
.and_then(|s| s.to_str().and_then(|s| s.parse().ok()))
482+
.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
483+
484+
// 0 is our sentinel value, so ensure that we'll never see 0 after
485+
// initialization has run
486+
MIN.store(amt + 1, Ordering::Relaxed);
487+
amt
488+
});
472489

473490
let my_thread = Thread::new(name.map(|name| {
474491
CString::new(name).expect("thread name may not contain interior null bytes")
@@ -1191,17 +1208,17 @@ impl ThreadId {
11911208

11921209
cfg_if::cfg_if! {
11931210
if #[cfg(target_has_atomic = "64")] {
1194-
use crate::sync::atomic::{AtomicU64, Ordering::Relaxed};
1211+
use crate::sync::atomic::AtomicU64;
11951212

11961213
static COUNTER: AtomicU64 = AtomicU64::new(0);
11971214

1198-
let mut last = COUNTER.load(Relaxed);
1215+
let mut last = COUNTER.load(Ordering::Relaxed);
11991216
loop {
12001217
let Some(id) = last.checked_add(1) else {
12011218
exhausted();
12021219
};
12031220

1204-
match COUNTER.compare_exchange_weak(last, id, Relaxed, Relaxed) {
1221+
match COUNTER.compare_exchange_weak(last, id, Ordering::Relaxed, Ordering::Relaxed) {
12051222
Ok(_) => return ThreadId(NonZero::new(id).unwrap()),
12061223
Err(id) => last = id,
12071224
}

0 commit comments

Comments
 (0)