Skip to content

Commit

Permalink
WeakDmaFile was accidentally missing from exports
Browse files Browse the repository at this point in the history
Also missing were default and new constructor methods.
  • Loading branch information
vlovich committed May 1, 2024
1 parent 3d7f7f9 commit eba5990
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
24 changes: 24 additions & 0 deletions glommio/src/io/dma_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,31 @@ pub struct WeakDmaFile {
pollable: PollableStatus,
}

impl Default for WeakDmaFile {
fn default() -> Self {
Self::new()
}
}

impl WeakDmaFile {
/// Creates an empty reference that will never upgrade.
pub fn new() -> WeakDmaFile {
Self {
file: WeakGlommioFile::new(),
o_direct_alignment: 0,
max_sectors_size: 0,
max_segment_size: 0,
pollable: PollableStatus::Pollable,
}
}

/// The number of strong references that still remain on the file.
/// If created via [Self::new], this will return 0.
pub fn strong_count(&self) -> usize {
self.file.strong_count()
}

/// Returns an `Option` containing ownership over the file if the file hasn't been closed yet, otherwise None.
pub fn upgrade(&self) -> Option<OwnedDmaFile> {
self.file.upgrade().map(|file| OwnedDmaFile {
file,
Expand Down
10 changes: 9 additions & 1 deletion glommio/src/io/glommio_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ impl From<GlommioFile> for OwnedGlommioFile {
}
}

#[derive(Debug, Clone)]
#[derive(Default, Debug, Clone)]
pub(crate) struct WeakGlommioFile {
pub(crate) fd: AWeak<RawFd>,
pub(crate) path: Option<PathBuf>,
Expand All @@ -447,6 +447,14 @@ pub(crate) struct WeakGlommioFile {
}

impl WeakGlommioFile {
pub(crate) fn new() -> Self {
Self::default()
}

pub(crate) fn strong_count(&self) -> usize {
self.fd.strong_count()
}

pub(crate) fn upgrade(&self) -> Option<OwnedGlommioFile> {
self.fd.upgrade().map(|fd| OwnedGlommioFile {
fd: Some(fd),
Expand Down
2 changes: 1 addition & 1 deletion glommio/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub use self::{
},
bulk_io::{IoVec, MergedBufferLimit, ReadAmplificationLimit, ReadManyResult},
directory::Directory,
dma_file::{CloseResult, DmaFile, OwnedDmaFile},
dma_file::{CloseResult, DmaFile, OwnedDmaFile, WeakDmaFile},
dma_file_stream::{
DmaStreamReader, DmaStreamReaderBuilder, DmaStreamWriter, DmaStreamWriterBuilder,
},
Expand Down

0 comments on commit eba5990

Please sign in to comment.