dope_sys/thread/handle.rs
1use std::ptr;
2
3use o3::base::marker::ThreadBound;
4
5use crate::kernel;
6
7/// One joinable native thread, joined on drop by its creating thread.
8#[repr(transparent)]
9pub struct Handle(pub(super) libc::pthread_t, pub(super) ThreadBound);
10
11impl Handle {
12 /// Joins the uniquely owned thread from its creating thread.
13 /// Native failure terminates before worker storage can be reclaimed.
14 pub fn join(self) {
15 drop(self);
16 }
17}
18
19impl Drop for Handle {
20 fn drop(&mut self) {
21 // SAFETY: successful spawn created this unique joinable handle, retained
22 // by its creating thread. pthread_join returns zero or a positive error
23 // code, which is checked before the owner can reclaim worker storage.
24 if let Err(cause) = unsafe {
25 kernel::raw::Status::new(libc::pthread_join(self.0, ptr::null_mut())).try_pthread()
26 } {
27 kernel::Fatal::Join(cause).terminate()
28 }
29 }
30}