Fix dead lock in canonical mode

This commit is contained in:
Jianfeng Jiang
2023-06-14 16:36:59 +08:00
committed by Tate, Hongliang Tian
parent bc3b849613
commit 288374ee09
2 changed files with 7 additions and 7 deletions

View File

@ -2,10 +2,11 @@ use core::sync::atomic::{AtomicBool, Ordering};
use alloc::{collections::VecDeque, sync::Arc}; use alloc::{collections::VecDeque, sync::Arc};
use bitflags::bitflags; use bitflags::bitflags;
use spin::mutex::Mutex;
use crate::task::schedule; use crate::task::schedule;
use super::SpinLock;
/// A wait queue. /// A wait queue.
/// ///
/// One may wait on a wait queue to put its executing thread to sleep. /// One may wait on a wait queue to put its executing thread to sleep.
@ -13,14 +14,14 @@ use crate::task::schedule;
/// Other threads may invoke the `wake`-family methods of a wait queue to /// Other threads may invoke the `wake`-family methods of a wait queue to
/// wake up one or many waiter threads. /// wake up one or many waiter threads.
pub struct WaitQueue { pub struct WaitQueue {
waiters: Mutex<VecDeque<Arc<Waiter>>>, waiters: SpinLock<VecDeque<Arc<Waiter>>>,
} }
impl WaitQueue { impl WaitQueue {
/// Creates a new instance. /// Creates a new instance.
pub fn new() -> Self { pub fn new() -> Self {
WaitQueue { WaitQueue {
waiters: Mutex::new(VecDeque::new()), waiters: SpinLock::new(VecDeque::new()),
} }
} }

View File

@ -109,7 +109,7 @@ impl LineDiscipline {
if !current_line.is_empty() { if !current_line.is_empty() {
current_line.backspace(); current_line.backspace();
} }
} else if meet_new_line(item, &self.termios()) { } else if meet_new_line(item, &termios) {
// a new line was met. We currently add the item to buffer. // a new line was met. We currently add the item to buffer.
// when we read content, the item should be skipped if it's EOF. // when we read content, the item should be skipped if it's EOF.
let mut current_line = self.current_line.lock(); let mut current_line = self.current_line.lock();
@ -129,7 +129,7 @@ impl LineDiscipline {
} }
if termios.contain_echo() { if termios.contain_echo() {
self.output_char(item); self.output_char(item, &termios);
} }
if self.is_readable() { if self.is_readable() {
@ -143,12 +143,11 @@ impl LineDiscipline {
} }
// TODO: respect output flags // TODO: respect output flags
fn output_char(&self, item: u8) { fn output_char(&self, item: u8, termios: &KernelTermios) {
if 0x20 <= item && item < 0x7f { if 0x20 <= item && item < 0x7f {
let ch = char::from(item); let ch = char::from(item);
print!("{}", ch); print!("{}", ch);
} }
let termios = self.termios.lock();
if item == *termios.get_special_char(CC_C_CHAR::VERASE) { if item == *termios.get_special_char(CC_C_CHAR::VERASE) {
// write a space to overwrite current character // write a space to overwrite current character
let bytes: [u8; 3] = [b'\x08', b' ', b'\x08']; let bytes: [u8; 3] = [b'\x08', b' ', b'\x08'];