about summary refs log tree commit diff
path: root/src/libstd/sys/wasm/thread_local_atomics.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2018-08-15 10:51:24 -0700
committerAlex Crichton <alex@alexcrichton.com>2018-09-24 15:55:35 -0700
commitb4877edd6750edc12aa2db1953a6551843bfa4b4 (patch)
tree52362638c13b0d040828d3a72ccad38e9f7ad522 /src/libstd/sys/wasm/thread_local_atomics.rs
parente5c6575801028f5e089ef2e7720aa1af9d452334 (diff)
downloadrust-b4877edd6750edc12aa2db1953a6551843bfa4b4.tar.gz
rust-b4877edd6750edc12aa2db1953a6551843bfa4b4.zip
std: Start implementing wasm32 atomics
This commit is an initial start at implementing the standard library for
wasm32-unknown-unknown with the experimental `atomics` feature enabled. None of
these changes will be visible to users of the wasm32-unknown-unknown target
because they all require recompiling the standard library. The hope with this is
that we can get this support into the standard library and start iterating on it
in-tree to enable experimentation.

Currently there's a few components in this PR:

* Atomic fences are disabled on wasm as there's no corresponding atomic op and
  it's not clear yet what the convention should be, but this will change in the
  future!
* Implementations of `Mutex`, `Condvar`, and `RwLock` were all added based on
  the atomic intrinsics that wasm has.
* The `ReentrantMutex` and thread-local-storage implementations panic currently
  as there's no great way to get a handle on the current thread's "id" yet.

Right now the wasm32 target with atomics is unfortunately pretty unusable,
requiring a lot of manual things here and there to actually get it operational.
This will likely continue to evolve as the story for atomics and wasm unfolds,
but we also need more LLVM support for some operations like custom `global`
directives for this to work best.
Diffstat (limited to 'src/libstd/sys/wasm/thread_local_atomics.rs')
-rw-r--r--src/libstd/sys/wasm/thread_local_atomics.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/libstd/sys/wasm/thread_local_atomics.rs b/src/libstd/sys/wasm/thread_local_atomics.rs
new file mode 100644
index 00000000000..1394013b4a3
--- /dev/null
+++ b/src/libstd/sys/wasm/thread_local_atomics.rs
@@ -0,0 +1,32 @@
+// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+pub type Key = usize;
+
+pub unsafe fn create(_dtor: Option<unsafe extern fn(*mut u8)>) -> Key {
+    panic!("TLS on wasm with atomics not implemented yet");
+}
+
+pub unsafe fn set(_key: Key, _value: *mut u8) {
+    panic!("TLS on wasm with atomics not implemented yet");
+}
+
+pub unsafe fn get(_key: Key) -> *mut u8 {
+    panic!("TLS on wasm with atomics not implemented yet");
+}
+
+pub unsafe fn destroy(_key: Key) {
+    panic!("TLS on wasm with atomics not implemented yet");
+}
+
+#[inline]
+pub fn requires_synchronized_create() -> bool {
+    false
+}