/// Reserves enough capacity so that `reserve_cap` tasks can be pushed without growing the
/// buffer.
Reserves enough capacity so that `reserve_cap` tasks can be pushed without growing the
buffer.
Reserves enough capacity so that ` reserve_cap ` tasks can be pushed without growing the buffer .
fn reserve(&self, reserve_cap: usize) {
        if reserve_cap > 0 {
            // Compute the current length.
            let b = self.inner.back.load(Ordering::Relaxed);
            let f = self.inner.front.load(Ordering::SeqCst);
            let len = b.wrapping_sub(f) as usize;
            // The current capacity.
            let cap = self.buffer.get().cap;
            // Is there enough capacity to push `reserve_cap` tasks?
            if cap.saturating_sub(len) < reserve_cap {
                // Keep doubling the capacity as much as is needed.
                let mut new_cap = cap * 2;
                while new_cap.saturating_sub(len) < reserve_cap {
                    new_cap = new_cap.wrapping_mul(2);
                }
                // Resize the buffer.
                unsafe {
                    self.resize(new_cap);
                }
            }
        }
    }
fn reserve ( & self , reserve_cap : usize ) { if reserve_cap > 0 { // Compute the current length. let b = self . inner . back . load ( Ordering :: Relaxed ) ; let f = self . inner . front . load ( Ordering :: SeqCst ) ; let len = b . wrapping_sub ( f ) as usize ; // The current capacity. let cap = self . buffer . get ( ) . cap ; // Is there enough capacity to push `reserve_cap` tasks? if cap . saturating_sub ( len ) < reserve_cap { // Keep doubling the capacity as much as is needed. let mut new_cap = cap * 2 ; while new_cap . saturating_sub ( len ) < reserve_cap { new_cap = new_cap . wrapping_mul ( 2 ) ; } // Resize the buffer. unsafe { self . resize ( new_cap ) ; } } } }
Reserves enough capacity so that `reserve_cap` tasks can be pushed without growing the
buffer.
Reserves enough capacity so that ` reserve_cap ` tasks can be pushed without growing the buffer .
&self
reserve_cap
usize