about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorDylan DPC <dylan.dpc@gmail.com>2021-05-07 16:19:20 +0200
committerGitHub <noreply@github.com>2021-05-07 16:19:20 +0200
commit8f0b1863d0617be844112778e77544a5bcee79cd (patch)
treed4ecc9536503dc6a45c709fca9bcc9825fad4aba /library/std/src
parent0c8c21d224ca94f63d2b07000e8223f3a041281b (diff)
parentcf79c06575f1710f05ee5309fb24bcdfff6f0140 (diff)
downloadrust-8f0b1863d0617be844112778e77544a5bcee79cd.tar.gz
rust-8f0b1863d0617be844112778e77544a5bcee79cd.zip
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````
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unsupported/args.rs1
-rw-r--r--library/std/src/sys/wasm/args.rs42
-rw-r--r--library/std/src/sys/wasm/atomics/condvar.rs (renamed from library/std/src/sys/wasm/condvar_atomics.rs)0
-rw-r--r--library/std/src/sys/wasm/atomics/futex.rs (renamed from library/std/src/sys/wasm/futex_atomics.rs)0
-rw-r--r--library/std/src/sys/wasm/atomics/mutex.rs (renamed from library/std/src/sys/wasm/mutex_atomics.rs)0
-rw-r--r--library/std/src/sys/wasm/atomics/rwlock.rs (renamed from library/std/src/sys/wasm/rwlock_atomics.rs)0
-rw-r--r--library/std/src/sys/wasm/atomics/thread.rs (renamed from library/std/src/sys/wasm/thread.rs)22
-rw-r--r--library/std/src/sys/wasm/mod.rs14
8 files changed, 14 insertions, 65 deletions
diff --git a/library/std/src/sys/unsupported/args.rs b/library/std/src/sys/unsupported/args.rs
index c924a7d8a26..a2d75a61976 100644
--- a/library/std/src/sys/unsupported/args.rs
+++ b/library/std/src/sys/unsupported/args.rs
@@ -1,4 +1,5 @@
 use crate::ffi::OsString;
+use crate::fmt;
 
 pub struct Args {}
 
diff --git a/library/std/src/sys/wasm/args.rs b/library/std/src/sys/wasm/args.rs
deleted file mode 100644
index fde1ab79e1f..00000000000
--- a/library/std/src/sys/wasm/args.rs
+++ /dev/null
@@ -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()
-    }
-}
diff --git a/library/std/src/sys/wasm/condvar_atomics.rs b/library/std/src/sys/wasm/atomics/condvar.rs
index 0c1c076cc91..0c1c076cc91 100644
--- a/library/std/src/sys/wasm/condvar_atomics.rs
+++ b/library/std/src/sys/wasm/atomics/condvar.rs
diff --git a/library/std/src/sys/wasm/futex_atomics.rs b/library/std/src/sys/wasm/atomics/futex.rs
index 3d8bf42f725..3d8bf42f725 100644
--- a/library/std/src/sys/wasm/futex_atomics.rs
+++ b/library/std/src/sys/wasm/atomics/futex.rs
diff --git a/library/std/src/sys/wasm/mutex_atomics.rs b/library/std/src/sys/wasm/atomics/mutex.rs
index 5ff0ec052b6..5ff0ec052b6 100644
--- a/library/std/src/sys/wasm/mutex_atomics.rs
+++ b/library/std/src/sys/wasm/atomics/mutex.rs
diff --git a/library/std/src/sys/wasm/rwlock_atomics.rs b/library/std/src/sys/wasm/atomics/rwlock.rs
index 06442e925f4..06442e925f4 100644
--- a/library/std/src/sys/wasm/rwlock_atomics.rs
+++ b/library/std/src/sys/wasm/atomics/rwlock.rs
diff --git a/library/std/src/sys/wasm/thread.rs b/library/std/src/sys/wasm/atomics/thread.rs
index b7bf95c89b4..54bc877aa7d 100644
--- a/library/std/src/sys/wasm/thread.rs
+++ b/library/std/src/sys/wasm/atomics/thread.rs
@@ -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};
 
diff --git a/library/std/src/sys/wasm/mod.rs b/library/std/src/sys/wasm/mod.rs
index afcc5ca9286..cd701a333f8 100644
--- a/library/std/src/sys/wasm/mod.rs
+++ b/library/std/src/sys/wasm/mod.rs
@@ -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;
     }
 }