Use SpinLock on FileTable for efficiency

This commit is contained in:
Shaowei Song
2024-09-13 03:36:33 +00:00
committed by Tate, Hongliang Tian
parent 4a43e317b2
commit 1186fb7ca9
14 changed files with 108 additions and 66 deletions

View File

@ -8,6 +8,7 @@ use crate::{
pub fn sys_lseek(fd: FileDesc, offset: isize, whence: u32, ctx: &Context) -> Result<SyscallReturn> {
debug!("fd = {}, offset = {}, whence = {}", fd, offset, whence);
let seek_from = match whence {
0 => {
if offset < 0 {
@ -19,8 +20,11 @@ pub fn sys_lseek(fd: FileDesc, offset: isize, whence: u32, ctx: &Context) -> Res
2 => SeekFrom::End(offset),
_ => return_errno!(Errno::EINVAL),
};
let file_table = ctx.process.file_table().lock();
let file = file_table.get_file(fd)?;
let file = {
let file_table = ctx.process.file_table().lock();
file_table.get_file(fd)?.clone()
};
let offset = file.seek(seek_from)?;
Ok(SyscallReturn::Return(offset as _))
}