]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys/unix/ext/thread.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / 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.
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 #[allow(deprecated)]
16 use os::unix::raw::pthread_t;
17 use sys_common::{AsInner, IntoInner};
18 use thread::JoinHandle;
19
20 #[stable(feature = "thread_extensions", since = "1.9.0")]
21 #[allow(deprecated)]
22 pub type RawPthread = pthread_t;
23
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;
30
31 /// Consumes the thread, returning the raw pthread_t
32 ///
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;
38 }
39
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
44 }
45
46 fn into_pthread_t(self) -> RawPthread {
47 self.into_inner().into_id() as RawPthread
48 }
49 }