From 38531e2ecc2173b7c8b8c91497c7e319a79f7de9 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 20 Oct 2016 21:49:47 -0600 Subject: [PATCH] Improve wait condition performance --- kernel/sync/wait_condition.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel/sync/wait_condition.rs b/kernel/sync/wait_condition.rs index 997b458..cb17026 100644 --- a/kernel/sync/wait_condition.rs +++ b/kernel/sync/wait_condition.rs @@ -1,6 +1,5 @@ use alloc::arc::Arc; use collections::Vec; -use core::mem; use spin::{Mutex, RwLock}; use context::{self, Context}; @@ -13,17 +12,17 @@ pub struct WaitCondition { impl WaitCondition { pub fn new() -> WaitCondition { WaitCondition { - contexts: Mutex::new(Vec::new()) + contexts: Mutex::new(Vec::with_capacity(16)) } } pub fn notify(&self) -> usize { - let mut contexts = Vec::new(); - mem::swap(&mut *self.contexts.lock(), &mut contexts); - for context_lock in contexts.iter() { + let mut contexts = self.contexts.lock(); + let len = contexts.len(); + while let Some(context_lock) = contexts.pop() { context_lock.write().unblock(); } - contexts.len() + len } pub fn wait(&self) {