From f915a7fbfac23eec25bb69c7c3955c570f033596 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 24 Feb 2025 13:51:18 -0700 Subject: [PATCH] ready_queue: micro optimize: release lock before bumping counters The counter bump should just be a sequence of atomic additions, but it's still desirable to do that outside of the critical section. --- crates/kumod/src/ready_queue.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/kumod/src/ready_queue.rs b/crates/kumod/src/ready_queue.rs index 1d96125c..0375349a 100644 --- a/crates/kumod/src/ready_queue.rs +++ b/crates/kumod/src/ready_queue.rs @@ -113,11 +113,14 @@ impl Fifo { } pub fn push(&self, msg: Message) -> Result<(), Message> { - let mut list = self.list.lock(); - if list.len() + 1 > self.capacity.load(Ordering::Relaxed) { - return Err(msg); + { + let mut list = self.list.lock(); + if list.len() + 1 > self.capacity.load(Ordering::Relaxed) { + return Err(msg); + } + list.push_back(msg); } - list.push_back(msg); + // Increment the count after we've dropped the mutexguard on the list self.count.inc(); Ok(()) }