Make the file lookup faster

This commit is contained in:
Ruihan Li
2024-12-26 21:35:56 +08:00
committed by Tate, Hongliang Tian
parent fb8f493b43
commit b9ce3e64ad
59 changed files with 483 additions and 390 deletions

View File

@ -1,7 +1,10 @@
// SPDX-License-Identifier: MPL-2.0
use super::SyscallReturn;
use crate::{fs::file_table::FileDesc, prelude::*};
use crate::{
fs::file_table::{get_file_fast, FileDesc},
prelude::*,
};
pub fn sys_read(
fd: FileDesc,
@ -14,10 +17,8 @@ pub fn sys_read(
fd, user_buf_addr, buf_len
);
let file = {
let file_table = ctx.posix_thread.file_table().lock();
file_table.get_file(fd)?.clone()
};
let mut file_table = ctx.thread_local.file_table().borrow_mut();
let file = get_file_fast!(&mut file_table, fd);
// According to <https://man7.org/linux/man-pages/man2/read.2.html>, if
// the user specified an empty buffer, we should detect errors by checking