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.0"
version = "0.6.1"
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
10 changes: 10 additions & 0 deletions bbqueue/src/prod_cons/framed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ where
hdr: sz,
})
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
pub fn capacity(&self) -> usize {
self.bbq.capacity()
}
}

impl<Q, H> FramedProducer<Q, H>
Expand Down Expand Up @@ -222,6 +227,11 @@ where
hdr,
})
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
pub fn capacity(&self) -> usize {
self.bbq.capacity()
}
}

impl<Q, H> FramedConsumer<Q, H>
Expand Down
10 changes: 10 additions & 0 deletions bbqueue/src/prod_cons/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ where
to_commit: 0,
})
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
pub fn capacity(&self) -> usize {
self.bbq.capacity()
}
}

impl<Q> StreamProducer<Q>
Expand Down Expand Up @@ -174,6 +179,11 @@ where
to_release: 0,
})
}

/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
pub fn capacity(&self) -> usize {
self.bbq.capacity()
}
}

impl<Q> StreamConsumer<Q>
Expand Down
8 changes: 8 additions & 0 deletions bbqueue/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
pub const fn stream_consumer(&self) -> StreamConsumer<&'_ Self> {
StreamConsumer { bbq: self }
}

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

#[cfg(feature = "alloc")]
Expand Down