pub fn call_once<'a, F>(&'a self, builder: F) -> &'a T
    where
        F: FnOnce() -> T,
    {
        let mut status = self.state.load(Ordering::SeqCst);

        if status == INCOMPLETE {
            status = self
                .state
                .compare_and_swap(INCOMPLETE, RUNNING, Ordering::SeqCst);
            if status == INCOMPLETE {
                // We init
                // We use a guard (Finish) to catch panics caused by builder
                let mut finish = Finish {
                    state: &self.state,
                    panicked: true,
                };
                unsafe { *self.data.get() = Some(builder()) };
                finish.panicked = false;

                status = COMPLETE;
                self.state.store(status, Ordering::SeqCst);

                // This next line is strictly an optimization
                return self.force_get();
            }
        }

        loop {
            match status {
                INCOMPLETE => unreachable!(),
                RUNNING => {
                    // We spin
                    cpu_relax();
                    status = self.state.load(Ordering::SeqCst)
                }
                PANICKED => panic!("Once has panicked"),
                COMPLETE => return self.force_get(),
                _ => unsafe { unreachable() },
            }
        }
    }
/// Performs an initialization routine once and only once. The given closure
/// will be executed if this is the first time `call_once` has been called,
/// and otherwise the routine will *not* be invoked.
///
/// This method will block the calling thread if another initialization
/// routine is currently running.
///
/// When this function returns, it is guaranteed that some initialization
/// has run and completed (it may not be the closure specified). The
/// returned pointer will point to the result from the closure that was
/// run.
Performs an initialization routine once and only once. The given closure
will be executed if this is the first time `call_once` has been called,
and otherwise the routine will *not* be invoked.

This method will block the calling thread if another initialization
routine is currently running.

When this function returns, it is guaranteed that some initialization
has run and completed (it may not be the closure specified). The
returned pointer will point to the result from the closure that was
run.
Performs an initialization routine once and only once . The given closure will be executed if this is the first time ` call_once ` has been called and otherwise the routine will * not * be invoked . This method will block the calling thread if another initialization routine is currently running . When this function returns it is guaranteed that some initialization has run and completed ( it may not be the closure specified ) . The returned pointer will point to the result from the closure that was run .
pub fn call_once<'a, F>(&'a self, builder: F) -> &'a T
    where
        F: FnOnce() -> T,
    {
        let mut status = self.state.load(Ordering::SeqCst);
        if status == INCOMPLETE {
            status = self
                .state
                .compare_and_swap(INCOMPLETE, RUNNING, Ordering::SeqCst);
            if status == INCOMPLETE {
                // We init
                // We use a guard (Finish) to catch panics caused by builder
                let mut finish = Finish {
                    state: &self.state,
                    panicked: true,
                };
                unsafe { *self.data.get() = Some(builder()) };
                finish.panicked = false;
                status = COMPLETE;
                self.state.store(status, Ordering::SeqCst);
                // This next line is strictly an optimization
                return self.force_get();
            }
        }
        loop {
            match status {
                INCOMPLETE => unreachable!(),
                RUNNING => {
                    // We spin
                    cpu_relax();
                    status = self.state.load(Ordering::SeqCst)
                }
                PANICKED => panic!("Once has panicked"),
                COMPLETE => return self.force_get(),
                _ => unsafe { unreachable() },
            }
        }
    }
pub fn call_once < ' a , F > ( & ' a self , builder : F ) -> & ' a T where F : FnOnce ( ) -> T , { let mut status = self . state . load ( Ordering :: SeqCst ) ; if status == INCOMPLETE { status = self . state . compare_and_swap ( INCOMPLETE , RUNNING , Ordering :: SeqCst ) ; if status == INCOMPLETE { // We init // We use a guard (Finish) to catch panics caused by builder let mut finish = Finish { state : & self . state , panicked : true , } ; unsafe { * self . data . get ( ) = Some ( builder ( ) ) } ; finish . panicked = false ; status = COMPLETE ; self . state . store ( status , Ordering :: SeqCst ) ; // This next line is strictly an optimization return self . force_get ( ) ; } } loop { match status { INCOMPLETE => unreachable ! ( ) , RUNNING => { // We spin cpu_relax ( ) ; status = self . state . load ( Ordering :: SeqCst ) } PANICKED => panic ! ( " " ) , COMPLETE => return self . force_get ( ) , _ => unsafe { unreachable ( ) } , } } }
Performs an initialization routine once and only once.
Performs an initialization routine once and only once .
&'a self
builder
F
&'a self
builder
F