@@ -134,6 +134,23 @@ macro_rules! impl_ {
134
134
self . _dequeue( head) // ▲
135
135
}
136
136
137
+ /// Returns the maximum number of elements the queue can hold
138
+ pub fn capacity( & self ) -> $uxx {
139
+ unsafe { self . rb. as_ref( ) . capacity( ) }
140
+ }
141
+
142
+ /// Returns the number of elements in the queue
143
+ ///
144
+ /// # Note
145
+ ///
146
+ /// This is a conservative estimate. Interrupt during this function
147
+ /// might cause that the `Consumer` actually has more than N items available.
148
+ pub fn len( & self ) -> $uxx {
149
+ let head = unsafe { self . rb. as_ref( ) . 0 . head. load_relaxed( ) } ;
150
+ let tail = unsafe { self . rb. as_ref( ) . 0 . tail. load_acquire( ) } ;
151
+ tail. wrapping_sub( head)
152
+ }
153
+
137
154
unsafe fn _peek( & self , head: $uxx) -> & T {
138
155
let rb = self . rb. as_ref( ) ;
139
156
@@ -197,6 +214,23 @@ macro_rules! impl_ {
197
214
}
198
215
}
199
216
217
+ /// Returns the maximum number of elements the queue can hold
218
+ pub fn capacity( & self ) -> $uxx {
219
+ unsafe { self . rb. as_ref( ) . capacity( ) }
220
+ }
221
+
222
+ /// Returns the number of elements in the queue
223
+ ///
224
+ /// # Note
225
+ ///
226
+ /// This is a conservative estimate. Interrupt during this function
227
+ /// might cause that the `Producer` actually has more than N items of available space.
228
+ pub fn len( & self ) -> $uxx {
229
+ let head = unsafe { self . rb. as_ref( ) . 0 . head. load_acquire( ) } ;
230
+ let tail = unsafe { self . rb. as_ref( ) . 0 . tail. load_relaxed( ) } ;
231
+ tail. wrapping_sub( head)
232
+ }
233
+
200
234
/// Adds an `item` to the end of the queue without checking if it's full
201
235
///
202
236
/// # Unsafety
0 commit comments