1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#![feature(doc_cfg)]
#![allow(clippy::missing_safety_doc)]
use std::thread::JoinHandle;
macro_rules! unbracket {
(_ [$($tt1:tt)*]) => { $($tt1)* };
(() [$($tt1:tt)*]) => { ($($tt1)*) };
([] [$($tt1:tt)*]) => { [$($tt1)*] };
({} [$($tt1:tt)*]) => { {$($tt1)*} };
($tt0:tt [$($tt1:tt)*] @unbracket ($($tt2:tt)*) $($tt3:tt)*) => { unbracket!{ $tt0 [$($tt1)* $($tt2)*] $($tt3)*} };
($tt0:tt [$($tt1:tt)*] @unbracket [$($tt2:tt)*] $($tt3:tt)*) => { unbracket!{ $tt0 [$($tt1)* $($tt2)*] $($tt3)*} };
($tt0:tt [$($tt1:tt)*] @unbracket {$($tt2:tt)*} $($tt3:tt)*) => { unbracket!{ $tt0 [$($tt1)* $($tt2)*] $($tt3)*} };
($tt0:tt [$($tt1:tt)*] $tt2:tt $($tt3:tt)*) => { unbracket!{$tt0 [$($tt1)* $tt2] $($tt3)*} };
}
macro_rules! cfg_doc {
($(#[doc=$doc0:literal])+ decl: $decl:tt $($($(#[doc=$doc1:literal])+)? if $cfg:tt $body:tt)*) => {
unbracket! {_ []
#[cfg(doc)]
#[doc(cfg(any($($cfg),*)))]
$(#[doc=$doc0])+
$($(
$(#[doc=$doc1])+
)?)*
@unbracket $decl {
unimplemented!("Documentation implementation!");
}
$(
#[cfg(all(not(doc), $cfg))]
@unbracket $decl
$body
)*
}
}
}
cfg_doc! {
decl: [pub unsafe fn kill_thread_graceful<T>(handle: JoinHandle<T>)]
if unix {
use std::os::unix::thread::JoinHandleExt;
use libc::pthread_cancel;
let raw_handle = handle.into_pthread_t();
pthread_cancel(raw_handle);
}
}
cfg_doc! {
decl: [pub unsafe fn kill_thread_forcibly_exit_code<T>(handle: JoinHandle<T>, exit_code: u32)]
if windows {
use std::os::windows::io::IntoRawHandle;
use winapi::um::processthreadsapi::TerminateThread;
use winapi::ctypes::c_void as winapi_c_void;
let raw_handle = handle.into_raw_handle();
TerminateThread(raw_handle as *mut winapi_c_void, exit_code);
}
}
cfg_doc! {
decl: [pub unsafe fn suspend_thread<T>(handle: JoinHandle<T>)]
if windows {
use std::os::windows::io::IntoRawHandle;
use winapi::um::processthreadsapi::SuspendThread;
use winapi::ctypes::c_void as winapi_c_void;
let raw_handle = handle.into_raw_handle();
SuspendThread(raw_handle as *mut winapi_c_void);
}
}