Skip to content

Commit

Permalink
Rollup merge of rust-lang#84655 - CDirkx:wasm, r=m-ou-se
Browse files Browse the repository at this point in the history
Cleanup of `wasm`

Some more cleanup of `sys`, this time `wasm`

- Reuse `unsupported::args` (functionally equivalent implementation, just an empty iterator).
- Split out `atomics` implementation of `wasm::thread`, the non-`atomics` implementation is reused from `unsupported`.
- Move all of the `atomics` code to a separate directory `wasm/atomics`.

```@rustbot``` label: +T-libs-impl
r? ```@m-ou-se```
  • Loading branch information
Dylan-DPC authored May 7, 2021
2 parents 097ee3c + cf79c06 commit 9dc4c3c
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 65 deletions.
1 change: 1 addition & 0 deletions library/std/src/sys/unsupported/args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::ffi::OsString;
use crate::fmt;

pub struct Args {}

Expand Down
42 changes: 0 additions & 42 deletions library/std/src/sys/wasm/args.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ impl 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;
Expand All @@ -46,9 +36,7 @@ impl Thread {
}
}

pub fn join(self) {
self.0
}
pub fn join(self) {}
}

pub mod guard {
Expand All @@ -61,11 +49,9 @@ pub mod 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};

Expand Down
14 changes: 9 additions & 5 deletions library/std/src/sys/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#![deny(unsafe_op_in_unsafe_fn)]

pub mod alloc;
#[path = "../unsupported/args.rs"]
pub mod args;
#[path = "../unix/cmath.rs"]
pub mod cmath;
Expand All @@ -37,7 +38,6 @@ pub mod pipe;
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"]
Expand All @@ -49,21 +49,25 @@ pub use crate::sys_common::os_str_bytes as os_str;

cfg_if::cfg_if! {
if #[cfg(target_feature = "atomics")] {
#[path = "condvar_atomics.rs"]
#[path = "atomics/condvar.rs"]
pub mod condvar;
#[path = "mutex_atomics.rs"]
#[path = "atomics/mutex.rs"]
pub mod mutex;
#[path = "rwlock_atomics.rs"]
#[path = "atomics/rwlock.rs"]
pub mod rwlock;
#[path = "futex_atomics.rs"]
#[path = "atomics/futex.rs"]
pub mod futex;
#[path = "atomics/thread.rs"]
pub mod thread;
} else {
#[path = "../unsupported/condvar.rs"]
pub mod condvar;
#[path = "../unsupported/mutex.rs"]
pub mod mutex;
#[path = "../unsupported/rwlock.rs"]
pub mod rwlock;
#[path = "../unsupported/thread.rs"]
pub mod thread;
}
}

Expand Down

0 comments on commit 9dc4c3c

Please sign in to comment.