1
+ use core:: cell:: UnsafeCell ;
1
2
use core:: ffi:: c_void;
2
3
use core:: fmt;
4
+ use core:: panic:: { RefUnwindSafe , UnwindSafe } ;
3
5
use core:: ptr:: NonNull ;
4
- use std:: cell:: UnsafeCell ;
5
- use std:: panic:: { RefUnwindSafe , UnwindSafe } ;
6
- use std:: sync:: atomic:: AtomicIsize ;
7
- use std:: sync:: atomic:: Ordering ;
6
+ use core:: sync:: atomic:: { AtomicIsize , Ordering } ;
8
7
9
8
use crate :: ffi;
10
9
@@ -166,13 +165,13 @@ impl Once {
166
165
invoke_dispatch_once ( predicate, work) ;
167
166
}
168
167
169
- // NOTE: Unlike in C, we cannot use `std ::hint::assert_unchecked`,
168
+ // NOTE: Unlike in C, we cannot use `core ::hint::assert_unchecked`,
170
169
// since that would actually be lying from a language perspective;
171
170
// the value seems to only settle on being !0 after some time
172
171
// (something about the _COMM_PAGE_CPU_QUIESCENT_COUNTER?)
173
172
//
174
173
// TODO: Investigate this further!
175
- // std ::hint::assert_unchecked(atomic_predicate.load(Ordering::Acquire) == !0);
174
+ // core ::hint::assert_unchecked(atomic_predicate.load(Ordering::Acquire) == !0);
176
175
} else {
177
176
invoke_dispatch_once ( predicate, work) ;
178
177
}
@@ -196,9 +195,8 @@ impl fmt::Debug for Once {
196
195
197
196
#[ cfg( test) ]
198
197
mod tests {
199
- use std:: cell:: Cell ;
200
- use std:: mem:: ManuallyDrop ;
201
- use std:: thread;
198
+ use core:: cell:: Cell ;
199
+ use core:: mem:: ManuallyDrop ;
202
200
203
201
use super :: * ;
204
202
@@ -249,12 +247,13 @@ mod tests {
249
247
}
250
248
251
249
#[ test]
250
+ #[ cfg( feature = "std" ) ]
252
251
fn test_threaded ( ) {
253
252
let once = Once :: new ( ) ;
254
253
255
254
let num = AtomicIsize :: new ( 0 ) ;
256
255
257
- thread:: scope ( |scope| {
256
+ std :: thread:: scope ( |scope| {
258
257
scope. spawn ( || {
259
258
once. call_once ( || {
260
259
num. fetch_add ( 1 , Ordering :: Relaxed ) ;
@@ -329,9 +328,7 @@ mod tests {
329
328
let once = Once :: new ( ) ;
330
329
331
330
once. call_once ( || {
332
- once. call_once ( || {
333
- println ! ( "foo" ) ;
334
- } ) ;
331
+ once. call_once ( || { } ) ;
335
332
} ) ;
336
333
}
337
334
}
0 commit comments