pub fn pop(&self) -> Option<T> {
        // Load the back and front index.
        let b = self.inner.back.load(Ordering::Relaxed);
        let f = self.inner.front.load(Ordering::Relaxed);

        // Calculate the length of the queue.
        let len = b.wrapping_sub(f);

        // Is the queue empty?
        if len <= 0 {
            return None;
        }

        match self.flavor {
            // Pop from the front of the queue.
            Flavor::Fifo => {
                // Try incrementing the front index to pop the task.
                let f = self.inner.front.fetch_add(1, Ordering::SeqCst);
                let new_f = f.wrapping_add(1);

                if b.wrapping_sub(new_f) < 0 {
                    self.inner.front.store(f, Ordering::Relaxed);
                    return None;
                }

                unsafe {
                    // Read the popped task.
                    let buffer = self.buffer.get();
                    let task = buffer.read(f);

                    // Shrink the buffer if `len - 1` is less than one fourth of the capacity.
                    if buffer.cap > MIN_CAP && len <= buffer.cap as isize / 4 {
                        self.resize(buffer.cap / 2);
                    }

                    Some(task)
                }
            }

            // Pop from the back of the queue.
            Flavor::Lifo => {
                // Decrement the back index.
                let b = b.wrapping_sub(1);
                self.inner.back.store(b, Ordering::Relaxed);

                atomic::fence(Ordering::SeqCst);

                // Load the front index.
                let f = self.inner.front.load(Ordering::Relaxed);

                // Compute the length after the back index was decremented.
                let len = b.wrapping_sub(f);

                if len < 0 {
                    // The queue is empty. Restore the back index to the original task.
                    self.inner.back.store(b.wrapping_add(1), Ordering::Relaxed);
                    None
                } else {
                    // Read the task to be popped.
                    let buffer = self.buffer.get();
                    let mut task = unsafe { Some(buffer.read(b)) };

                    // Are we popping the last task from the queue?
                    if len == 0 {
                        // Try incrementing the front index.
                        if self
                            .inner
                            .front
                            .compare_exchange(
                                f,
                                f.wrapping_add(1),
                                Ordering::SeqCst,
                                Ordering::Relaxed,
                            )
                            .is_err()
                        {
                            // Failed. We didn't pop anything.
                            mem::forget(task.take());
                        }

                        // Restore the back index to the original task.
                        self.inner.back.store(b.wrapping_add(1), Ordering::Relaxed);
                    } else {
                        // Shrink the buffer if `len` is less than one fourth of the capacity.
                        if buffer.cap > MIN_CAP && len < buffer.cap as isize / 4 {
                            unsafe {
                                self.resize(buffer.cap / 2);
                            }
                        }
                    }

                    task
                }
            }
        }
    }
/// Pops a task from the queue.
Pops a task from the queue.
Pops a task from the queue .
pub fn pop(&self) -> Option<T> {
        // Load the back and front index.
        let b = self.inner.back.load(Ordering::Relaxed);
        let f = self.inner.front.load(Ordering::Relaxed);
        // Calculate the length of the queue.
        let len = b.wrapping_sub(f);
        // Is the queue empty?
        if len <= 0 {
            return None;
        }
        match self.flavor {
            // Pop from the front of the queue.
            Flavor::Fifo => {
                // Try incrementing the front index to pop the task.
                let f = self.inner.front.fetch_add(1, Ordering::SeqCst);
                let new_f = f.wrapping_add(1);
                if b.wrapping_sub(new_f) < 0 {
                    self.inner.front.store(f, Ordering::Relaxed);
                    return None;
                }
                unsafe {
                    // Read the popped task.
                    let buffer = self.buffer.get();
                    let task = buffer.read(f);
                    // Shrink the buffer if `len - 1` is less than one fourth of the capacity.
                    if buffer.cap > MIN_CAP && len <= buffer.cap as isize / 4 {
                        self.resize(buffer.cap / 2);
                    }
                    Some(task)
                }
            }
            // Pop from the back of the queue.
            Flavor::Lifo => {
                // Decrement the back index.
                let b = b.wrapping_sub(1);
                self.inner.back.store(b, Ordering::Relaxed);
                atomic::fence(Ordering::SeqCst);
                // Load the front index.
                let f = self.inner.front.load(Ordering::Relaxed);
                // Compute the length after the back index was decremented.
                let len = b.wrapping_sub(f);
                if len < 0 {
                    // The queue is empty. Restore the back index to the original task.
                    self.inner.back.store(b.wrapping_add(1), Ordering::Relaxed);
                    None
                } else {
                    // Read the task to be popped.
                    let buffer = self.buffer.get();
                    let mut task = unsafe { Some(buffer.read(b)) };
                    // Are we popping the last task from the queue?
                    if len == 0 {
                        // Try incrementing the front index.
                        if self
                            .inner
                            .front
                            .compare_exchange(
                                f,
                                f.wrapping_add(1),
                                Ordering::SeqCst,
                                Ordering::Relaxed,
                            )
                            .is_err()
                        {
                            // Failed. We didn't pop anything.
                            mem::forget(task.take());
                        }
                        // Restore the back index to the original task.
                        self.inner.back.store(b.wrapping_add(1), Ordering::Relaxed);
                    } else {
                        // Shrink the buffer if `len` is less than one fourth of the capacity.
                        if buffer.cap > MIN_CAP && len < buffer.cap as isize / 4 {
                            unsafe {
                                self.resize(buffer.cap / 2);
                            }
                        }
                    }
                    task
                }
            }
        }
    }
pub fn pop ( & self ) -> Option < T > { // Load the back and front index. let b = self . inner . back . load ( Ordering :: Relaxed ) ; let f = self . inner . front . load ( Ordering :: Relaxed ) ; // Calculate the length of the queue. let len = b . wrapping_sub ( f ) ; // Is the queue empty? if len <= 0 { return None ; } match self . flavor { // Pop from the front of the queue. Flavor :: Fifo => { // Try incrementing the front index to pop the task. let f = self . inner . front . fetch_add ( 1 , Ordering :: SeqCst ) ; let new_f = f . wrapping_add ( 1 ) ; if b . wrapping_sub ( new_f ) < 0 { self . inner . front . store ( f , Ordering :: Relaxed ) ; return None ; } unsafe { // Read the popped task. let buffer = self . buffer . get ( ) ; let task = buffer . read ( f ) ; // Shrink the buffer if `len - 1` is less than one fourth of the capacity. if buffer . cap > MIN_CAP && len <= buffer . cap as isize / 4 { self . resize ( buffer . cap / 2 ) ; } Some ( task ) } } // Pop from the back of the queue. Flavor :: Lifo => { // Decrement the back index. let b = b . wrapping_sub ( 1 ) ; self . inner . back . store ( b , Ordering :: Relaxed ) ; atomic :: fence ( Ordering :: SeqCst ) ; // Load the front index. let f = self . inner . front . load ( Ordering :: Relaxed ) ; // Compute the length after the back index was decremented. let len = b . wrapping_sub ( f ) ; if len < 0 { // The queue is empty. Restore the back index to the original task. self . inner . back . store ( b . wrapping_add ( 1 ) , Ordering :: Relaxed ) ; None } else { // Read the task to be popped. let buffer = self . buffer . get ( ) ; let mut task = unsafe { Some ( buffer . read ( b ) ) } ; // Are we popping the last task from the queue? if len == 0 { // Try incrementing the front index. if self . inner . front . compare_exchange ( f , f . wrapping_add ( 1 ) , Ordering :: SeqCst , Ordering :: Relaxed , ) . is_err ( ) { // Failed. We didn't pop anything. mem :: forget ( task . take ( ) ) ; } // Restore the back index to the original task. self . inner . back . store ( b . wrapping_add ( 1 ) , Ordering :: Relaxed ) ; } else { // Shrink the buffer if `len` is less than one fourth of the capacity. if buffer . cap > MIN_CAP && len < buffer . cap as isize / 4 { unsafe { self . resize ( buffer . cap / 2 ) ; } } } task } } } }
Pops a task from the queue.
Pops a task from the queue .
&self
&self