Skip to content

Commit c83f975

Browse files
ids1024jackpot51
authored andcommitted
Redox: Add JoinHandleExt (matching Unix version)
1 parent ddaab61 commit c83f975

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/libstd/sys/redox/ext/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod ffi;
3333
pub mod fs;
3434
pub mod io;
3535
pub mod process;
36+
pub mod thread;
3637

3738
/// A prelude for conveniently writing platform-specific code.
3839
///
@@ -46,5 +47,7 @@ pub mod prelude {
4647
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
4748
pub use super::fs::{FileTypeExt, PermissionsExt, OpenOptionsExt, MetadataExt};
4849
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
50+
pub use super::thread::JoinHandleExt;
51+
#[doc(no_inline)] #[stable(feature = "rust1", since = "1.0.0")]
4952
pub use super::process::{CommandExt, ExitStatusExt};
5053
}

src/libstd/sys/redox/ext/thread.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! Unix-specific extensions to primitives in the `std::thread` module.
12+
13+
#![stable(feature = "thread_extensions", since = "1.9.0")]
14+
15+
use sys_common::{AsInner, IntoInner};
16+
use thread::JoinHandle;
17+
18+
#[stable(feature = "thread_extensions", since = "1.9.0")]
19+
#[allow(deprecated)]
20+
pub type RawPthread = usize;
21+
22+
/// Unix-specific extensions to `std::thread::JoinHandle`
23+
#[stable(feature = "thread_extensions", since = "1.9.0")]
24+
pub trait JoinHandleExt {
25+
/// Extracts the raw pthread_t without taking ownership
26+
#[stable(feature = "thread_extensions", since = "1.9.0")]
27+
fn as_pthread_t(&self) -> RawPthread;
28+
29+
/// Consumes the thread, returning the raw pthread_t
30+
///
31+
/// This function **transfers ownership** of the underlying pthread_t to
32+
/// the caller. Callers are then the unique owners of the pthread_t and
33+
/// must either detach or join the pthread_t once it's no longer needed.
34+
#[stable(feature = "thread_extensions", since = "1.9.0")]
35+
fn into_pthread_t(self) -> RawPthread;
36+
}
37+
38+
#[stable(feature = "thread_extensions", since = "1.9.0")]
39+
impl<T> JoinHandleExt for JoinHandle<T> {
40+
fn as_pthread_t(&self) -> RawPthread {
41+
self.as_inner().id() as RawPthread
42+
}
43+
44+
fn into_pthread_t(self) -> RawPthread {
45+
self.into_inner().into_id() as RawPthread
46+
}
47+
}

0 commit comments

Comments
 (0)