mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 09:53:04 +03:00
Rework wasm::thread to thread_atomics
This commit is contained in:
@@ -37,7 +37,6 @@
|
||||
pub mod process;
|
||||
#[path = "../unsupported/stdio.rs"]
|
||||
pub mod stdio;
|
||||
pub mod thread;
|
||||
#[path = "../unsupported/thread_local_dtor.rs"]
|
||||
pub mod thread_local_dtor;
|
||||
#[path = "../unsupported/thread_local_key.rs"]
|
||||
@@ -57,6 +56,8 @@
|
||||
pub mod rwlock;
|
||||
#[path = "futex_atomics.rs"]
|
||||
pub mod futex;
|
||||
#[path = "thread_atomics.rs"]
|
||||
pub mod thread;
|
||||
} else {
|
||||
#[path = "../unsupported/condvar.rs"]
|
||||
pub mod condvar;
|
||||
@@ -64,6 +65,8 @@
|
||||
pub mod mutex;
|
||||
#[path = "../unsupported/rwlock.rs"]
|
||||
pub mod rwlock;
|
||||
#[path = "../unsupported/thread.rs"]
|
||||
pub mod thread;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,20 +13,10 @@ pub unsafe fn new(_stack: usize, _p: Box<dyn FnOnce()>) -> io::Result<Thread> {
|
||||
unsupported()
|
||||
}
|
||||
|
||||
pub fn yield_now() {
|
||||
// do nothing
|
||||
}
|
||||
pub fn yield_now() {}
|
||||
|
||||
pub fn set_name(_name: &CStr) {
|
||||
// nope
|
||||
}
|
||||
pub fn set_name(_name: &CStr) {}
|
||||
|
||||
#[cfg(not(target_feature = "atomics"))]
|
||||
pub fn sleep(_dur: Duration) {
|
||||
panic!("can't sleep");
|
||||
}
|
||||
|
||||
#[cfg(target_feature = "atomics")]
|
||||
pub fn sleep(dur: Duration) {
|
||||
use crate::arch::wasm32;
|
||||
use crate::cmp;
|
||||
@@ -46,9 +36,7 @@ pub fn sleep(dur: Duration) {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn join(self) {
|
||||
self.0
|
||||
}
|
||||
pub fn join(self) {}
|
||||
}
|
||||
|
||||
pub mod guard {
|
||||
@@ -61,11 +49,9 @@ pub unsafe fn init() -> Option<Guard> {
|
||||
}
|
||||
}
|
||||
|
||||
// This is only used by atomics primitives when the `atomics` feature is
|
||||
// enabled. In that mode we currently just use our own thread-local to store our
|
||||
// We currently just use our own thread-local to store our
|
||||
// current thread's ID, and then we lazily initialize it to something allocated
|
||||
// from a global counter.
|
||||
#[cfg(target_feature = "atomics")]
|
||||
pub fn my_id() -> u32 {
|
||||
use crate::sync::atomic::{AtomicU32, Ordering::SeqCst};
|
||||
|
||||
Reference in New Issue
Block a user