]> git.lizzy.rs Git - rust.git/commitdiff
AsRawHandle and IntoRawHandle for JoinHandle
authorPeter Atashian <retep998@gmail.com>
Thu, 29 Oct 2015 20:54:09 +0000 (16:54 -0400)
committerPeter Atashian <retep998@gmail.com>
Sat, 5 Dec 2015 01:09:30 +0000 (20:09 -0500)
This allows users to get the HANDLE of a spawned thread on Windows

Signed-off-by: Peter Atashian <retep998@gmail.com>
src/libstd/sys/windows/ext/mod.rs
src/libstd/sys/windows/ext/thread.rs [new file with mode: 0644]
src/libstd/sys/windows/thread.rs
src/libstd/thread/mod.rs

index 7f095ae7ff6b51ca3fd82ced9933a8a14528c5a1..c3578fdfdb16ba452c68051f3ddb1cb7e2ff14fa 100644 (file)
@@ -21,6 +21,7 @@
 pub mod io;
 pub mod raw;
 pub mod process;
+pub mod thread;
 
 /// A prelude for conveniently writing platform-specific code.
 ///
diff --git a/src/libstd/sys/windows/ext/thread.rs b/src/libstd/sys/windows/ext/thread.rs
new file mode 100644 (file)
index 0000000..3a07204
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+//! Extensions to `std::thread` for Windows.
+
+#![unstable(feature = "thread_extensions", issue = "29791")]
+
+use os::windows::io::{RawHandle, AsRawHandle, IntoRawHandle};
+use thread;
+use sys_common::{AsInner, IntoInner};
+
+impl<T> AsRawHandle for thread::JoinHandle<T> {
+    fn as_raw_handle(&self) -> RawHandle {
+        self.as_inner().handle().raw() as *mut _
+    }
+}
+
+impl<T> IntoRawHandle for thread::JoinHandle<T>  {
+    fn into_raw_handle(self) -> RawHandle {
+        self.into_inner().into_handle().into_raw() as *mut _
+    }
+}
index a6e6cc94b7679cc42a11e13fa9f48a4e81dceb9b..1ba8586756311b46664d09ca36e97da8dd2446e7 100644 (file)
@@ -77,6 +77,10 @@ pub fn sleep(dur: Duration) {
             c::Sleep(super::dur2timeout(dur))
         }
     }
+
+    pub fn handle(&self) -> &Handle { &self.handle }
+
+    pub fn into_handle(self) -> Handle { self.handle }
 }
 
 pub mod guard {
index eaa32cdb3424d8cc9e7da8256f9cf8f7d460cca9..aef47aa57263b5b818fb56bb4488fa72489e714b 100644 (file)
 use sys_common::thread_info;
 use sys_common::unwind;
 use sys_common::util;
+use sys_common::{AsInner, IntoInner};
 use time::Duration;
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -621,6 +622,14 @@ pub fn join(mut self) -> Result<T> {
     }
 }
 
+impl<T> AsInner<imp::Thread> for JoinHandle<T> {
+    fn as_inner(&self) -> &imp::Thread { self.0.native.as_ref().unwrap() }
+}
+
+impl<T> IntoInner<imp::Thread> for JoinHandle<T> {
+    fn into_inner(self) -> imp::Thread { self.0.native.unwrap() }
+}
+
 fn _assert_sync_and_send() {
     fn _assert_both<T: Send + Sync>() {}
     _assert_both::<JoinHandle<()>>();