From d2cfbcfa3476aaf20da945813a3393825cc04340 Mon Sep 17 00:00:00 2001 From: Serge Barral Date: Tue, 18 Oct 2022 12:19:36 +0200 Subject: [PATCH] Replace the `Parker` crate by `crossbeam_utils` --- asynchronix/Cargo.toml | 2 +- asynchronix/src/runtime/executor.rs | 16 +++++++++------- asynchronix/src/runtime/executor/pool_manager.rs | 6 ++++-- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/asynchronix/Cargo.toml b/asynchronix/Cargo.toml index 6a9599b..96dae5c 100644 --- a/asynchronix/Cargo.toml +++ b/asynchronix/Cargo.toml @@ -20,7 +20,7 @@ dev-hooks = [] dev-logs = [] [dependencies] -parking = "2.0" +crossbeam-utils = "0.8" slab = "0.4" cache-padded = "1.1" num_cpus = "1.13" diff --git a/asynchronix/src/runtime/executor.rs b/asynchronix/src/runtime/executor.rs index 045b0af..9d993e8 100644 --- a/asynchronix/src/runtime/executor.rs +++ b/asynchronix/src/runtime/executor.rs @@ -49,7 +49,7 @@ use std::sync::{Arc, Mutex}; use std::thread::{self, JoinHandle}; use std::time::{Duration, Instant}; -use parking::Parker; +use crossbeam_utils::sync::{Parker, Unparker}; use slab::Slab; mod find_bit; @@ -86,7 +86,7 @@ pub(crate) struct Executor { /// List of tasks that have not completed yet. active_tasks: Arc>>, /// Parker for the main executor thread. - parker: parking::Parker, + parker: Parker, /// Join handles of the worker threads. worker_handles: Vec>, } @@ -96,11 +96,13 @@ impl Executor { /// /// The maximum number of threads is set with the `num_threads` parameter. pub(crate) fn new(num_threads: usize) -> Self { - let (parker, unparker) = parking::pair(); + let parker = Parker::new(); + let unparker = parker.unparker().clone(); let (local_data, shared_data): (Vec<_>, Vec<_>) = (0..num_threads) .map(|_| { - let (parker, unparker) = parking::pair(); + let parker = Parker::new(); + let unparker = parker.unparker().clone(); let local_queue = LocalQueue::new(); let stealer = local_queue.stealer(); @@ -282,7 +284,7 @@ struct ExecutorContext { /// Unique executor ID inherited by all tasks spawned on this executor instance. executor_id: usize, /// Unparker for the main executor thread. - executor_unparker: parking::Unparker, + executor_unparker: Unparker, /// Manager for all worker threads. pool_manager: PoolManager, } @@ -291,8 +293,8 @@ impl ExecutorContext { /// Creates a new shared executor context. pub(super) fn new( executor_id: usize, - executor_unparker: parking::Unparker, - shared_data: impl Iterator, + executor_unparker: Unparker, + shared_data: impl Iterator, ) -> Self { let (stealers, worker_unparkers): (Vec<_>, Vec<_>) = shared_data.into_iter().unzip(); let worker_unparkers = worker_unparkers.into_boxed_slice(); diff --git a/asynchronix/src/runtime/executor/pool_manager.rs b/asynchronix/src/runtime/executor/pool_manager.rs index c1e327f..d0577d1 100644 --- a/asynchronix/src/runtime/executor/pool_manager.rs +++ b/asynchronix/src/runtime/executor/pool_manager.rs @@ -2,6 +2,8 @@ use std::any::Any; use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering}; use std::sync::Mutex; +use crossbeam_utils::sync::Unparker; + use super::find_bit; use super::rng; use super::Stealer; @@ -16,7 +18,7 @@ pub(super) struct PoolManager { /// List of the stealers associated to each worker thread. stealers: Box<[Stealer]>, /// List of the thread unparkers associated to each worker thread. - worker_unparkers: Box<[parking::Unparker]>, + worker_unparkers: Box<[Unparker]>, /// Bit field of all workers that are currently unparked. active_workers: AtomicUsize, /// Count of all workers currently searching for tasks. @@ -40,7 +42,7 @@ impl PoolManager { pub(super) fn new( pool_size: usize, stealers: Box<[Stealer]>, - worker_unparkers: Box<[parking::Unparker]>, + worker_unparkers: Box<[Unparker]>, ) -> Self { assert!( pool_size >= 1,