Skip to content

Commit

Permalink
[Closes #106] Hold Arc<SpinLock<OpenedFileTable>> instead of just `…
Browse files Browse the repository at this point in the history
…SpinLock<>` (#157)

Co-authored-by: Seiya Nuta <nuta@seiya.me>
  • Loading branch information
michalfita and nuta authored Mar 25, 2022
1 parent c758075 commit a47e12e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
5 changes: 0 additions & 5 deletions kernel/fs/opened_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,6 @@ impl OpenedFileTable {
Ok(())
}

/// Clones the table.
pub fn fork(&self) -> OpenedFileTable {
self.clone()
}

/// Closes all opened files.
pub fn close_all(&mut self) {
self.files.clear();
Expand Down
12 changes: 6 additions & 6 deletions kernel/process/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ pub struct Process {
cmdline: AtomicRefCell<Cmdline>,
children: SpinLock<Vec<Arc<Process>>>,
vm: AtomicRefCell<Option<Arc<SpinLock<Vm>>>>,
opened_files: SpinLock<OpenedFileTable>,
opened_files: Arc<SpinLock<OpenedFileTable>>,
root_fs: Arc<SpinLock<RootFs>>,
signals: Arc<SpinLock<SignalDelivery>>,
signaled_frame: AtomicCell<Option<PtRegs>>,
Expand All @@ -140,7 +140,7 @@ impl Process {
vm: AtomicRefCell::new(None),
pid: PId::new(0),
root_fs: INITIAL_ROOT_FS.clone(),
opened_files: SpinLock::new(OpenedFileTable::new()),
opened_files: Arc::new(SpinLock::new(OpenedFileTable::new())),
signals: Arc::new(SpinLock::new(SignalDelivery::new())),
signaled_frame: AtomicCell::new(None),
sigset: SpinLock::new(SigSet::ZERO),
Expand Down Expand Up @@ -200,7 +200,7 @@ impl Process {
cmdline: AtomicRefCell::new(Cmdline::from_argv(argv)),
arch: arch::Process::new_user_thread(entry.ip, entry.user_sp),
vm: AtomicRefCell::new(Some(Arc::new(SpinLock::new(entry.vm)))),
opened_files: SpinLock::new(opened_files),
opened_files: Arc::new(SpinLock::new(opened_files)),
root_fs,
signals: Arc::new(SpinLock::new(SignalDelivery::new())),
signaled_frame: AtomicCell::new(None),
Expand Down Expand Up @@ -271,7 +271,7 @@ impl Process {
}

/// The ppened files table.
pub fn opened_files(&self) -> &SpinLock<OpenedFileTable> {
pub fn opened_files(&self) -> &Arc<SpinLock<OpenedFileTable>> {
&self.opened_files
}

Expand Down Expand Up @@ -499,7 +499,7 @@ impl Process {
let pid = alloc_pid(&mut process_table)?;
let arch = parent.arch.fork(parent_frame)?;
let vm = parent.vm().as_ref().unwrap().lock().fork()?;
let opened_files = parent.opened_files().lock().fork();
let opened_files = parent.opened_files().lock().clone(); // TODO: #88 has to address this
let process_group = parent.process_group();
let sig_set = parent.sigset.lock();

Expand All @@ -512,7 +512,7 @@ impl Process {
cmdline: AtomicRefCell::new(parent.cmdline().clone()),
children: SpinLock::new(Vec::new()),
vm: AtomicRefCell::new(Some(Arc::new(SpinLock::new(vm)))),
opened_files: SpinLock::new(opened_files),
opened_files: Arc::new(SpinLock::new(opened_files)),
root_fs: parent.root_fs().clone(),
arch,
signals: Arc::new(SpinLock::new(SignalDelivery::new())), // TODO: #88 has to address this
Expand Down

0 comments on commit a47e12e

Please sign in to comment.