diff options
| author | FenrirWolf <[email protected]> | 2018-06-10 11:49:19 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2018-06-10 11:49:19 -0600 |
| commit | 49041a4e56a4cab33ae7889537d33670e8b012fb (patch) | |
| tree | 0c931e8716200f9aa8c7daef47b62474d0285d5c /ctr-std/src/thread | |
| parent | Merge pull request #69 from FenrirWolf/libctru-1.5.0 (diff) | |
| parent | Fixes according to Fenrir's review (diff) | |
| download | ctru-rs-49041a4e56a4cab33ae7889537d33670e8b012fb.tar.xz ctru-rs-49041a4e56a4cab33ae7889537d33670e8b012fb.zip | |
Merge pull request #68 from linouxis9/master
Update for latest nightly 2018-05-06
Diffstat (limited to 'ctr-std/src/thread')
| -rw-r--r-- | ctr-std/src/thread/local.rs | 41 | ||||
| -rw-r--r-- | ctr-std/src/thread/mod.rs | 3 |
2 files changed, 42 insertions, 2 deletions
diff --git a/ctr-std/src/thread/local.rs b/ctr-std/src/thread/local.rs index 99479bc..40d3280 100644 --- a/ctr-std/src/thread/local.rs +++ b/ctr-std/src/thread/local.rs @@ -172,12 +172,16 @@ macro_rules! __thread_local_inner { &'static $crate::cell::UnsafeCell< $crate::option::Option<$t>>> { + #[cfg(target_arch = "wasm32")] + static __KEY: $crate::thread::__StaticLocalKeyInner<$t> = + $crate::thread::__StaticLocalKeyInner::new(); + #[thread_local] - #[cfg(target_thread_local)] + #[cfg(all(target_thread_local, not(target_arch = "wasm32")))] static __KEY: $crate::thread::__FastLocalKeyInner<$t> = $crate::thread::__FastLocalKeyInner::new(); - #[cfg(not(target_thread_local))] + #[cfg(all(not(target_thread_local), not(target_arch = "wasm32")))] static __KEY: $crate::thread::__OsLocalKeyInner<$t> = $crate::thread::__OsLocalKeyInner::new(); @@ -295,6 +299,39 @@ impl<T: 'static> LocalKey<T> { } } +/// On some platforms like wasm32 there's no threads, so no need to generate +/// thread locals and we can instead just use plain statics! +#[doc(hidden)] +#[cfg(target_arch = "wasm32")] +pub mod statik { + use cell::UnsafeCell; + use fmt; + + pub struct Key<T> { + inner: UnsafeCell<Option<T>>, + } + + unsafe impl<T> ::marker::Sync for Key<T> { } + + impl<T> fmt::Debug for Key<T> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.pad("Key { .. }") + } + } + + impl<T> Key<T> { + pub const fn new() -> Key<T> { + Key { + inner: UnsafeCell::new(None), + } + } + + pub unsafe fn get(&self) -> Option<&'static UnsafeCell<Option<T>>> { + Some(&*(&self.inner as *const _)) + } + } +} + #[doc(hidden)] #[cfg(target_thread_local)] pub mod fast { diff --git a/ctr-std/src/thread/mod.rs b/ctr-std/src/thread/mod.rs index 71aee67..1b976b7 100644 --- a/ctr-std/src/thread/mod.rs +++ b/ctr-std/src/thread/mod.rs @@ -203,6 +203,9 @@ pub use self::local::{LocalKey, AccessError}; // where available, but both are needed. #[unstable(feature = "libstd_thread_internals", issue = "0")] +#[cfg(target_arch = "wasm32")] +#[doc(hidden)] pub use self::local::statik::Key as __StaticLocalKeyInner; +#[unstable(feature = "libstd_thread_internals", issue = "0")] #[cfg(target_thread_local)] #[doc(hidden)] pub use self::local::fast::Key as __FastLocalKeyInner; #[unstable(feature = "libstd_thread_internals", issue = "0")] |