Skip to content

Commit

Permalink
Add Buf::create_unlocked.
Browse files Browse the repository at this point in the history
  • Loading branch information
travis1829 committed Mar 11, 2022
1 parent 79ba9a7 commit 10c06ca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 7 additions & 0 deletions kernel-rs/src/bio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ impl Buf {
unsafe { &mut *entry.inner.get_mut_raw() }
}

/// Returns a `BufUnlocked` without releasing the lock or consuming `self`.
pub fn create_unlocked(&self) -> BufUnlocked {
unsafe { ManuallyDrop::take(&mut self.inner.clone()) }
}

/// Returns a `BufUnlocked` after releasing the lock and consuming `self`.
pub fn unlock(mut self, ctx: &KernelCtx<'_, '_>) -> BufUnlocked {
// SAFETY: this method consumes self and self.inner will not be used again.
let inner = unsafe { ManuallyDrop::take(&mut self.inner) };
Expand All @@ -169,6 +175,7 @@ impl Buf {
inner
}

/// Releases the lock and consumes `self`.
pub fn free(self, ctx: &KernelCtx<'_, '_>) {
let _ = self.unlock(ctx);
}
Expand Down
5 changes: 2 additions & 3 deletions kernel-rs/src/fs/lfs/segment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,9 @@ impl Segment {
let mut buf = self.read_segment_block(self.offset + 1, ctx);
buf.deref_inner_mut().data.fill(0);
buf.deref_inner_mut().valid = true;
let buf = buf.unlock(ctx);
self.segment_summary[self.offset] = f(buf.clone());
self.segment_summary[self.offset] = f(buf.create_unlocked());
self.offset += 1;
Some((buf.lock(ctx), self.get_disk_block_no(self.offset, ctx)))
Some((buf, self.get_disk_block_no(self.offset, ctx)))
}
}

Expand Down

0 comments on commit 10c06ca

Please sign in to comment.