aboutsummaryrefslogtreecommitdiff
path: root/ctr-std/src/sys/unix/fast_thread_local.rs
diff options
context:
space:
mode:
authorFenrir <[email protected]>2017-07-26 01:53:40 -0600
committerFenrir <[email protected]>2017-07-26 01:53:40 -0600
commit361c812e6aba4a414304457fb9170014159e4978 (patch)
tree6ac98462bd1eb469b2b09623719142bc87d62861 /ctr-std/src/sys/unix/fast_thread_local.rs
parentMerge pull request #36 from FenrirWolf/errDisp (diff)
downloadarchived-ctru-rs-361c812e6aba4a414304457fb9170014159e4978.tar.xz
archived-ctru-rs-361c812e6aba4a414304457fb9170014159e4978.zip
Thread fixes + module update
Diffstat (limited to 'ctr-std/src/sys/unix/fast_thread_local.rs')
-rw-r--r--ctr-std/src/sys/unix/fast_thread_local.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/ctr-std/src/sys/unix/fast_thread_local.rs b/ctr-std/src/sys/unix/fast_thread_local.rs
index 6eeae2d..9f0eee0 100644
--- a/ctr-std/src/sys/unix/fast_thread_local.rs
+++ b/ctr-std/src/sys/unix/fast_thread_local.rs
@@ -12,9 +12,10 @@
#![unstable(feature = "thread_local_internals", issue = "0")]
use cell::{Cell, UnsafeCell};
-use intrinsics;
+use mem;
use ptr;
+
pub struct Key<T> {
inner: UnsafeCell<Option<T>>,
@@ -37,7 +38,7 @@ impl<T> Key<T> {
pub fn get(&'static self) -> Option<&'static UnsafeCell<Option<T>>> {
unsafe {
- if intrinsics::needs_drop::<T>() && self.dtor_running.get() {
+ if mem::needs_drop::<T>() && self.dtor_running.get() {
return None
}
self.register_dtor();
@@ -46,7 +47,7 @@ impl<T> Key<T> {
}
unsafe fn register_dtor(&self) {
- if !intrinsics::needs_drop::<T>() || self.dtor_registered.get() {
+ if !mem::needs_drop::<T>() || self.dtor_registered.get() {
return
}
@@ -56,7 +57,7 @@ impl<T> Key<T> {
}
}
-unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
+pub unsafe fn register_dtor(t: *mut u8, dtor: unsafe extern fn(*mut u8)) {
// The fallback implementation uses a vanilla OS-based TLS key to track
// the list of destructors that need to be run for this thread. The key
// then has its own destructor which runs all the other destructors.
@@ -96,17 +97,17 @@ pub unsafe extern fn destroy_value<T>(ptr: *mut u8) {
// `None`.
(*ptr).dtor_running.set(true);
- // The OSX implementation of TLS apparently had an odd aspect to it
+ // The macOS implementation of TLS apparently had an odd aspect to it
// where the pointer we have may be overwritten while this destructor
// is running. Specifically if a TLS destructor re-accesses TLS it may
// trigger a re-initialization of all TLS variables, paving over at
// least some destroyed ones with initial values.
//
- // This means that if we drop a TLS value in place on OSX that we could
+ // This means that if we drop a TLS value in place on macOS that we could
// revert the value to its original state halfway through the
// destructor, which would be bad!
//
- // Hence, we use `ptr::read` on OSX (to move to a "safe" location)
+ // Hence, we use `ptr::read` on macOS (to move to a "safe" location)
// instead of drop_in_place.
if cfg!(target_os = "macos") {
ptr::read((*ptr).inner.get());
@@ -114,3 +115,7 @@ pub unsafe extern fn destroy_value<T>(ptr: *mut u8) {
ptr::drop_in_place((*ptr).inner.get());
}
}
+
+pub fn requires_move_before_drop() -> bool {
+ false
+}