Skip to content

Commit 75be558

Browse files
authored
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 #110897 This `Key` type seems unused. Let's remove it and see if anything explodes. :)
2 parents c464be9 + 0b3073a commit 75be558

File tree

2 files changed

+1
-80
lines changed

2 files changed

+1
-80
lines changed

library/std/src/sys_common/thread_local_key.rs

-61
Original file line numberDiff line numberDiff line change
@@ -87,31 +87,6 @@ pub struct StaticKey {
8787
dtor: Option<unsafe extern "C" fn(*mut u8)>,
8888
}
8989

90-
/// A type for a safely managed OS-based TLS slot.
91-
///
92-
/// This type allocates an OS TLS key when it is initialized and will deallocate
93-
/// the key when it falls out of scope. When compared with `StaticKey`, this
94-
/// type is entirely safe to use.
95-
///
96-
/// Implementations will likely, however, contain unsafe code as this type only
97-
/// operates on `*mut u8`, a raw pointer.
98-
///
99-
/// # Examples
100-
///
101-
/// ```ignore (cannot-doctest-private-modules)
102-
/// use tls::os::Key;
103-
///
104-
/// let key = Key::new(None);
105-
/// assert!(key.get().is_null());
106-
/// key.set(1 as *mut u8);
107-
/// assert!(!key.get().is_null());
108-
///
109-
/// drop(key); // deallocate this TLS slot.
110-
/// ```
111-
pub struct Key {
112-
key: imp::Key,
113-
}
114-
11590
/// Constant initialization value for static TLS keys.
11691
///
11792
/// This value specifies no destructor by default.
@@ -194,39 +169,3 @@ impl StaticKey {
194169
}
195170
}
196171
}
197-
198-
impl Key {
199-
/// Creates a new managed OS TLS key.
200-
///
201-
/// This key will be deallocated when the key falls out of scope.
202-
///
203-
/// The argument provided is an optionally-specified destructor for the
204-
/// value of this TLS key. When a thread exits and the value for this key
205-
/// is non-null the destructor will be invoked. The TLS value will be reset
206-
/// to null before the destructor is invoked.
207-
///
208-
/// Note that the destructor will not be run when the `Key` goes out of
209-
/// scope.
210-
#[inline]
211-
pub fn new(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
212-
Key { key: unsafe { imp::create(dtor) } }
213-
}
214-
215-
/// See StaticKey::get
216-
#[inline]
217-
pub fn get(&self) -> *mut u8 {
218-
unsafe { imp::get(self.key) }
219-
}
220-
221-
/// See StaticKey::set
222-
#[inline]
223-
pub fn set(&self, val: *mut u8) {
224-
unsafe { imp::set(self.key, val) }
225-
}
226-
}
227-
228-
impl Drop for Key {
229-
fn drop(&mut self) {
230-
unsafe { imp::destroy(self.key) }
231-
}
232-
}

library/std/src/sys_common/thread_local_key/tests.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
1-
use super::{Key, StaticKey};
1+
use super::StaticKey;
22
use core::ptr;
33

4-
fn assert_sync<T: Sync>() {}
5-
fn assert_send<T: Send>() {}
6-
7-
#[test]
8-
fn smoke() {
9-
assert_sync::<Key>();
10-
assert_send::<Key>();
11-
12-
let k1 = Key::new(None);
13-
let k2 = Key::new(None);
14-
assert!(k1.get().is_null());
15-
assert!(k2.get().is_null());
16-
k1.set(ptr::invalid_mut(1));
17-
k2.set(ptr::invalid_mut(2));
18-
assert_eq!(k1.get() as usize, 1);
19-
assert_eq!(k2.get() as usize, 2);
20-
}
21-
224
#[test]
235
fn statik() {
246
static K1: StaticKey = StaticKey::new(None);

0 commit comments

Comments
 (0)