@@ -25,29 +25,44 @@ extern "C" {
2525///
2626/// This type does not detach or free resources on drop. It just leaks the
2727/// thread. To detach or join, call [`detach`] or [`join`] explicitly.
28- #[ derive( Copy , Clone ) ]
28+ // In this library, we assume `libc::pthread` can be casted to and from a
29+ // `usize` and directly compared for equality (without using `pthread_equal`).
30+ // POSIX says that `pthread_t` can be a struct type; if any platform ever
31+ // does that, the code below won't compile, and we'll have to figure out what
32+ // to do about it.
33+ #[ derive( Copy , Clone , Eq , PartialEq ) ]
2934pub struct Thread ( libc:: pthread_t ) ;
3035
3136impl Thread {
32- /// Convert to `Self` from a raw pointer.
37+ /// Convert to `Self` from a raw pointer that was returned from
38+ /// `Thread::to_raw`.
3339 #[ inline]
3440 pub fn from_raw ( raw : * mut c_void ) -> Self {
3541 Self ( raw. expose_addr ( ) as libc:: pthread_t )
3642 }
3743
38- /// Convert to `Self` from a raw non-null pointer.
44+ /// Convert to `Self` from a raw non-null pointer that was returned from
45+ /// `Thread::to_raw_non_null`.
3946 #[ inline]
4047 pub fn from_raw_non_null ( raw : NonNull < c_void > ) -> Self {
4148 Self :: from_raw ( raw. as_ptr ( ) )
4249 }
4350
4451 /// Convert to a raw pointer from a `Self`.
52+ ///
53+ /// This value is guaranteed to uniquely identify a thread, while it is
54+ /// running. After a thread has exited, this value may be reused by new
55+ /// threads.
4556 #[ inline]
4657 pub fn to_raw ( self ) -> * mut c_void {
4758 from_exposed_addr_mut ( self . 0 as usize )
4859 }
4960
5061 /// Convert to a raw non-null pointer from a `Self`.
62+ ///
63+ /// This value is guaranteed to uniquely identify a thread, while it is
64+ /// running. After a thread has exited, this value may be reused by new
65+ /// threads.
5166 #[ inline]
5267 pub fn to_raw_non_null ( self ) -> NonNull < c_void > {
5368 NonNull :: new ( self . to_raw ( ) ) . unwrap ( )
0 commit comments