Rollup merge of #84655 - CDirkx:wasm, r=m-ou-se

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````
This commit is contained in:
Dylan DPC 2021-05-07 16:19:20 +02:00 committed by GitHub
commit 8f0b1863d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 65 deletions

View File

@ -1,4 +1,5 @@
use crate::ffi::OsString;
use crate::fmt;
pub struct Args {}

View File

@ -1,42 +0,0 @@
use crate::ffi::OsString;
use crate::fmt;
use crate::vec;
pub fn args() -> Args {
Args { iter: Vec::new().into_iter() }
}
pub struct Args {
iter: vec::IntoIter<OsString>,
}
impl !Send for Args {}
impl !Sync for Args {}
impl fmt::Debug for Args {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.iter.as_slice().fmt(f)
}
}
impl Iterator for Args {
type Item = OsString;
fn next(&mut self) -> Option<OsString> {
self.iter.next()
}
fn size_hint(&self) -> (usize, Option<usize>) {
self.iter.size_hint()
}
}
impl ExactSizeIterator for Args {
fn len(&self) -> usize {
self.iter.len()
}
}
impl DoubleEndedIterator for Args {
fn next_back(&mut self) -> Option<OsString> {
self.iter.next_back()
}
}

View File

@ -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;
@ -46,9 +36,7 @@ impl Thread {
}
}
pub fn join(self) {
self.0
}
pub fn join(self) {}
}
pub mod guard {
@ -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};

View File

@ -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;
@ -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"]
@ -49,14 +49,16 @@ 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;
@ -64,6 +66,8 @@ cfg_if::cfg_if! {
pub mod mutex;
#[path = "../unsupported/rwlock.rs"]
pub mod rwlock;
#[path = "../unsupported/thread.rs"]
pub mod thread;
}
}