mirror of https://github.com/fafhrd91/actix-net
update changelog
This commit is contained in:
parent
bb245c796e
commit
180a107223
|
@ -8,8 +8,10 @@
|
||||||
* Rename `Arbiter::{send => spawn}` and `Arbiter::{exec_fn => spawn_fn}`. [#253]
|
* Rename `Arbiter::{send => spawn}` and `Arbiter::{exec_fn => spawn_fn}`. [#253]
|
||||||
* Remove `Arbiter::exec`. [#253]
|
* Remove `Arbiter::exec`. [#253]
|
||||||
* Remove deprecated `Arbiter::local_join` and `Arbiter::is_running`. [#253]
|
* Remove deprecated `Arbiter::local_join` and `Arbiter::is_running`. [#253]
|
||||||
|
* Rename `Arbiter => Worker`. [#254]
|
||||||
|
|
||||||
[#253]: https://github.com/actix/actix-net/pull/253
|
[#253]: https://github.com/actix/actix-net/pull/253
|
||||||
|
[#254]: https://github.com/actix/actix-net/pull/254
|
||||||
|
|
||||||
|
|
||||||
## 2.0.0-beta.2 - 2021-01-09
|
## 2.0.0-beta.2 - 2021-01-09
|
||||||
|
|
|
@ -22,7 +22,6 @@ macros = ["actix-macros"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-macros = { version = "0.2.0-beta.1", optional = true }
|
actix-macros = { version = "0.2.0-beta.1", optional = true }
|
||||||
|
|
||||||
ahash = "0.7"
|
|
||||||
futures-core = { version = "0.3", default-features = false }
|
futures-core = { version = "0.3", default-features = false }
|
||||||
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
tokio = { version = "1", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] }
|
||||||
|
|
||||||
|
|
|
@ -6,9 +6,9 @@ use tokio::sync::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
worker::Worker,
|
|
||||||
runtime::Runtime,
|
runtime::Runtime,
|
||||||
system::{System, SystemWorker},
|
system::{System, SystemWorker},
|
||||||
|
worker::Worker,
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Builder an actix runtime.
|
/// Builder an actix runtime.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use std::{
|
use std::{
|
||||||
any::{Any, TypeId},
|
any::{Any, TypeId},
|
||||||
cell::RefCell,
|
cell::RefCell,
|
||||||
|
collections::HashMap,
|
||||||
fmt,
|
fmt,
|
||||||
future::Future,
|
future::Future,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
|
@ -9,12 +10,8 @@ use std::{
|
||||||
thread,
|
thread,
|
||||||
};
|
};
|
||||||
|
|
||||||
use ahash::AHashMap;
|
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use tokio::{
|
use tokio::{sync::mpsc, task::LocalSet};
|
||||||
sync::mpsc::{unbounded_channel, UnboundedReceiver, UnboundedSender},
|
|
||||||
task::LocalSet,
|
|
||||||
};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
runtime::Runtime,
|
runtime::Runtime,
|
||||||
|
@ -25,7 +22,7 @@ pub(crate) static COUNT: AtomicUsize = AtomicUsize::new(0);
|
||||||
|
|
||||||
thread_local!(
|
thread_local!(
|
||||||
static ADDR: RefCell<Option<Worker>> = RefCell::new(None);
|
static ADDR: RefCell<Option<Worker>> = RefCell::new(None);
|
||||||
static STORAGE: RefCell<AHashMap<TypeId, Box<dyn Any>>> = RefCell::new(AHashMap::new());
|
static STORAGE: RefCell<HashMap<TypeId, Box<dyn Any>>> = RefCell::new(HashMap::new());
|
||||||
);
|
);
|
||||||
|
|
||||||
pub(crate) enum WorkerCommand {
|
pub(crate) enum WorkerCommand {
|
||||||
|
@ -51,13 +48,13 @@ impl fmt::Debug for WorkerCommand {
|
||||||
/// Some Arbiter functions execute on the current thread.
|
/// Some Arbiter functions execute on the current thread.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Worker {
|
pub struct Worker {
|
||||||
sender: UnboundedSender<WorkerCommand>,
|
sender: mpsc::UnboundedSender<WorkerCommand>,
|
||||||
thread_handle: Option<thread::JoinHandle<()>>,
|
thread_handle: Option<thread::JoinHandle<()>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for Worker {
|
impl Clone for Worker {
|
||||||
fn clone(&self) -> Self {
|
fn clone(&self) -> Self {
|
||||||
Self::new_with_sender(self.sender.clone())
|
Self::new_handle(self.sender.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,9 +66,9 @@ impl Default for Worker {
|
||||||
|
|
||||||
impl Worker {
|
impl Worker {
|
||||||
pub(crate) fn new_system(local: &LocalSet) -> Self {
|
pub(crate) fn new_system(local: &LocalSet) -> Self {
|
||||||
let (tx, rx) = unbounded_channel();
|
let (tx, rx) = mpsc::unbounded_channel();
|
||||||
|
|
||||||
let arb = Worker::new_with_sender(tx);
|
let arb = Worker::new_handle(tx);
|
||||||
ADDR.with(|cell| *cell.borrow_mut() = Some(arb.clone()));
|
ADDR.with(|cell| *cell.borrow_mut() = Some(arb.clone()));
|
||||||
STORAGE.with(|cell| cell.borrow_mut().clear());
|
STORAGE.with(|cell| cell.borrow_mut().clear());
|
||||||
|
|
||||||
|
@ -80,7 +77,7 @@ impl Worker {
|
||||||
arb
|
arb
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new_with_sender(sender: UnboundedSender<WorkerCommand>) -> Self {
|
fn new_handle(sender: mpsc::UnboundedSender<WorkerCommand>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
sender,
|
sender,
|
||||||
thread_handle: None,
|
thread_handle: None,
|
||||||
|
@ -110,7 +107,7 @@ impl Worker {
|
||||||
let id = COUNT.fetch_add(1, Ordering::Relaxed);
|
let id = COUNT.fetch_add(1, Ordering::Relaxed);
|
||||||
let name = format!("actix-rt:worker:{}", id);
|
let name = format!("actix-rt:worker:{}", id);
|
||||||
let sys = System::current();
|
let sys = System::current();
|
||||||
let (tx, rx) = unbounded_channel();
|
let (tx, rx) = mpsc::unbounded_channel();
|
||||||
|
|
||||||
let handle = thread::Builder::new()
|
let handle = thread::Builder::new()
|
||||||
.name(name.clone())
|
.name(name.clone())
|
||||||
|
@ -118,7 +115,7 @@ impl Worker {
|
||||||
let tx = tx.clone();
|
let tx = tx.clone();
|
||||||
move || {
|
move || {
|
||||||
let rt = Runtime::new().expect("Can not create Runtime");
|
let rt = Runtime::new().expect("Can not create Runtime");
|
||||||
let arb = Worker::new_with_sender(tx);
|
let arb = Worker::new_handle(tx);
|
||||||
|
|
||||||
STORAGE.with(|cell| cell.borrow_mut().clear());
|
STORAGE.with(|cell| cell.borrow_mut().clear());
|
||||||
|
|
||||||
|
@ -179,8 +176,10 @@ impl Worker {
|
||||||
.is_ok()
|
.is_ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Insert item to worker's thread-local storage.
|
/// Insert item into worker's thread-local storage.
|
||||||
pub fn insert_item<T: 'static>(item: T) {
|
///
|
||||||
|
/// Overwrites any item of the same type previously inserted.
|
||||||
|
pub fn set_item<T: 'static>(item: T) {
|
||||||
STORAGE.with(move |cell| cell.borrow_mut().insert(TypeId::of::<T>(), Box::new(item)));
|
STORAGE.with(move |cell| cell.borrow_mut().insert(TypeId::of::<T>(), Box::new(item)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +215,7 @@ impl Worker {
|
||||||
///
|
///
|
||||||
/// # Panics
|
/// # Panics
|
||||||
/// Panics if item is not in worker's thread-local item storage.
|
/// Panics if item is not in worker's thread-local item storage.
|
||||||
pub fn get_item_mut<T: 'static, F, R>(mut f: F) -> R
|
pub fn get_mut_item<T: 'static, F, R>(mut f: F) -> R
|
||||||
where
|
where
|
||||||
F: FnMut(&mut T) -> R,
|
F: FnMut(&mut T) -> R,
|
||||||
{
|
{
|
||||||
|
@ -244,7 +243,7 @@ impl Worker {
|
||||||
|
|
||||||
/// A persistent worker future that processes worker commands.
|
/// A persistent worker future that processes worker commands.
|
||||||
struct WorkerRunner {
|
struct WorkerRunner {
|
||||||
rx: UnboundedReceiver<WorkerCommand>,
|
rx: mpsc::UnboundedReceiver<WorkerCommand>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for WorkerRunner {
|
impl Drop for WorkerRunner {
|
||||||
|
|
Loading…
Reference in New Issue