mirror of
https://github.com/fafhrd91/actix-net
synced 2024-11-24 01:11:07 +01:00
Return worker index in WakerInterest::WorkerAvailable (#337)
This commit is contained in:
parent
20c2da17ed
commit
bd48908792
@ -238,11 +238,10 @@ impl Accept {
|
|||||||
match guard.pop_front() {
|
match guard.pop_front() {
|
||||||
// worker notify it becomes available. we may want to recover
|
// worker notify it becomes available. we may want to recover
|
||||||
// from backpressure.
|
// from backpressure.
|
||||||
Some(WakerInterest::WorkerAvailable) => {
|
Some(WakerInterest::WorkerAvailable(idx)) => {
|
||||||
drop(guard);
|
drop(guard);
|
||||||
// Assume all worker are avail as no worker index returned.
|
|
||||||
self.avail.set_available_all(&self.handles);
|
|
||||||
self.maybe_backpressure(&mut sockets, false);
|
self.maybe_backpressure(&mut sockets, false);
|
||||||
|
self.avail.set_available(idx, true);
|
||||||
}
|
}
|
||||||
// a new worker thread is made and it's handle would be added to Accept
|
// a new worker thread is made and it's handle would be added to Accept
|
||||||
Some(WakerInterest::Worker(handle)) => {
|
Some(WakerInterest::Worker(handle)) => {
|
||||||
|
@ -320,7 +320,7 @@ impl ServerBuilder {
|
|||||||
idx: usize,
|
idx: usize,
|
||||||
waker: WakerQueue,
|
waker: WakerQueue,
|
||||||
) -> (WorkerHandleAccept, WorkerHandleServer) {
|
) -> (WorkerHandleAccept, WorkerHandleServer) {
|
||||||
let avail = WorkerAvailability::new(waker);
|
let avail = WorkerAvailability::new(idx, waker);
|
||||||
let services = self.services.iter().map(|v| v.clone_factory()).collect();
|
let services = self.services.iter().map(|v| v.clone_factory()).collect();
|
||||||
|
|
||||||
ServerWorker::start(idx, services, avail, self.worker_config)
|
ServerWorker::start(idx, services, avail, self.worker_config)
|
||||||
|
@ -72,7 +72,7 @@ impl WakerQueue {
|
|||||||
pub(crate) enum WakerInterest {
|
pub(crate) enum WakerInterest {
|
||||||
/// `WorkerAvailable` is an interest from `Worker` notifying `Accept` there is a worker
|
/// `WorkerAvailable` is an interest from `Worker` notifying `Accept` there is a worker
|
||||||
/// available and can accept new tasks.
|
/// available and can accept new tasks.
|
||||||
WorkerAvailable,
|
WorkerAvailable(usize),
|
||||||
/// `Pause`, `Resume`, `Stop` Interest are from `ServerBuilder` future. It listens to
|
/// `Pause`, `Resume`, `Stop` Interest are from `ServerBuilder` future. It listens to
|
||||||
/// `ServerCommand` and notify `Accept` to do exactly these tasks.
|
/// `ServerCommand` and notify `Accept` to do exactly these tasks.
|
||||||
Pause,
|
Pause,
|
||||||
|
@ -96,13 +96,15 @@ impl WorkerHandleServer {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct WorkerAvailability {
|
pub(crate) struct WorkerAvailability {
|
||||||
|
idx: usize,
|
||||||
waker: WakerQueue,
|
waker: WakerQueue,
|
||||||
available: Arc<AtomicBool>,
|
available: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkerAvailability {
|
impl WorkerAvailability {
|
||||||
pub fn new(waker: WakerQueue) -> Self {
|
pub fn new(idx: usize, waker: WakerQueue) -> Self {
|
||||||
WorkerAvailability {
|
WorkerAvailability {
|
||||||
|
idx,
|
||||||
waker,
|
waker,
|
||||||
available: Arc::new(AtomicBool::new(false)),
|
available: Arc::new(AtomicBool::new(false)),
|
||||||
}
|
}
|
||||||
@ -116,7 +118,7 @@ impl WorkerAvailability {
|
|||||||
let old = self.available.swap(val, Ordering::Release);
|
let old = self.available.swap(val, Ordering::Release);
|
||||||
// notify the accept on switched to available.
|
// notify the accept on switched to available.
|
||||||
if !old && val {
|
if !old && val {
|
||||||
self.waker.wake(WakerInterest::WorkerAvailable);
|
self.waker.wake(WakerInterest::WorkerAvailable(self.idx));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user