/// Commits all changes, switches sides and then updates the now unactive
/// side
Commits all changes, switches sides and then updates the now unactive
side
Commits all changes switches sides and then updates the now unactive side
pub fn commit(&self) {
        // Make sure that we are the only ones that manipulate the structure
        while self
                .exclusive_write
                .compare_exchange_weak(
                    true, false,
                    Ordering::SeqCst, Ordering::SeqCst
                )
                .is_err() {}
        let active_side = self.active_side.get();
        // switch the reader from left to right or from right to left
        self.active_side.swap(active_side);
        // Wait until all readers switched to the new side
        if active_side == ActiveSide::Left {
            while self.readers_left.load(Ordering::SeqCst) > 0 {  }
        } else {
            while self.readers_right.load(Ordering::SeqCst) > 0 {  }
        }
        // Finally copy the new data over to the other side
        if active_side == ActiveSide::Left {
            unsafe { *(self.left.get() as *mut _) = &mut *self.right.get() };
        } else {
            unsafe { *(self.right.get() as *mut _) = &mut *self.left.get() };
        }
        // Unlock datastructure
        self.exclusive_write.store(true, Ordering::SeqCst);
    }
pub fn commit ( & self ) { // Make sure that we are the only ones that manipulate the structure while self . exclusive_write . compare_exchange_weak ( true , false , Ordering :: SeqCst , Ordering :: SeqCst ) . is_err ( ) { } let active_side = self . active_side . get ( ) ; // switch the reader from left to right or from right to left self . active_side . swap ( active_side ) ; // Wait until all readers switched to the new side if active_side == ActiveSide :: Left { while self . readers_left . load ( Ordering :: SeqCst ) > 0 { } } else { while self . readers_right . load ( Ordering :: SeqCst ) > 0 { } } // Finally copy the new data over to the other side if active_side == ActiveSide :: Left { unsafe { * ( self . left . get ( ) as * mut _ ) = & mut * self . right . get ( ) } ; } else { unsafe { * ( self . right . get ( ) as * mut _ ) = & mut * self . left . get ( ) } ; } // Unlock datastructure self . exclusive_write . store ( true , Ordering :: SeqCst ) ; }
Commits all changes, switches sides and then updates the now unactive
side
Commits all changes switches sides and then updates the now unactive side
&self