diff --git a/actix-server/src/counter.rs b/actix-server/src/counter.rs index 1302c91c..539ce497 100644 --- a/actix-server/src/counter.rs +++ b/actix-server/src/counter.rs @@ -9,6 +9,7 @@ use futures::task::AtomicTask; /// Counter could be cloned, total ncount is shared across all clones. pub struct Counter(Rc); +#[derive(Debug)] struct CounterInner { count: Cell, capacity: usize, @@ -40,6 +41,7 @@ impl Counter { } } +#[derive(Debug)] pub struct CounterGuard(Rc); impl CounterGuard { @@ -57,11 +59,7 @@ impl Drop for CounterGuard { impl CounterInner { fn inc(&self) { - let num = self.count.get() + 1; - self.count.set(num); - if num == self.capacity { - self.task.register(); - } + self.count.set(self.count.get() + 1); } fn dec(&self) { @@ -73,6 +71,10 @@ impl CounterInner { } fn available(&self) -> bool { - self.count.get() < self.capacity + let avail = self.count.get() < self.capacity; + if !avail { + self.task.register(); + } + avail } } diff --git a/actix-server/src/worker.rs b/actix-server/src/worker.rs index ec8934b9..f72294e2 100644 --- a/actix-server/src/worker.rs +++ b/actix-server/src/worker.rs @@ -398,7 +398,7 @@ impl Future for Worker { let guard = self.conns.get(); let _ = self.services[msg.token.0] .as_mut() - .expect("actix net bug") + .expect("actix-server bug") .1 .call((Some(guard), ServerMessage::Connect(msg.io))); continue;