Skip to content
Snippets Groups Projects
Commit a97aa95c authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Improve wait condition performance

parent 962836aa
No related branches found
No related tags found
No related merge requests found
use alloc::arc::Arc; use alloc::arc::Arc;
use collections::Vec; use collections::Vec;
use core::mem;
use spin::{Mutex, RwLock}; use spin::{Mutex, RwLock};
use context::{self, Context}; use context::{self, Context};
...@@ -13,17 +12,17 @@ pub struct WaitCondition { ...@@ -13,17 +12,17 @@ pub struct WaitCondition {
impl WaitCondition { impl WaitCondition {
pub fn new() -> WaitCondition { pub fn new() -> WaitCondition {
WaitCondition { WaitCondition {
contexts: Mutex::new(Vec::new()) contexts: Mutex::new(Vec::with_capacity(16))
} }
} }
pub fn notify(&self) -> usize { pub fn notify(&self) -> usize {
let mut contexts = Vec::new(); let mut contexts = self.contexts.lock();
mem::swap(&mut *self.contexts.lock(), &mut contexts); let len = contexts.len();
for context_lock in contexts.iter() { while let Some(context_lock) = contexts.pop() {
context_lock.write().unblock(); context_lock.write().unblock();
} }
contexts.len() len
} }
pub fn wait(&self) { pub fn wait(&self) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment