fn try_recv(&self) -> Result<T, TryRecvError> {
        let backoff = Backoff::new();
        let mut head = self.head.load(Ordering::Relaxed);

        loop {
            // Deconstruct the head.
            let index = head & (self.mark_bit - 1);
            let lap = head & !(self.one_lap - 1);

            // Inspect the corresponding slot.
            let slot = unsafe { &*self.buffer.add(index) };
            let stamp = slot.stamp.load(Ordering::Acquire);

            // If the the stamp is ahead of the head by 1, we may attempt to pop.
            if head + 1 == stamp {
                let new = if index + 1 < self.cap {
                    // Same lap, incremented index.
                    // Set to `{ lap: lap, mark: 0, index: index + 1 }`.
                    head + 1
                } else {
                    // One lap forward, index wraps around to zero.
                    // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`.
                    lap.wrapping_add(self.one_lap)
                };

                // Try moving the head.
                match self.head.compare_exchange_weak(
                    head,
                    new,
                    Ordering::SeqCst,
                    Ordering::Relaxed,
                ) {
                    Ok(_) => {
                        // Read the message from the slot and update the stamp.
                        let msg = unsafe { slot.msg.get().read() };
                        let stamp = head.wrapping_add(self.one_lap);
                        slot.stamp.store(stamp, Ordering::Release);

                        // Wake a blocked send operation.
                        self.send_ops.notify_one();

                        // Wake all blocked sinks.
                        self.sink_ops.notify_all();

                        // Notify send operations waiting for handoff.
                        if let Some(h) = &self.handoff {
                            h.notify_all();
                        }

                        return Ok(msg);
                    }
                    Err(h) => {
                        head = h;
                        backoff.spin();
                    }
                }
            } else if stamp == head {
                atomic::fence(Ordering::SeqCst);
                let tail = self.tail.load(Ordering::Relaxed);

                // If the tail equals the head, that means the channel is empty.
                if (tail & !self.mark_bit) == head {
                    // If the channel is disconnected...
                    if tail & self.mark_bit != 0 {
                        return Err(TryRecvError::Disconnected);
                    } else {
                        // Otherwise, the receive operation is not ready.
                        return Err(TryRecvError::Empty);
                    }
                }

                backoff.spin();
                head = self.head.load(Ordering::Relaxed);
            } else {
                // Snooze because we need to wait for the stamp to get updated.
                backoff.snooze();
                head = self.head.load(Ordering::Relaxed);
            }
        }
    }
/// Attempts to receive a message.
Attempts to receive a message.
Attempts to receive a message .
fn try_recv(&self) -> Result<T, TryRecvError> {
        let backoff = Backoff::new();
        let mut head = self.head.load(Ordering::Relaxed);
        loop {
            // Deconstruct the head.
            let index = head & (self.mark_bit - 1);
            let lap = head & !(self.one_lap - 1);
            // Inspect the corresponding slot.
            let slot = unsafe { &*self.buffer.add(index) };
            let stamp = slot.stamp.load(Ordering::Acquire);
            // If the the stamp is ahead of the head by 1, we may attempt to pop.
            if head + 1 == stamp {
                let new = if index + 1 < self.cap {
                    // Same lap, incremented index.
                    // Set to `{ lap: lap, mark: 0, index: index + 1 }`.
                    head + 1
                } else {
                    // One lap forward, index wraps around to zero.
                    // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`.
                    lap.wrapping_add(self.one_lap)
                };
                // Try moving the head.
                match self.head.compare_exchange_weak(
                    head,
                    new,
                    Ordering::SeqCst,
                    Ordering::Relaxed,
                ) {
                    Ok(_) => {
                        // Read the message from the slot and update the stamp.
                        let msg = unsafe { slot.msg.get().read() };
                        let stamp = head.wrapping_add(self.one_lap);
                        slot.stamp.store(stamp, Ordering::Release);
                        // Wake a blocked send operation.
                        self.send_ops.notify_one();
                        // Wake all blocked sinks.
                        self.sink_ops.notify_all();
                        // Notify send operations waiting for handoff.
                        if let Some(h) = &self.handoff {
                            h.notify_all();
                        }
                        return Ok(msg);
                    }
                    Err(h) => {
                        head = h;
                        backoff.spin();
                    }
                }
            } else if stamp == head {
                atomic::fence(Ordering::SeqCst);
                let tail = self.tail.load(Ordering::Relaxed);
                // If the tail equals the head, that means the channel is empty.
                if (tail & !self.mark_bit) == head {
                    // If the channel is disconnected...
                    if tail & self.mark_bit != 0 {
                        return Err(TryRecvError::Disconnected);
                    } else {
                        // Otherwise, the receive operation is not ready.
                        return Err(TryRecvError::Empty);
                    }
                }
                backoff.spin();
                head = self.head.load(Ordering::Relaxed);
            } else {
                // Snooze because we need to wait for the stamp to get updated.
                backoff.snooze();
                head = self.head.load(Ordering::Relaxed);
            }
        }
    }
fn try_recv ( & self ) -> Result < T , TryRecvError > { let backoff = Backoff :: new ( ) ; let mut head = self . head . load ( Ordering :: Relaxed ) ; loop { // Deconstruct the head. let index = head & ( self . mark_bit - 1 ) ; let lap = head & ! ( self . one_lap - 1 ) ; // Inspect the corresponding slot. let slot = unsafe { & * self . buffer . add ( index ) } ; let stamp = slot . stamp . load ( Ordering :: Acquire ) ; // If the the stamp is ahead of the head by 1, we may attempt to pop. if head + 1 == stamp { let new = if index + 1 < self . cap { // Same lap, incremented index. // Set to `{ lap: lap, mark: 0, index: index + 1 }`. head + 1 } else { // One lap forward, index wraps around to zero. // Set to `{ lap: lap.wrapping_add(1), mark: 0, index: 0 }`. lap . wrapping_add ( self . one_lap ) } ; // Try moving the head. match self . head . compare_exchange_weak ( head , new , Ordering :: SeqCst , Ordering :: Relaxed , ) { Ok ( _ ) => { // Read the message from the slot and update the stamp. let msg = unsafe { slot . msg . get ( ) . read ( ) } ; let stamp = head . wrapping_add ( self . one_lap ) ; slot . stamp . store ( stamp , Ordering :: Release ) ; // Wake a blocked send operation. self . send_ops . notify_one ( ) ; // Wake all blocked sinks. self . sink_ops . notify_all ( ) ; // Notify send operations waiting for handoff. if let Some ( h ) = & self . handoff { h . notify_all ( ) ; } return Ok ( msg ) ; } Err ( h ) => { head = h ; backoff . spin ( ) ; } } } else if stamp == head { atomic :: fence ( Ordering :: SeqCst ) ; let tail = self . tail . load ( Ordering :: Relaxed ) ; // If the tail equals the head, that means the channel is empty. if ( tail & ! self . mark_bit ) == head { // If the channel is disconnected... if tail & self . mark_bit != 0 { return Err ( TryRecvError :: Disconnected ) ; } else { // Otherwise, the receive operation is not ready. return Err ( TryRecvError :: Empty ) ; } } backoff . spin ( ) ; head = self . head . load ( Ordering :: Relaxed ) ; } else { // Snooze because we need to wait for the stamp to get updated. backoff . snooze ( ) ; head = self . head . load ( Ordering :: Relaxed ) ; } } }
Attempts to receive a message.
Attempts to receive a message .
&self