Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bbqueue/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bbqueue"
version = "0.6.1"
version = "0.6.2"
description = "A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers"
repository = "https://github.com/jamesmunns/bbqueue"
authors = ["James Munns <james@onevariable.com>"]
Expand Down
40 changes: 40 additions & 0 deletions bbqueue/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,28 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
#[inline(always)]
pub fn capacity(&self) -> usize {
// SAFETY: capacity never changes, therefore reading the len is safe
unsafe {
self.sto.ptr_len().1
}
}

/// Get access to the internal storage implementation details
///
/// NOTE: Although this method is safe, use of the `Storage` methods are not.
/// You should *never* attempt to access or modify the underlying data contained
/// in a storage implementation while the bbqueue is live. That will IMMEDIATELY
/// lead to undefined behavior.
///
/// As far as I am aware, the only reasonable use for this is for cases where you
/// have a custom `Storage` implementation that has unique teardown/drop in place
/// requirements. Treat any uses of this function with *extreme* caution!
#[inline(always)]
pub fn storage(&self) -> &S {
&self.sto
}
}

#[cfg(feature = "alloc")]
Expand Down Expand Up @@ -148,6 +164,30 @@ impl<S: Storage, C: Coord, N: Notifier> crate::queue::ArcBBQueue<S, C, N> {
bbq: self.0.bbq_ref(),
}
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
#[inline(always)]
pub fn capacity(&self) -> usize {
// SAFETY: capacity never changes, therefore reading the len is safe
unsafe {
self.0.sto.ptr_len().1
}
}

/// Get access to the internal storage implementation details
///
/// NOTE: Although this method is safe, use of the `Storage` methods are not.
/// You should *never* attempt to access or modify the underlying data contained
/// in a storage implementation while the bbqueue is live. That will IMMEDIATELY
/// lead to undefined behavior.
///
/// As far as I am aware, the only reasonable use for this is for cases where you
/// have a custom `Storage` implementation that has unique teardown/drop in place
/// requirements. Treat any uses of this function with *extreme* caution!
#[inline(always)]
pub fn storage(&self) -> &S {
&self.0.sto
}
}

#[cfg(test)]
Expand Down