mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 02:43:24 +00:00
Use SpinLock
on FileTable
for efficiency
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
4a43e317b2
commit
1186fb7ca9
@ -394,16 +394,16 @@ fn clone_fs(
|
||||
}
|
||||
|
||||
fn clone_files(
|
||||
parent_file_table: &Arc<Mutex<FileTable>>,
|
||||
parent_file_table: &Arc<SpinLock<FileTable>>,
|
||||
clone_flags: CloneFlags,
|
||||
) -> Arc<Mutex<FileTable>> {
|
||||
) -> Arc<SpinLock<FileTable>> {
|
||||
// if CLONE_FILES is set, the child and parent shares the same file table
|
||||
// Otherwise, the child will deep copy a new file table.
|
||||
// FIXME: the clone may not be deep copy.
|
||||
if clone_flags.contains(CloneFlags::CLONE_FILES) {
|
||||
parent_file_table.clone()
|
||||
} else {
|
||||
Arc::new(Mutex::new(parent_file_table.lock().clone()))
|
||||
Arc::new(SpinLock::new(parent_file_table.lock().clone()))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub struct ProcessBuilder<'a> {
|
||||
argv: Option<Vec<CString>>,
|
||||
envp: Option<Vec<CString>>,
|
||||
process_vm: Option<ProcessVm>,
|
||||
file_table: Option<Arc<Mutex<FileTable>>>,
|
||||
file_table: Option<Arc<SpinLock<FileTable>>>,
|
||||
fs: Option<Arc<RwMutex<FsResolver>>>,
|
||||
umask: Option<Arc<RwLock<FileCreationMask>>>,
|
||||
resource_limits: Option<ResourceLimits>,
|
||||
@ -67,7 +67,7 @@ impl<'a> ProcessBuilder<'a> {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn file_table(&mut self, file_table: Arc<Mutex<FileTable>>) -> &mut Self {
|
||||
pub fn file_table(&mut self, file_table: Arc<SpinLock<FileTable>>) -> &mut Self {
|
||||
self.file_table = Some(file_table);
|
||||
self
|
||||
}
|
||||
@ -152,7 +152,7 @@ impl<'a> ProcessBuilder<'a> {
|
||||
let process_vm = process_vm.or_else(|| Some(ProcessVm::alloc())).unwrap();
|
||||
|
||||
let file_table = file_table
|
||||
.or_else(|| Some(Arc::new(Mutex::new(FileTable::new_with_stdio()))))
|
||||
.or_else(|| Some(Arc::new(SpinLock::new(FileTable::new_with_stdio()))))
|
||||
.unwrap();
|
||||
|
||||
let fs = fs
|
||||
|
@ -79,7 +79,7 @@ pub struct Process {
|
||||
/// Process group
|
||||
pub(super) process_group: Mutex<Weak<ProcessGroup>>,
|
||||
/// File table
|
||||
file_table: Arc<Mutex<FileTable>>,
|
||||
file_table: Arc<SpinLock<FileTable>>,
|
||||
/// FsResolver
|
||||
fs: Arc<RwMutex<FsResolver>>,
|
||||
/// umask
|
||||
@ -180,7 +180,7 @@ impl Process {
|
||||
process_vm: ProcessVm,
|
||||
|
||||
fs: Arc<RwMutex<FsResolver>>,
|
||||
file_table: Arc<Mutex<FileTable>>,
|
||||
file_table: Arc<SpinLock<FileTable>>,
|
||||
|
||||
umask: Arc<RwLock<FileCreationMask>>,
|
||||
resource_limits: ResourceLimits,
|
||||
@ -611,7 +611,7 @@ impl Process {
|
||||
|
||||
// ************** File system ****************
|
||||
|
||||
pub fn file_table(&self) -> &Arc<Mutex<FileTable>> {
|
||||
pub fn file_table(&self) -> &Arc<SpinLock<FileTable>> {
|
||||
&self.file_table
|
||||
}
|
||||
|
||||
@ -724,7 +724,7 @@ mod test {
|
||||
String::new(),
|
||||
ProcessVm::alloc(),
|
||||
Arc::new(RwMutex::new(FsResolver::new())),
|
||||
Arc::new(Mutex::new(FileTable::new())),
|
||||
Arc::new(SpinLock::new(FileTable::new())),
|
||||
Arc::new(RwLock::new(FileCreationMask::default())),
|
||||
ResourceLimits::default(),
|
||||
Nice::default(),
|
||||
|
Reference in New Issue
Block a user