Skip to content

Commit 979abde

Browse files
authored
Add "capacity" accessor (#125)
1 parent 4c13fee commit 979abde

4 files changed

Lines changed: 29 additions & 1 deletion

File tree

bbqueue/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bbqueue"
3-
version = "0.6.0"
3+
version = "0.6.1"
44
description = "A SPSC, lockless, no_std, thread safe, queue, based on BipBuffers"
55
repository = "https://github.com/jamesmunns/bbqueue"
66
authors = ["James Munns <james@onevariable.com>"]

bbqueue/src/prod_cons/framed.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ where
147147
hdr: sz,
148148
})
149149
}
150+
151+
/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
152+
pub fn capacity(&self) -> usize {
153+
self.bbq.capacity()
154+
}
150155
}
151156

152157
impl<Q, H> FramedProducer<Q, H>
@@ -222,6 +227,11 @@ where
222227
hdr,
223228
})
224229
}
230+
231+
/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
232+
pub fn capacity(&self) -> usize {
233+
self.bbq.capacity()
234+
}
225235
}
226236

227237
impl<Q, H> FramedConsumer<Q, H>

bbqueue/src/prod_cons/stream.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ where
120120
to_commit: 0,
121121
})
122122
}
123+
124+
/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
125+
pub fn capacity(&self) -> usize {
126+
self.bbq.capacity()
127+
}
123128
}
124129

125130
impl<Q> StreamProducer<Q>
@@ -174,6 +179,11 @@ where
174179
to_release: 0,
175180
})
176181
}
182+
183+
/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
184+
pub fn capacity(&self) -> usize {
185+
self.bbq.capacity()
186+
}
177187
}
178188

179189
impl<Q> StreamConsumer<Q>

bbqueue/src/queue.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ impl<S: Storage, C: Coord, N: Notifier> BBQueue<S, C, N> {
9595
pub const fn stream_consumer(&self) -> StreamConsumer<&'_ Self> {
9696
StreamConsumer { bbq: self }
9797
}
98+
99+
/// Get the total capacity of the buffer, e.g. how much space is present in [`Storage`]
100+
pub fn capacity(&self) -> usize {
101+
// SAFETY: capacity never changes, therefore reading the len is safe
102+
unsafe {
103+
self.sto.ptr_len().1
104+
}
105+
}
98106
}
99107

100108
#[cfg(feature = "alloc")]

0 commit comments

Comments
 (0)