1
0
mirror of https://github.com/fafhrd91/actix-net synced 2024-11-27 21:22:57 +01:00

better method names

This commit is contained in:
Nikolay Kim 2018-09-14 13:12:55 -07:00
parent 39c3902818
commit 2927a49fdf
3 changed files with 13 additions and 11 deletions

View File

@ -11,15 +11,15 @@ pub struct Counter(Rc<CounterInner>);
struct CounterInner { struct CounterInner {
count: Cell<usize>, count: Cell<usize>,
max: usize, capacity: usize,
task: AtomicTask, task: AtomicTask,
} }
impl Counter { impl Counter {
/// Create `Counter` instance and set max value. /// Create `Counter` instance and set max value.
pub fn new(max: usize) -> Self { pub fn new(capacity: usize) -> Self {
Counter(Rc::new(CounterInner { Counter(Rc::new(CounterInner {
max, capacity,
count: Cell::new(0), count: Cell::new(0),
task: AtomicTask::new(), task: AtomicTask::new(),
})) }))
@ -29,10 +29,12 @@ impl Counter {
CounterGuard::new(self.0.clone()) CounterGuard::new(self.0.clone())
} }
pub fn check(&self) -> bool { /// Check if counter is not at capacity
self.0.check() pub fn available(&self) -> bool {
self.0.available()
} }
/// Get total number of acquired counts
pub fn total(&self) -> usize { pub fn total(&self) -> usize {
self.0.count.get() self.0.count.get()
} }
@ -57,7 +59,7 @@ impl CounterInner {
fn inc(&self) { fn inc(&self) {
let num = self.count.get() + 1; let num = self.count.get() + 1;
self.count.set(num); self.count.set(num);
if num == self.max { if num == self.capacity {
self.task.register(); self.task.register();
} }
} }
@ -65,12 +67,12 @@ impl CounterInner {
fn dec(&self) { fn dec(&self) {
let num = self.count.get(); let num = self.count.get();
self.count.set(num - 1); self.count.set(num - 1);
if num == self.max { if num == self.capacity {
self.task.notify(); self.task.notify();
} }
} }
fn check(&self) -> bool { fn available(&self) -> bool {
self.count.get() < self.max self.count.get() < self.capacity
} }
} }

View File

@ -169,7 +169,7 @@ impl Worker {
} }
fn check_readiness(&mut self) -> Result<bool, usize> { fn check_readiness(&mut self) -> Result<bool, usize> {
let mut ready = self.conns.check(); let mut ready = self.conns.available();
let mut failed = None; let mut failed = None;
for (idx, service) in self.services.iter_mut().enumerate() { for (idx, service) in self.services.iter_mut().enumerate() {
match service.poll_ready() { match service.poll_ready() {

View File

@ -69,7 +69,7 @@ impl<T: AsyncRead + AsyncWrite> Service for OpensslAcceptorService<T> {
type Future = OpensslAcceptorServiceFut<T>; type Future = OpensslAcceptorServiceFut<T>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> { fn poll_ready(&mut self) -> Poll<(), Self::Error> {
if self.conns.check() { if self.conns.available() {
Ok(Async::Ready(())) Ok(Async::Ready(()))
} else { } else {
Ok(Async::NotReady) Ok(Async::NotReady)