diff options
| author | linouxis9 <[email protected]> | 2018-05-07 15:31:54 +0200 |
|---|---|---|
| committer | linouxis9 <[email protected]> | 2018-05-07 15:35:20 +0200 |
| commit | 4901431b02227416b08e5fbc9a7ac3f5ac2f44a7 (patch) | |
| tree | 7fb75cf805b8f0e9b7f169af37c9d2aa0c4aded6 /ctr-std/src/thread | |
| parent | Merge pull request #66 from FenrirWolf/swkbd (diff) | |
| download | ctru-rs-4901431b02227416b08e5fbc9a7ac3f5ac2f44a7.tar.xz ctru-rs-4901431b02227416b08e5fbc9a7ac3f5ac2f44a7.zip | |
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")] |