]> git.lizzy.rs Git - rust.git/commitdiff
Add JoinHandleExt to get the pthread_t on unix platforms
authorPeter Atashian <retep998@gmail.com>
Fri, 4 Dec 2015 02:58:00 +0000 (21:58 -0500)
committerPeter Atashian <retep998@gmail.com>
Sat, 5 Dec 2015 01:09:32 +0000 (20:09 -0500)
Signed-off-by: Peter Atashian <retep998@gmail.com>
14 files changed:
src/libstd/os/android/raw.rs
src/libstd/os/bitrig/raw.rs
src/libstd/os/dragonfly/raw.rs
src/libstd/os/freebsd/raw.rs
src/libstd/os/ios/raw.rs
src/libstd/os/linux/raw.rs
src/libstd/os/macos/raw.rs
src/libstd/os/nacl/raw.rs
src/libstd/os/netbsd/raw.rs
src/libstd/os/openbsd/raw.rs
src/libstd/sys/unix/ext/mod.rs
src/libstd/sys/unix/ext/raw.rs
src/libstd/sys/unix/ext/thread.rs [new file with mode: 0644]
src/libstd/sys/unix/thread.rs

index fe28a73875696959505878e7f032270f6c53392a..e58ba03ec67ae999802f277979d236df7c4bc86f 100644 (file)
 
 #![stable(feature = "raw_ext", since = "1.1.0")]
 
+use os::raw::c_long;
+
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = c_long;
+
 #[doc(inline)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
 pub use self::arch::{dev_t, mode_t, blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t};
index 45e46b252a4abfc2cd2e386367685813edea72b5..81de8810cba5db277f32adb578eac9aac4ed0378 100644 (file)
@@ -25,6 +25,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index cb692b0662aad5e0bc63f5e47b251e98f55fa010..581aebebc034f8f9d6059b067a4dee448205cbc6 100644 (file)
@@ -25,6 +25,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index cb8fadbfd6edf1f30e97a7b5514aefc7f7744eec..a1e39721bcf63056fc501eed9c04469a8ecc3633 100644 (file)
@@ -21,6 +21,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type fflags_t = u32;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[doc(inline)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
 pub use self::arch::{stat, time_t};
index aeb3e993a72f4fd8e856978ade5a27f3ecc3d23c..20fe833a98076930eb5e597f67155acf4050190b 100644 (file)
@@ -24,6 +24,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index 35de9bfc194d615cc96c7b19a5de2824fcc8a59f..f44199f311bfa7298a5e86eb57c8e12365270360 100644 (file)
 
 #![stable(feature = "raw_ext", since = "1.1.0")]
 
+use os::raw::c_ulong;
+
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = c_ulong;
+
 #[doc(inline)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
 pub use self::arch::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
index 4abd6f2d4dea3507946dd77b0d30beb7374442b9..1407132b9c96de52583005f46be7a4ab9bbf6f8f 100644 (file)
@@ -24,6 +24,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = c_long;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index 36f8a5fb5c923264a2b0c100d0c06a9b2dc62b9c..7258a14aaf4b357d258738a2ca435d7d505074e9 100644 (file)
@@ -24,6 +24,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Copy, Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index 882d08c66065e7b631c92189eaa6669cb869df57..9ca58924955103c1e18f90771b3d7e14fd925d77 100644 (file)
@@ -25,6 +25,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index 1cc0eedfcd050a6c6cf38aa7879b8014a797f6ef..209546c4e4f5626f383907e88df398a64bad639e 100644 (file)
@@ -25,6 +25,8 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64;
 
+#[unstable(feature = "pthread_t", issue = "29791")] pub type pthread_t = usize;
+
 #[repr(C)]
 #[derive(Clone)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
index b57e325089d26bb4c7495a2728dc628dd9bd9e5c..276ef25a03a448bb7c38d0e05bbcc72160cb459d 100644 (file)
@@ -34,6 +34,7 @@
 pub mod fs;
 pub mod process;
 pub mod raw;
+pub mod thread;
 
 /// A prelude for conveniently writing platform-specific code.
 ///
index 8377e53f4178bda7d89d70cc545b02bbfea146e8..d1cc6cba51dbc06dfc7e1e1518f65e5da2116276 100644 (file)
@@ -16,6 +16,9 @@
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32;
 #[stable(feature = "raw_ext", since = "1.1.0")] pub type pid_t = i32;
 
+#[doc(inline)]
+#[unstable(feature = "pthread_t", issue = "29791")]
+pub use sys::platform::raw::pthread_t;
 #[doc(inline)]
 #[stable(feature = "raw_ext", since = "1.1.0")]
 pub use sys::platform::raw::{dev_t, ino_t, mode_t, nlink_t, off_t, blksize_t};
diff --git a/src/libstd/sys/unix/ext/thread.rs b/src/libstd/sys/unix/ext/thread.rs
new file mode 100644 (file)
index 0000000..c1c1609
--- /dev/null
@@ -0,0 +1,43 @@
+// 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.
+
+//! Unix-specific extensions to primitives in the `std::process` module.
+
+#![unstable(feature = "thread_extensions", issue = "29791")]
+
+use os::unix::raw::{pthread_t};
+use sys_common::{AsInner, IntoInner};
+use thread::{JoinHandle};
+
+#[unstable(feature = "thread_extensions", issue = "29791")]
+pub type RawPthread = pthread_t;
+
+/// Unix-specific extensions to `std::thread::JoinHandle`
+#[unstable(feature = "thread_extensions", issue = "29791")]
+pub trait JoinHandleExt {
+    /// Extracts the raw pthread_t without taking ownership
+    fn as_pthread_t(&self) -> RawPthread;
+    /// Consumes the thread, returning the raw pthread_t
+    ///
+    /// This function **transfers ownership** of the underlying pthread_t to
+    /// the caller. Callers are then the unique owners of the pthread_t and
+    /// must either detech or join the pthread_t once it's no longer needed.
+    fn into_pthread_t(self) -> RawPthread;
+}
+
+#[unstable(feature = "thread_extensions", issue = "29791")]
+impl<T> JoinHandleExt for JoinHandle<T> {
+    fn as_pthread_t(&self) -> RawPthread {
+        self.as_inner().id() as RawPthread
+    }
+    fn into_pthread_t(self) -> RawPthread {
+        self.into_inner().into_id() as RawPthread
+    }
+}
index f111f97be60a049184c82d8c24aba0daeb4ad505..4d715b579c6c5d9d5b14bbb8006ed0cd2a406e90 100644 (file)
@@ -152,6 +152,14 @@ pub fn join(self) {
             debug_assert_eq!(ret, 0);
         }
     }
+
+    pub fn id(&self) -> libc::pthread_t { self.id }
+
+    pub fn into_id(self) -> libc::pthread_t {
+        let id = self.id;
+        mem::forget(self);
+        id
+    }
 }
 
 impl Drop for Thread {