-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
std: Use native
#[thread_local]
TLS on wasm
This commit moves `thread_local!` on WebAssembly targets to using the `#[thread_local]` attribute in LLVM. This was recently implemented upstream and is [in the process of being documented][dox]. This change only takes affect if modules are compiled with `+atomics` which is currently unstable and a pretty esoteric method of compiling wasm artifacts. This "new power" of the wasm toolchain means that the old `wasm-bindgen-threads` feature of the standard library can be removed since it should now be possible to create a fully functioning threaded wasm module without intrusively dealing with libstd symbols or intrinsics. Yay! [dox]: WebAssembly/tool-conventions#116
- Loading branch information
1 parent
a120caf
commit dc50a63
Showing
10 changed files
with
72 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![unstable(feature = "thread_local_internals", issue = "0")] | ||
|
||
pub unsafe fn register_dtor(_t: *mut u8, _dtor: unsafe extern fn(*mut u8)) { | ||
// FIXME: right now there is no concept of "thread exit", but this is likely | ||
// going to show up at some point in the form of an exported symbol that the | ||
// wasm runtime is oging to be expected to call. For now we basically just | ||
// ignore the arguments, but if such a function starts to exist it will | ||
// likely look like the OSX implementation in `unix/fast_thread_local.rs` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,26 @@ | ||
use crate::boxed::Box; | ||
use crate::ptr; | ||
|
||
pub type Key = usize; | ||
|
||
struct Allocated { | ||
value: *mut u8, | ||
dtor: Option<unsafe extern fn(*mut u8)>, | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn create(dtor: Option<unsafe extern fn(*mut u8)>) -> Key { | ||
Box::into_raw(Box::new(Allocated { | ||
value: ptr::null_mut(), | ||
dtor, | ||
})) as usize | ||
pub unsafe fn create(_dtor: Option<unsafe extern fn(*mut u8)>) -> Key { | ||
panic!("should not be used on the wasm target"); | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn set(key: Key, value: *mut u8) { | ||
(*(key as *mut Allocated)).value = value; | ||
pub unsafe fn set(_key: Key, _value: *mut u8) { | ||
panic!("should not be used on the wasm target"); | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn get(key: Key) -> *mut u8 { | ||
(*(key as *mut Allocated)).value | ||
pub unsafe fn get(_key: Key) -> *mut u8 { | ||
panic!("should not be used on the wasm target"); | ||
} | ||
|
||
#[inline] | ||
pub unsafe fn destroy(key: Key) { | ||
let key = Box::from_raw(key as *mut Allocated); | ||
if let Some(f) = key.dtor { | ||
f(key.value); | ||
} | ||
pub unsafe fn destroy(_key: Key) { | ||
panic!("should not be used on the wasm target"); | ||
} | ||
|
||
#[inline] | ||
pub fn requires_synchronized_create() -> bool { | ||
false | ||
panic!("should not be used on the wasm target"); | ||
} |
This file was deleted.
Oops, something went wrong.
Submodule llvm-project
updated
1288 files