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.
This commit is contained in:
Wez Furlong
2025-02-24 13:51:18 -07:00
parent 0666374f58
commit f915a7fbfa
+7 -4
View File
@@ -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(())
}