diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-04-28 10:52:01 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-28 10:52:01 +0900 |
| commit | 75be5580715d2d045302e05d62530ab240f14afe (patch) | |
| tree | 5fb71dbec064a016404443bc3c3a733dfe25bfb1 | |
| parent | c464be96f8dd847477dd00ba6e63977625e5fafe (diff) | |
| parent | 0b3073abb1b4f783deaf3860fe745c586ae2bded (diff) | |
| download | rust-75be5580715d2d045302e05d62530ab240f14afe.tar.gz rust-75be5580715d2d045302e05d62530ab240f14afe.zip | |
Rollup merge of #110898 - m-ou-se:remove-unused-thread-local-key, r=cuviper
Remove unused std::sys_common::thread_local_key::Key Part of https://github.com/rust-lang/rust/issues/110897 This `Key` type seems unused. Let's remove it and see if anything explodes. :)
| -rw-r--r-- | library/std/src/sys_common/thread_local_key.rs | 61 | ||||
| -rw-r--r-- | library/std/src/sys_common/thread_local_key/tests.rs | 20 |
2 files changed, 1 insertions, 80 deletions
diff --git a/library/std/src/sys_common/thread_local_key.rs b/library/std/src/sys_common/thread_local_key.rs index 89360e45601..204834984a2 100644 --- a/library/std/src/sys_common/thread_local_key.rs +++ b/library/std/src/sys_common/thread_local_key.rs @@ -87,31 +87,6 @@ pub struct StaticKey { dtor: Option<unsafe extern "C" fn(*mut u8)>, } -/// A type for a safely managed OS-based TLS slot. -/// -/// This type allocates an OS TLS key when it is initialized and will deallocate -/// the key when it falls out of scope. When compared with `StaticKey`, this -/// type is entirely safe to use. -/// -/// Implementations will likely, however, contain unsafe code as this type only -/// operates on `*mut u8`, a raw pointer. -/// -/// # Examples -/// -/// ```ignore (cannot-doctest-private-modules) -/// use tls::os::Key; -/// -/// let key = Key::new(None); -/// assert!(key.get().is_null()); -/// key.set(1 as *mut u8); -/// assert!(!key.get().is_null()); -/// -/// drop(key); // deallocate this TLS slot. -/// ``` -pub struct Key { - key: imp::Key, -} - /// Constant initialization value for static TLS keys. /// /// This value specifies no destructor by default. @@ -194,39 +169,3 @@ impl StaticKey { } } } - -impl Key { - /// Creates a new managed OS TLS key. - /// - /// This key will be deallocated when the key falls out of scope. - /// - /// The argument provided is an optionally-specified destructor for the - /// value of this TLS key. When a thread exits and the value for this key - /// is non-null the destructor will be invoked. The TLS value will be reset - /// to null before the destructor is invoked. - /// - /// Note that the destructor will not be run when the `Key` goes out of - /// scope. - #[inline] - pub fn new(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key { - Key { key: unsafe { imp::create(dtor) } } - } - - /// See StaticKey::get - #[inline] - pub fn get(&self) -> *mut u8 { - unsafe { imp::get(self.key) } - } - - /// See StaticKey::set - #[inline] - pub fn set(&self, val: *mut u8) { - unsafe { imp::set(self.key, val) } - } -} - -impl Drop for Key { - fn drop(&mut self) { - unsafe { imp::destroy(self.key) } - } -} diff --git a/library/std/src/sys_common/thread_local_key/tests.rs b/library/std/src/sys_common/thread_local_key/tests.rs index 6f32b858f09..6a44c65d918 100644 --- a/library/std/src/sys_common/thread_local_key/tests.rs +++ b/library/std/src/sys_common/thread_local_key/tests.rs @@ -1,24 +1,6 @@ -use super::{Key, StaticKey}; +use super::StaticKey; use core::ptr; -fn assert_sync<T: Sync>() {} -fn assert_send<T: Send>() {} - -#[test] -fn smoke() { - assert_sync::<Key>(); - assert_send::<Key>(); - - let k1 = Key::new(None); - let k2 = Key::new(None); - assert!(k1.get().is_null()); - assert!(k2.get().is_null()); - k1.set(ptr::invalid_mut(1)); - k2.set(ptr::invalid_mut(2)); - assert_eq!(k1.get() as usize, 1); - assert_eq!(k2.get() as usize, 2); -} - #[test] fn statik() { static K1: StaticKey = StaticKey::new(None); |
