Skip to main content

henad_core/
send_sync.rs

1//! `Send` and `Sync` bounds that relax on wasm with atomics.
2//!
3//! The name follows `wgpu_types::WasmNotSend`, which exists for the same reason. A wgpu handle is
4//! `Send + Sync` on wasm only through `fragile-send-sync-non-atomic-wasm`, and that feature turns
5//! itself off once atomics are on. Anything holding a device or a queue stops being `Send` in the
6//! threaded web build.
7//!
8//! Nothing is lost. One thread in a browser touches wgpu, and nothing is sent anywhere.
9
10/// `Send`, relaxed to nothing on wasm with atomics.
11#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))]
12pub trait WasmNotSend: Send {}
13#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))]
14impl<T: Send> WasmNotSend for T {}
15
16/// `Sync`, relaxed to nothing on wasm with atomics.
17#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))]
18pub trait WasmNotSync: Sync {}
19#[cfg(not(all(target_arch = "wasm32", target_feature = "atomics")))]
20impl<T: Sync> WasmNotSync for T {}
21
22/// `Send`, relaxed to nothing on wasm with atomics.
23#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))]
24pub trait WasmNotSend {}
25#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))]
26impl<T> WasmNotSend for T {}
27
28/// `Sync`, relaxed to nothing on wasm with atomics.
29#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))]
30pub trait WasmNotSync {}
31#[cfg(all(target_arch = "wasm32", target_feature = "atomics"))]
32impl<T> WasmNotSync for T {}