pub fn update_with(&self, mut f: impl FnMut(Option<&mut T>)) -> RcuSyncHandle<T> 
        where T: Clone
    {
        let mut current = self.read();
        let mut new = current.clone().map(|x| Box::new(x.cloned()));
        loop {
            f(new.as_mut().map(|x| x.as_mut()));
            let current_ptr = current.map_or(ptr::null(), RcuReference::into_inner) as *mut T;
            let new_ptr = option_box_to_ptr(new);
            match self.data.compare_exchange_weak(current_ptr, new_ptr, Ordering::AcqRel, Ordering::Acquire) {
                Ok(old) => {
                    return RcuSyncHandle { data: old };
                },
                Err(old) => {
                    // SAFETY: this is read from current ptr.
                    current = unsafe { RcuReference::new(old) };
                    // SAFETY: this is the original value.
                    new = unsafe { ptr_to_option_box(new_ptr) };
                    if old.is_null() {
                        new = None;
                    } else {
                        // SAFETY: old is read from current RCU.
                        let cloned_old = unsafe { (*old).clone() };
                        if let Some(x) = new.as_mut() {
                            *x.as_mut() = cloned_old;
                        } else {
                            new = Some(Box::new(cloned_old));
                        }
                    }
                }
            }
        }
    }
/// Fetches the old value, applies a function to it, and returns the old value as `RcuSyncHandle`. 
Fetches the old value, applies a function to it, and returns the old value as `RcuSyncHandle`.
Fetches the old value applies a function to it and returns the old value as ` RcuSyncHandle ` .
pub fn update_with(&self, mut f: impl FnMut(Option<&mut T>)) -> RcuSyncHandle<T> 
        where T: Clone
    {
        let mut current = self.read();
        let mut new = current.clone().map(|x| Box::new(x.cloned()));
        loop {
            f(new.as_mut().map(|x| x.as_mut()));
            let current_ptr = current.map_or(ptr::null(), RcuReference::into_inner) as *mut T;
            let new_ptr = option_box_to_ptr(new);
            match self.data.compare_exchange_weak(current_ptr, new_ptr, Ordering::AcqRel, Ordering::Acquire) {
                Ok(old) => {
                    return RcuSyncHandle { data: old };
                },
                Err(old) => {
                    // SAFETY: this is read from current ptr.
                    current = unsafe { RcuReference::new(old) };
                    // SAFETY: this is the original value.
                    new = unsafe { ptr_to_option_box(new_ptr) };
                    if old.is_null() {
                        new = None;
                    } else {
                        // SAFETY: old is read from current RCU.
                        let cloned_old = unsafe { (*old).clone() };
                        if let Some(x) = new.as_mut() {
                            *x.as_mut() = cloned_old;
                        } else {
                            new = Some(Box::new(cloned_old));
                        }
                    }
                }
            }
        }
    }
pub fn update_with ( & self , mut f : impl FnMut ( Option < & mut T > ) ) -> RcuSyncHandle < T > where T : Clone { let mut current = self . read ( ) ; let mut new = current . clone ( ) . map ( | x | Box :: new ( x . cloned ( ) ) ) ; loop { f ( new . as_mut ( ) . map ( | x | x . as_mut ( ) ) ) ; let current_ptr = current . map_or ( ptr :: null ( ) , RcuReference :: into_inner ) as * mut T ; let new_ptr = option_box_to_ptr ( new ) ; match self . data . compare_exchange_weak ( current_ptr , new_ptr , Ordering :: AcqRel , Ordering :: Acquire ) { Ok ( old ) => { return RcuSyncHandle { data : old } ; } , Err ( old ) => { // SAFETY: this is read from current ptr. current = unsafe { RcuReference :: new ( old ) } ; // SAFETY: this is the original value. new = unsafe { ptr_to_option_box ( new_ptr ) } ; if old . is_null ( ) { new = None ; } else { // SAFETY: old is read from current RCU. let cloned_old = unsafe { ( * old ) . clone ( ) } ; if let Some ( x ) = new . as_mut ( ) { * x . as_mut ( ) = cloned_old ; } else { new = Some ( Box :: new ( cloned_old ) ) ; } } } } } }
Fetches the old value, applies a function to it, and returns the old value as `RcuSyncHandle`.
Fetches the old value applies a function to it and returns the old value as ` RcuSyncHandle ` .
&self
f
impl FnMut(Option<&mut T>)
&self
f
impl FnMut(Option<&mut T>)