1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-23 22:51:07 +01:00

Return worker index in WakerInterest::WorkerAvailable (#337)

This commit is contained in:
fakeshadow 2021-04-15 21:59:10 -07:00 committed by GitHub
parent 20c2da17ed
commit bd48908792
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 7 deletions

View File

@ -238,11 +238,10 @@ impl Accept {
match guard.pop_front() {
// worker notify it becomes available. we may want to recover
// from backpressure.
Some(WakerInterest::WorkerAvailable) => {
Some(WakerInterest::WorkerAvailable(idx)) => {
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.avail.set_available(idx, true);
}
// a new worker thread is made and it's handle would be added to Accept
Some(WakerInterest::Worker(handle)) => {

View File

@ -320,7 +320,7 @@ impl ServerBuilder {
idx: usize,
waker: WakerQueue,
) -> (WorkerHandleAccept, WorkerHandleServer) {
let avail = WorkerAvailability::new(waker);
let avail = WorkerAvailability::new(idx, waker);
let services = self.services.iter().map(|v| v.clone_factory()).collect();
ServerWorker::start(idx, services, avail, self.worker_config)

View File

@ -72,7 +72,7 @@ impl WakerQueue {
pub(crate) enum WakerInterest {
/// `WorkerAvailable` is an interest from `Worker` notifying `Accept` there is a worker
/// available and can accept new tasks.
WorkerAvailable,
WorkerAvailable(usize),
/// `Pause`, `Resume`, `Stop` Interest are from `ServerBuilder` future. It listens to
/// `ServerCommand` and notify `Accept` to do exactly these tasks.
Pause,

View File

@ -96,13 +96,15 @@ impl WorkerHandleServer {
#[derive(Clone)]
pub(crate) struct WorkerAvailability {
idx: usize,
waker: WakerQueue,
available: Arc<AtomicBool>,
}
impl WorkerAvailability {
pub fn new(waker: WakerQueue) -> Self {
pub fn new(idx: usize, waker: WakerQueue) -> Self {
WorkerAvailability {
idx,
waker,
available: Arc::new(AtomicBool::new(false)),
}
@ -116,7 +118,7 @@ impl WorkerAvailability {
let old = self.available.swap(val, Ordering::Release);
// notify the accept on switched to available.
if !old && val {
self.waker.wake(WakerInterest::WorkerAvailable);
self.waker.wake(WakerInterest::WorkerAvailable(self.idx));
}
}
}