Skip to content

Commit bac7eac

Browse files
committed
Use std::sync::OnceLock instead of async_lock::OnceCell
1 parent 12b4f2e commit bac7eac

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ name = "timer"
2626
harness = false
2727

2828
[dependencies]
29-
async-lock = "3.0.0"
3029
cfg-if = "1"
3130
concurrent-queue = "2.2.0"
3231
futures-io = { version = "0.3.28", default-features = false, features = ["std"] }

src/driver.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use std::cell::{Cell, RefCell};
22
use std::future::Future;
33
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
4-
use std::sync::Arc;
4+
use std::sync::{Arc, OnceLock};
55
use std::task::Waker;
66
use std::task::{Context, Poll};
77
use std::thread;
88
use std::time::{Duration, Instant};
99

10-
use async_lock::OnceCell;
1110
use futures_lite::pin;
1211
use parking::Parker;
1312

@@ -18,9 +17,9 @@ static BLOCK_ON_COUNT: AtomicUsize = AtomicUsize::new(0);
1817

1918
/// Unparker for the "async-io" thread.
2019
fn unparker() -> &'static parking::Unparker {
21-
static UNPARKER: OnceCell<parking::Unparker> = OnceCell::new();
20+
static UNPARKER: OnceLock<parking::Unparker> = OnceLock::new();
2221

23-
UNPARKER.get_or_init_blocking(|| {
22+
UNPARKER.get_or_init(|| {
2423
let (parker, unparker) = parking::pair();
2524

2625
// Spawn a helper thread driving the reactor.

src/reactor.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ use std::mem;
88
use std::panic;
99
use std::pin::Pin;
1010
use std::sync::atomic::{AtomicUsize, Ordering};
11-
use std::sync::{Arc, Mutex, MutexGuard};
11+
use std::sync::{Arc, Mutex, MutexGuard, OnceLock};
1212
use std::task::{Context, Poll, Waker};
1313
use std::time::{Duration, Instant};
1414

15-
use async_lock::OnceCell;
1615
use concurrent_queue::ConcurrentQueue;
1716
use futures_lite::ready;
1817
use polling::{Event, Events, Poller};
@@ -93,9 +92,9 @@ pub(crate) struct Reactor {
9392
impl Reactor {
9493
/// Returns a reference to the reactor.
9594
pub(crate) fn get() -> &'static Reactor {
96-
static REACTOR: OnceCell<Reactor> = OnceCell::new();
95+
static REACTOR: OnceLock<Reactor> = OnceLock::new();
9796

98-
REACTOR.get_or_init_blocking(|| {
97+
REACTOR.get_or_init(|| {
9998
crate::driver::init();
10099
Reactor {
101100
poller: Poller::new().expect("cannot initialize I/O event notification"),

0 commit comments

Comments
 (0)