From 2927a49fdfe1c13505694bbba09fcfed63335257 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Fri, 14 Sep 2018 13:12:55 -0700 Subject: [PATCH] better method names --- src/counter.rs | 20 +++++++++++--------- src/server/worker.rs | 2 +- src/ssl/openssl.rs | 2 +- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/counter.rs b/src/counter.rs index d2bd0226..1302c91c 100644 --- a/src/counter.rs +++ b/src/counter.rs @@ -11,15 +11,15 @@ pub struct Counter(Rc); struct CounterInner { count: Cell, - max: usize, + capacity: usize, task: AtomicTask, } impl Counter { /// Create `Counter` instance and set max value. - pub fn new(max: usize) -> Self { + pub fn new(capacity: usize) -> Self { Counter(Rc::new(CounterInner { - max, + capacity, count: Cell::new(0), task: AtomicTask::new(), })) @@ -29,10 +29,12 @@ impl Counter { CounterGuard::new(self.0.clone()) } - pub fn check(&self) -> bool { - self.0.check() + /// Check if counter is not at capacity + pub fn available(&self) -> bool { + self.0.available() } + /// Get total number of acquired counts pub fn total(&self) -> usize { self.0.count.get() } @@ -57,7 +59,7 @@ impl CounterInner { fn inc(&self) { let num = self.count.get() + 1; self.count.set(num); - if num == self.max { + if num == self.capacity { self.task.register(); } } @@ -65,12 +67,12 @@ impl CounterInner { fn dec(&self) { let num = self.count.get(); self.count.set(num - 1); - if num == self.max { + if num == self.capacity { self.task.notify(); } } - fn check(&self) -> bool { - self.count.get() < self.max + fn available(&self) -> bool { + self.count.get() < self.capacity } } diff --git a/src/server/worker.rs b/src/server/worker.rs index a741c35d..0e4e2224 100644 --- a/src/server/worker.rs +++ b/src/server/worker.rs @@ -169,7 +169,7 @@ impl Worker { } fn check_readiness(&mut self) -> Result { - let mut ready = self.conns.check(); + let mut ready = self.conns.available(); let mut failed = None; for (idx, service) in self.services.iter_mut().enumerate() { match service.poll_ready() { diff --git a/src/ssl/openssl.rs b/src/ssl/openssl.rs index 17083c58..26a70011 100644 --- a/src/ssl/openssl.rs +++ b/src/ssl/openssl.rs @@ -69,7 +69,7 @@ impl Service for OpensslAcceptorService { type Future = OpensslAcceptorServiceFut; fn poll_ready(&mut self) -> Poll<(), Self::Error> { - if self.conns.check() { + if self.conns.available() { Ok(Async::Ready(())) } else { Ok(Async::NotReady)