Skip to content

Commit 15c607c

Browse files
committed
Stabilize WebAssembly atomic intrinsics
This commit stabilizes the wasm atomic intrinsics now that the threads proposal has advanced to Stage 4, and is shipping in browsers. Unfortunately these intrinsics still aren't available through the precompiled versions of the standard library because atomics are no This commit also updates the availability and documentation of these intrinsics to reflect how they're always available, but they probably won't work as expected unless shared memory is used (which isn't enabled by default). This reflects a change in the threads proposal from the last year or so where the instructions validate without requiring a shared memory.
1 parent a5db4ea commit 15c607c

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

crates/core_arch/src/wasm32/atomic.rs

+18-14
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
//!
77
//! [spec]: https://github.com/WebAssembly/threads
88
9-
#![cfg(any(target_feature = "atomics", doc))]
10-
119
#[cfg(test)]
1210
use stdarch_test::assert_instr;
1311

@@ -43,14 +41,16 @@ extern "C" {
4341
///
4442
/// # Availability
4543
///
46-
/// This intrinsic is only available **when the standard library itself is
47-
/// compiled with the `atomics` target feature**. This version of the standard
48-
/// library is not obtainable via `rustup`, but rather will require the
49-
/// standard library to be compiled from source.
44+
/// This intrinsic is always available in the standard library but it will not
45+
/// work as expected with the precompiled versions of the standard library. The
46+
/// standard library must be compiled with `-Ctarget-feature=+atomics` to have
47+
/// the wasm module use shared memory which makes this intrinsic more useful.
48+
/// The standard library is not compiled with this flag by default.
5049
///
5150
/// [instr]: https://webassembly.github.io/threads/syntax/instructions.html#syntax-instr-atomic-memory
5251
#[inline]
5352
#[cfg_attr(test, assert_instr("i32.atomic.wait"))]
53+
#[stable(feature = "wasm_atomics", since = "1.50.0")]
5454
pub unsafe fn memory_atomic_wait32(ptr: *mut i32, expression: i32, timeout_ns: i64) -> i32 {
5555
llvm_atomic_wait_i32(ptr, expression, timeout_ns)
5656
}
@@ -78,14 +78,16 @@ pub unsafe fn memory_atomic_wait32(ptr: *mut i32, expression: i32, timeout_ns: i
7878
///
7979
/// # Availability
8080
///
81-
/// This intrinsic is only available **when the standard library itself is
82-
/// compiled with the `atomics` target feature**. This version of the standard
83-
/// library is not obtainable via `rustup`, but rather will require the
84-
/// standard library to be compiled from source.
81+
/// This intrinsic is always available in the standard library but it will not
82+
/// work as expected with the precompiled versions of the standard library. The
83+
/// standard library must be compiled with `-Ctarget-feature=+atomics` to have
84+
/// the wasm module use shared memory which makes this intrinsic more useful.
85+
/// The standard library is not compiled with this flag by default.
8586
///
8687
/// [instr]: https://webassembly.github.io/threads/syntax/instructions.html#syntax-instr-atomic-memory
8788
#[inline]
8889
#[cfg_attr(test, assert_instr("i64.atomic.wait"))]
90+
#[stable(feature = "wasm_atomics", since = "1.50.0")]
8991
pub unsafe fn memory_atomic_wait64(ptr: *mut i64, expression: i64, timeout_ns: i64) -> i32 {
9092
llvm_atomic_wait_i64(ptr, expression, timeout_ns)
9193
}
@@ -105,14 +107,16 @@ pub unsafe fn memory_atomic_wait64(ptr: *mut i64, expression: i64, timeout_ns: i
105107
///
106108
/// # Availability
107109
///
108-
/// This intrinsic is only available **when the standard library itself is
109-
/// compiled with the `atomics` target feature**. This version of the standard
110-
/// library is not obtainable via `rustup`, but rather will require the
111-
/// standard library to be compiled from source.
110+
/// This intrinsic is always available in the standard library but it will not
111+
/// work as expected with the precompiled versions of the standard library. The
112+
/// standard library must be compiled with `-Ctarget-feature=+atomics` to have
113+
/// the wasm module use shared memory which makes this intrinsic more useful.
114+
/// The standard library is not compiled with this flag by default.
112115
///
113116
/// [instr]: https://webassembly.github.io/threads/syntax/instructions.html#syntax-instr-atomic-memory
114117
#[inline]
115118
#[cfg_attr(test, assert_instr("atomic.wake"))]
119+
#[stable(feature = "wasm_atomics", since = "1.50.0")]
116120
pub unsafe fn memory_atomic_notify(ptr: *mut i32, waiters: u32) -> u32 {
117121
llvm_atomic_notify(ptr, waiters as i32) as u32
118122
}

crates/core_arch/src/wasm32/mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#[cfg(test)]
44
use stdarch_test::assert_instr;
55

6-
#[cfg(any(target_feature = "atomics", doc))]
76
mod atomic;
8-
#[cfg(any(target_feature = "atomics", doc))]
97
pub use self::atomic::*;
108

119
mod simd128;

0 commit comments

Comments
 (0)