pub fn alloc_write(&self, size: u64, max_size: u64) -> Option<u64> {

        // loop retries for compare-and-swap
        loop {

            let write_ptr = unsafe { &*self.write_ptr };

            let write_pos = write_ptr.load(atomic::Ordering::Relaxed);
            if write_pos > max_size {
                return None;
            }

            let old_write_pos = write_ptr.compare_and_swap
                (write_pos, write_pos + size, atomic::Ordering::Relaxed);

            // Only if we are overwriting the old value we are ok; otherwise retry
            if old_write_pos == write_pos {
                return Some(old_write_pos)
            }
        }

    }
/// Reserves `size` bytes for writing, updates the write_pos atomically
/// and returns the position at which the bytes can be written
///
/// If no more then max_size bytes are available, None is returned
Reserves `size` bytes for writing, updates the write_pos atomically
and returns the position at which the bytes can be written

If no more then max_size bytes are available, None is returned
Reserves ` size ` bytes for writing updates the write_pos atomically and returns the position at which the bytes can be written If no more then max_size bytes are available None is returned
pub fn alloc_write(&self, size: u64, max_size: u64) -> Option<u64> {
        // loop retries for compare-and-swap
        loop {
            let write_ptr = unsafe { &*self.write_ptr };
            let write_pos = write_ptr.load(atomic::Ordering::Relaxed);
            if write_pos > max_size {
                return None;
            }
            let old_write_pos = write_ptr.compare_and_swap
                (write_pos, write_pos + size, atomic::Ordering::Relaxed);
            // Only if we are overwriting the old value we are ok; otherwise retry
            if old_write_pos == write_pos {
                return Some(old_write_pos)
            }
        }
    }
pub fn alloc_write ( & self , size : u64 , max_size : u64 ) -> Option < u64 > { // loop retries for compare-and-swap loop { let write_ptr = unsafe { & * self . write_ptr } ; let write_pos = write_ptr . load ( atomic :: Ordering :: Relaxed ) ; if write_pos > max_size { return None ; } let old_write_pos = write_ptr . compare_and_swap ( write_pos , write_pos + size , atomic :: Ordering :: Relaxed ) ; // Only if we are overwriting the old value we are ok; otherwise retry if old_write_pos == write_pos { return Some ( old_write_pos ) } } }
Reserves `size` bytes for writing, updates the write_pos atomically
and returns the position at which the bytes can be written
Reserves ` size ` bytes for writing updates the write_pos atomically and returns the position at which the bytes can be written
&self
size
u64
max_size
u64
&self
size
u64
max_size
u64