@@ -2,9 +2,12 @@ use crate::ffi::CStr;
2
2
use crate :: io;
3
3
use crate :: mem;
4
4
use crate :: ptr;
5
+ use crate :: sync:: {
6
+ atomic:: { AtomicU8 , Ordering :: SeqCst } ,
7
+ Arc ,
8
+ } ;
5
9
use crate :: sys:: mutex:: Mutex ;
6
10
use crate :: time:: Duration ;
7
- use crate :: sync:: { Arc , atomic:: { AtomicU8 , Ordering :: SeqCst } } ;
8
11
9
12
use crate :: sys:: ffi:: * ;
10
13
use crate :: sys:: thread_local;
@@ -27,8 +30,11 @@ unsafe impl Sync for Thread {}
27
30
28
31
impl Thread {
29
32
// unsafe: see thread::Builder::spawn_unchecked for safety requirements
30
- pub unsafe fn new ( name : Option < & CStr > , stack : usize , p : Box < dyn FnOnce ( ) > )
31
- -> io:: Result < Thread > {
33
+ pub unsafe fn new (
34
+ name : Option < & CStr > ,
35
+ stack : usize ,
36
+ p : Box < dyn FnOnce ( ) > ,
37
+ ) -> io:: Result < Thread > {
32
38
let join_mutex = Arc :: new ( Mutex :: new ( ) ) ;
33
39
let state = Arc :: new ( AtomicU8 :: new ( PENDING ) ) ;
34
40
@@ -55,17 +61,22 @@ impl Thread {
55
61
}
56
62
57
63
if res == errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY {
58
- return Err ( io:: Error :: new ( io:: ErrorKind :: Other , "could not allocate required memory for thread" ) ) ;
64
+ return Err ( io:: Error :: new (
65
+ io:: ErrorKind :: Other ,
66
+ "could not allocate required memory for thread" ,
67
+ ) ) ;
59
68
} else {
60
69
return Err ( io:: ErrorKind :: WouldBlock . into ( ) ) ;
61
70
}
62
71
}
63
72
64
73
return Ok ( thread) ;
65
74
66
- extern fn thread_start ( arg : * mut libc:: c_void ) -> * mut libc:: c_void {
75
+ extern "C" fn thread_start ( arg : * mut libc:: c_void ) -> * mut libc:: c_void {
67
76
unsafe {
68
- let arg = Box :: < ( Arc < Mutex > , Arc < AtomicU8 > , Box < Box < dyn FnOnce ( ) > > ) > :: from_raw ( arg as * mut _ ) ;
77
+ let arg = Box :: < ( Arc < Mutex > , Arc < AtomicU8 > , Box < Box < dyn FnOnce ( ) > > ) > :: from_raw (
78
+ arg as * mut _ ,
79
+ ) ;
69
80
let ( join_mutex, state, main) = * arg;
70
81
71
82
join_mutex. lock ( ) ;
@@ -125,7 +136,9 @@ impl Thread {
125
136
}
126
137
}
127
138
128
- pub fn id ( & self ) -> TaskHandle_t { self . id }
139
+ pub fn id ( & self ) -> TaskHandle_t {
140
+ self . id
141
+ }
129
142
130
143
pub fn into_id ( self ) -> TaskHandle_t {
131
144
let id = self . id ;
@@ -149,6 +162,10 @@ impl Drop for Thread {
149
162
pub mod guard {
150
163
use crate :: ops:: Range ;
151
164
pub type Guard = Range < usize > ;
152
- pub unsafe fn current ( ) -> Option < Guard > { None }
153
- pub unsafe fn init ( ) -> Option < Guard > { None }
165
+ pub unsafe fn current ( ) -> Option < Guard > {
166
+ None
167
+ }
168
+ pub unsafe fn init ( ) -> Option < Guard > {
169
+ None
170
+ }
154
171
}
0 commit comments