forked from ROMEO/nexosim
Replace the Parker
crate by crossbeam_utils
This commit is contained in:
parent
c3ca7fc0e1
commit
d2cfbcfa34
@ -20,7 +20,7 @@ dev-hooks = []
|
|||||||
dev-logs = []
|
dev-logs = []
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parking = "2.0"
|
crossbeam-utils = "0.8"
|
||||||
slab = "0.4"
|
slab = "0.4"
|
||||||
cache-padded = "1.1"
|
cache-padded = "1.1"
|
||||||
num_cpus = "1.13"
|
num_cpus = "1.13"
|
||||||
|
@ -49,7 +49,7 @@ use std::sync::{Arc, Mutex};
|
|||||||
use std::thread::{self, JoinHandle};
|
use std::thread::{self, JoinHandle};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use parking::Parker;
|
use crossbeam_utils::sync::{Parker, Unparker};
|
||||||
use slab::Slab;
|
use slab::Slab;
|
||||||
|
|
||||||
mod find_bit;
|
mod find_bit;
|
||||||
@ -86,7 +86,7 @@ pub(crate) struct Executor {
|
|||||||
/// List of tasks that have not completed yet.
|
/// List of tasks that have not completed yet.
|
||||||
active_tasks: Arc<Mutex<Slab<CancelToken>>>,
|
active_tasks: Arc<Mutex<Slab<CancelToken>>>,
|
||||||
/// Parker for the main executor thread.
|
/// Parker for the main executor thread.
|
||||||
parker: parking::Parker,
|
parker: Parker,
|
||||||
/// Join handles of the worker threads.
|
/// Join handles of the worker threads.
|
||||||
worker_handles: Vec<JoinHandle<()>>,
|
worker_handles: Vec<JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
@ -96,11 +96,13 @@ impl Executor {
|
|||||||
///
|
///
|
||||||
/// The maximum number of threads is set with the `num_threads` parameter.
|
/// The maximum number of threads is set with the `num_threads` parameter.
|
||||||
pub(crate) fn new(num_threads: usize) -> Self {
|
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)
|
let (local_data, shared_data): (Vec<_>, Vec<_>) = (0..num_threads)
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let (parker, unparker) = parking::pair();
|
let parker = Parker::new();
|
||||||
|
let unparker = parker.unparker().clone();
|
||||||
let local_queue = LocalQueue::new();
|
let local_queue = LocalQueue::new();
|
||||||
let stealer = local_queue.stealer();
|
let stealer = local_queue.stealer();
|
||||||
|
|
||||||
@ -282,7 +284,7 @@ struct ExecutorContext {
|
|||||||
/// Unique executor ID inherited by all tasks spawned on this executor instance.
|
/// Unique executor ID inherited by all tasks spawned on this executor instance.
|
||||||
executor_id: usize,
|
executor_id: usize,
|
||||||
/// Unparker for the main executor thread.
|
/// Unparker for the main executor thread.
|
||||||
executor_unparker: parking::Unparker,
|
executor_unparker: Unparker,
|
||||||
/// Manager for all worker threads.
|
/// Manager for all worker threads.
|
||||||
pool_manager: PoolManager,
|
pool_manager: PoolManager,
|
||||||
}
|
}
|
||||||
@ -291,8 +293,8 @@ impl ExecutorContext {
|
|||||||
/// Creates a new shared executor context.
|
/// Creates a new shared executor context.
|
||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
executor_id: usize,
|
executor_id: usize,
|
||||||
executor_unparker: parking::Unparker,
|
executor_unparker: Unparker,
|
||||||
shared_data: impl Iterator<Item = (Stealer, parking::Unparker)>,
|
shared_data: impl Iterator<Item = (Stealer, Unparker)>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let (stealers, worker_unparkers): (Vec<_>, Vec<_>) = shared_data.into_iter().unzip();
|
let (stealers, worker_unparkers): (Vec<_>, Vec<_>) = shared_data.into_iter().unzip();
|
||||||
let worker_unparkers = worker_unparkers.into_boxed_slice();
|
let worker_unparkers = worker_unparkers.into_boxed_slice();
|
||||||
|
@ -2,6 +2,8 @@ use std::any::Any;
|
|||||||
use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
|
use std::sync::atomic::{self, AtomicBool, AtomicUsize, Ordering};
|
||||||
use std::sync::Mutex;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
use crossbeam_utils::sync::Unparker;
|
||||||
|
|
||||||
use super::find_bit;
|
use super::find_bit;
|
||||||
use super::rng;
|
use super::rng;
|
||||||
use super::Stealer;
|
use super::Stealer;
|
||||||
@ -16,7 +18,7 @@ pub(super) struct PoolManager {
|
|||||||
/// List of the stealers associated to each worker thread.
|
/// List of the stealers associated to each worker thread.
|
||||||
stealers: Box<[Stealer]>,
|
stealers: Box<[Stealer]>,
|
||||||
/// List of the thread unparkers associated to each worker thread.
|
/// 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.
|
/// Bit field of all workers that are currently unparked.
|
||||||
active_workers: AtomicUsize,
|
active_workers: AtomicUsize,
|
||||||
/// Count of all workers currently searching for tasks.
|
/// Count of all workers currently searching for tasks.
|
||||||
@ -40,7 +42,7 @@ impl PoolManager {
|
|||||||
pub(super) fn new(
|
pub(super) fn new(
|
||||||
pool_size: usize,
|
pool_size: usize,
|
||||||
stealers: Box<[Stealer]>,
|
stealers: Box<[Stealer]>,
|
||||||
worker_unparkers: Box<[parking::Unparker]>,
|
worker_unparkers: Box<[Unparker]>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
assert!(
|
assert!(
|
||||||
pool_size >= 1,
|
pool_size >= 1,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user