use exclusive_session to eliminate some explicit drops.

This commit is contained in:
Yifan Wu 2022-03-10 16:41:06 -08:00
parent ba611a1458
commit fb196d35a9
8 changed files with 21 additions and 54 deletions

View file

@ -146,7 +146,6 @@ impl<const BASE_ADDR: usize> NS16550a<BASE_ADDR> {
impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {
fn read(&self) -> u8 {
//println!("NS16550a::read");
loop {
let mut inner = self.inner.exclusive_access();
if let Some(ch) = inner.read_buffer.pop_front() {
@ -154,7 +153,6 @@ impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {
} else {
let task_cx_ptr = self.condvar.wait_no_sched();
drop(inner);
//println!("before scheduling");
schedule(task_cx_ptr);
}
}
@ -164,15 +162,13 @@ impl<const BASE_ADDR: usize> CharDevice for NS16550a<BASE_ADDR> {
inner.ns16550a.write(ch);
}
fn handle_irq(&self) {
let mut inner = self.inner.exclusive_access();
let mut count = 0;
while let Some(ch) = inner.ns16550a.read() {
//println!("got {}", ch as char);
count += 1;
inner.read_buffer.push_back(ch);
}
drop(inner);
//assert_eq!(count, 1);
self.inner.exclusive_session(|inner| {
while let Some(ch) = inner.ns16550a.read() {
count += 1;
inner.read_buffer.push_back(ch);
}
});
if count > 0 {
self.condvar.signal();
}