Skip to content

Commit 52fa9da

Browse files
committed
Rework wasm::thread to thread_atomics
1 parent 76a04dd commit 52fa9da

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

library/std/src/sys/wasm/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ pub mod pipe;
3737
pub mod process;
3838
#[path = "../unsupported/stdio.rs"]
3939
pub mod stdio;
40-
pub mod thread;
4140
#[path = "../unsupported/thread_local_dtor.rs"]
4241
pub mod thread_local_dtor;
4342
#[path = "../unsupported/thread_local_key.rs"]
@@ -57,13 +56,17 @@ cfg_if::cfg_if! {
5756
pub mod rwlock;
5857
#[path = "futex_atomics.rs"]
5958
pub mod futex;
59+
#[path = "thread_atomics.rs"]
60+
pub mod thread;
6061
} else {
6162
#[path = "../unsupported/condvar.rs"]
6263
pub mod condvar;
6364
#[path = "../unsupported/mutex.rs"]
6465
pub mod mutex;
6566
#[path = "../unsupported/rwlock.rs"]
6667
pub mod rwlock;
68+
#[path = "../unsupported/thread.rs"]
69+
pub mod thread;
6770
}
6871
}
6972

library/std/src/sys/wasm/thread.rs renamed to library/std/src/sys/wasm/thread_atomics.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,10 @@ impl Thread {
1313
unsupported()
1414
}
1515

16-
pub fn yield_now() {
17-
// do nothing
18-
}
16+
pub fn yield_now() {}
1917

20-
pub fn set_name(_name: &CStr) {
21-
// nope
22-
}
18+
pub fn set_name(_name: &CStr) {}
2319

24-
#[cfg(not(target_feature = "atomics"))]
25-
pub fn sleep(_dur: Duration) {
26-
panic!("can't sleep");
27-
}
28-
29-
#[cfg(target_feature = "atomics")]
3020
pub fn sleep(dur: Duration) {
3121
use crate::arch::wasm32;
3222
use crate::cmp;
@@ -46,9 +36,7 @@ impl Thread {
4636
}
4737
}
4838

49-
pub fn join(self) {
50-
self.0
51-
}
39+
pub fn join(self) {}
5240
}
5341

5442
pub mod guard {
@@ -61,11 +49,9 @@ pub mod guard {
6149
}
6250
}
6351

64-
// This is only used by atomics primitives when the `atomics` feature is
65-
// enabled. In that mode we currently just use our own thread-local to store our
52+
// We currently just use our own thread-local to store our
6653
// current thread's ID, and then we lazily initialize it to something allocated
6754
// from a global counter.
68-
#[cfg(target_feature = "atomics")]
6955
pub fn my_id() -> u32 {
7056
use crate::sync::atomic::{AtomicU32, Ordering::SeqCst};
7157

0 commit comments

Comments
 (0)