|
1 | | -use crate::Instant; |
2 | 1 | use std::fmt; |
3 | | -use std::future::Future; |
4 | 2 | use std::mem; |
5 | 3 | use std::pin::Pin; |
6 | 4 | use std::sync::atomic::AtomicUsize; |
7 | 5 | use std::sync::atomic::Ordering::SeqCst; |
8 | 6 | use std::sync::{Arc, Mutex, Weak}; |
9 | 7 | use std::task::{Context, Poll}; |
| 8 | +use std::time::Instant; |
| 9 | + |
| 10 | +use std::future::Future; |
10 | 11 |
|
11 | 12 | use crate::AtomicWaker; |
12 | | -use crate::{ArcList, Heap, HeapTimer, Node, Slot}; |
| 13 | +use crate::{global, ArcList, Heap, HeapTimer, Node, Slot}; |
13 | 14 |
|
14 | 15 | /// A "timer heap" used to power separately owned instances of `Delay`. |
15 | 16 | /// |
@@ -277,39 +278,23 @@ impl Default for TimerHandle { |
277 | 278 | // handle which will return errors when timer objects are attempted to |
278 | 279 | // be associated. |
279 | 280 | if fallback == 0 { |
280 | | - #[cfg(not(target_arch = "wasm32"))] |
281 | | - { |
282 | | - let helper = match crate::global_native::HelperThread::new() { |
283 | | - Ok(helper) => helper, |
284 | | - Err(_) => return TimerHandle { inner: Weak::new() }, |
285 | | - }; |
286 | | - |
287 | | - // If we successfully set ourselves as the actual fallback then we |
288 | | - // want to `forget` the helper thread to ensure that it persists |
289 | | - // globally. If we fail to set ourselves as the fallback that means |
290 | | - // that someone was racing with this call to |
291 | | - // `TimerHandle::default`. They ended up winning so we'll destroy |
292 | | - // our helper thread (which shuts down the thread) and reload the |
293 | | - // fallback. |
294 | | - if helper.handle().set_as_global_fallback().is_ok() { |
295 | | - let ret = helper.handle(); |
296 | | - helper.forget(); |
297 | | - return ret; |
298 | | - } |
299 | | - } |
300 | | - |
301 | | - #[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))] |
302 | | - { |
303 | | - let handle = crate::global_wasm::run(); |
| 281 | + let helper = match global::HelperThread::new() { |
| 282 | + Ok(helper) => helper, |
| 283 | + Err(_) => return TimerHandle { inner: Weak::new() }, |
| 284 | + }; |
304 | 285 |
|
305 | | - // Same as above. |
306 | | - if handle.clone().set_as_global_fallback().is_ok() { |
307 | | - return handle; |
308 | | - } |
| 286 | + // If we successfully set ourselves as the actual fallback then we |
| 287 | + // want to `forget` the helper thread to ensure that it persists |
| 288 | + // globally. If we fail to set ourselves as the fallback that means |
| 289 | + // that someone was racing with this call to |
| 290 | + // `TimerHandle::default`. They ended up winning so we'll destroy |
| 291 | + // our helper thread (which shuts down the thread) and reload the |
| 292 | + // fallback. |
| 293 | + if helper.handle().set_as_global_fallback().is_ok() { |
| 294 | + let ret = helper.handle(); |
| 295 | + helper.forget(); |
| 296 | + return ret; |
309 | 297 | } |
310 | | - #[cfg(all(not(feature = "wasm-bindgen"), target_arch = "wasm32"))] |
311 | | - compile_error!("The `wasm-bindgen` feature must be used when compiling to wasm."); |
312 | | - |
313 | 298 | fallback = HANDLE_FALLBACK.load(SeqCst); |
314 | 299 | } |
315 | 300 |
|
|
0 commit comments