From 9982a9498d5c36be672101e939d9576cd681aa52 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 8 Oct 2019 15:02:43 +0600 Subject: [PATCH] register current task in counters available method. --- actix-utils/CHANGES.md | 5 +++++ actix-utils/Cargo.toml | 2 +- actix-utils/src/counter.rs | 17 ++++++++++------- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/actix-utils/CHANGES.md b/actix-utils/CHANGES.md index 97131b76..d2db8811 100644 --- a/actix-utils/CHANGES.md +++ b/actix-utils/CHANGES.md @@ -1,5 +1,10 @@ # Changes +## [0.4.6] - 2019-10-08 + +* Refactor `Counter` type. register current task in available method. + + ## [0.4.5] - 2019-07-19 ### Removed diff --git a/actix-utils/Cargo.toml b/actix-utils/Cargo.toml index f4f11ab6..b687d030 100644 --- a/actix-utils/Cargo.toml +++ b/actix-utils/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "actix-utils" -version = "0.4.5" +version = "0.4.6" authors = ["Nikolay Kim "] description = "Actix utils - various actix net related services" keywords = ["network", "framework", "async", "futures"] diff --git a/actix-utils/src/counter.rs b/actix-utils/src/counter.rs index 1302c91c..2f355094 100644 --- a/actix-utils/src/counter.rs +++ b/actix-utils/src/counter.rs @@ -25,11 +25,13 @@ impl Counter { })) } + /// Get counter guard. pub fn get(&self) -> CounterGuard { CounterGuard::new(self.0.clone()) } - /// Check if counter is not at capacity + /// Check if counter is not at capacity. If counter at capacity + /// it registers notification for current task. pub fn available(&self) -> bool { self.0.available() } @@ -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,11 @@ impl CounterInner { } fn available(&self) -> bool { - self.count.get() < self.capacity + if self.count.get() < self.capacity { + true + } else { + self.task.register(); + false + } } }