about summary refs log tree commit diff
path: root/src/libstd/rt/thread_local_storage.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-11-27 09:57:05 -0800
committerbors <bors@rust-lang.org>2013-11-27 09:57:05 -0800
commite4136bd552bc7bf2b83ceb5d114f9a254bfa2b01 (patch)
tree3b5accbf93dabd0921e46e326918a1c0e5bef263 /src/libstd/rt/thread_local_storage.rs
parenta6fc577ab580d09f05bb9b545b6a6511cfcb0a8f (diff)
parent5d6dbf3f262fabcb6cb920dd08be6f9d8df75d5c (diff)
downloadrust-e4136bd552bc7bf2b83ceb5d114f9a254bfa2b01.tar.gz
rust-e4136bd552bc7bf2b83ceb5d114f9a254bfa2b01.zip
auto merge of #10662 : alexcrichton/rust/thread-detach, r=pcwalton
This has one commit from a separate pull request (because these commits depend on that one), but otherwise the extra details can be found in the commit messages. The `rt::thread` module has been generally cleaned up for everyday safe usage (and it's a bug if it's not safe).
Diffstat (limited to 'src/libstd/rt/thread_local_storage.rs')
-rw-r--r--src/libstd/rt/thread_local_storage.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs
index 8fa64852846..62e1b6c50d6 100644
--- a/src/libstd/rt/thread_local_storage.rs
+++ b/src/libstd/rt/thread_local_storage.rs
@@ -34,6 +34,11 @@ pub unsafe fn get(key: Key) -> *mut c_void {
     pthread_getspecific(key)
 }
 
+#[cfg(unix)]
+pub unsafe fn destroy(key: Key) {
+    assert_eq!(0, pthread_key_delete(key));
+}
+
 #[cfg(target_os="macos")]
 #[allow(non_camel_case_types)] // foreign type
 type pthread_key_t = ::libc::c_ulong;
@@ -47,6 +52,7 @@ type pthread_key_t = ::libc::c_uint;
 #[cfg(unix)]
 extern {
     fn pthread_key_create(key: *mut pthread_key_t, dtor: *u8) -> c_int;
+    fn pthread_key_delete(key: pthread_key_t) -> c_int;
     fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
     fn pthread_setspecific(key: pthread_key_t, value: *mut c_void) -> c_int;
 }
@@ -72,8 +78,14 @@ pub unsafe fn get(key: Key) -> *mut c_void {
 }
 
 #[cfg(windows)]
+pub unsafe fn destroy(key: Key) {
+    assert!(TlsFree(key) != 0);
+}
+
+#[cfg(windows)]
 extern "system" {
     fn TlsAlloc() -> DWORD;
+    fn TlsFree(dwTlsIndex: DWORD) -> BOOL;
     fn TlsGetValue(dwTlsIndex: DWORD) -> LPVOID;
     fn TlsSetValue(dwTlsIndex: DWORD, lpTlsvalue: LPVOID) -> BOOL;
 }