Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove async-lock in favor of OnceLock #203

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ name = "async-io"
version = "2.3.4"
authors = ["Stjepan Glavina <[email protected]>"]
edition = "2021"
rust-version = "1.63"
rust-version = "1.70"
description = "Async I/O and timers"
license = "Apache-2.0 OR MIT"
repository = "https://github.com/smol-rs/async-io"
Expand All @@ -26,7 +26,6 @@ name = "timer"
harness = false

[dependencies]
async-lock = "3.0.0"
cfg-if = "1"
concurrent-queue = "2.2.0"
futures-io = { version = "0.3.28", default-features = false, features = ["std"] }
Expand Down
7 changes: 3 additions & 4 deletions src/driver.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::cell::{Cell, RefCell};
use std::future::Future;
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
use std::sync::Arc;
use std::sync::{Arc, OnceLock};
use std::task::Waker;
use std::task::{Context, Poll};
use std::thread;
use std::time::{Duration, Instant};

use async_lock::OnceCell;
use futures_lite::pin;
use parking::Parker;

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

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

UNPARKER.get_or_init_blocking(|| {
UNPARKER.get_or_init(|| {
let (parker, unparker) = parking::pair();

// Spawn a helper thread driving the reactor.
Expand Down
6 changes: 3 additions & 3 deletions src/reactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use std::mem;
use std::panic;
use std::pin::Pin;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::OnceLock;
use std::sync::{Arc, Mutex, MutexGuard};
use std::task::{Context, Poll, Waker};
use std::time::{Duration, Instant};

use async_lock::OnceCell;
use concurrent_queue::ConcurrentQueue;
use futures_lite::ready;
use polling::{Event, Events, Poller};
Expand Down Expand Up @@ -93,9 +93,9 @@ pub(crate) struct Reactor {
impl Reactor {
/// Returns a reference to the reactor.
pub(crate) fn get() -> &'static Reactor {
static REACTOR: OnceCell<Reactor> = OnceCell::new();
static REACTOR: OnceLock<Reactor> = OnceLock::new();

REACTOR.get_or_init_blocking(|| {
REACTOR.get_or_init(|| {
crate::driver::init();
Reactor {
poller: Poller::new().expect("cannot initialize I/O event notification"),
Expand Down
Loading