]>
git.proxmox.com Git - rustc.git/blob - src/libstd/sys/unix/ext/thread.rs
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.
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.
11 //! Unix-specific extensions to primitives in the `std::thread` module.
13 #![stable(feature = "thread_extensions", since = "1.9.0")]
16 use os
::unix
::raw
::pthread_t
;
17 use sys_common
::{AsInner, IntoInner}
;
18 use thread
::JoinHandle
;
20 #[stable(feature = "thread_extensions", since = "1.9.0")]
22 pub type RawPthread
= pthread_t
;
24 /// Unix-specific extensions to `std::thread::JoinHandle`
25 #[stable(feature = "thread_extensions", since = "1.9.0")]
26 pub trait JoinHandleExt
{
27 /// Extracts the raw pthread_t without taking ownership
28 #[stable(feature = "thread_extensions", since = "1.9.0")]
29 fn as_pthread_t(&self) -> RawPthread
;
31 /// Consumes the thread, returning the raw pthread_t
33 /// This function **transfers ownership** of the underlying pthread_t to
34 /// the caller. Callers are then the unique owners of the pthread_t and
35 /// must either detach or join the pthread_t once it's no longer needed.
36 #[stable(feature = "thread_extensions", since = "1.9.0")]
37 fn into_pthread_t(self) -> RawPthread
;
40 #[stable(feature = "thread_extensions", since = "1.9.0")]
41 impl<T
> JoinHandleExt
for JoinHandle
<T
> {
42 fn as_pthread_t(&self) -> RawPthread
{
43 self.as_inner().id() as RawPthread
46 fn into_pthread_t(self) -> RawPthread
{
47 self.into_inner().into_id() as RawPthread