fn start_recv(&self, token: &mut Token, backoff: &mut Backoff) -> bool {
        let guard = epoch::pin();

        loop {
            // Loading the head block doesn't have to be a `SeqCst` operation. If we get a stale
            // value, the following CAS will fail or not even be attempted. Loading the head index
            // must be `SeqCst` because we need the up-to-date value when checking whether the
            // channel is empty.
            let head_ptr = self.head.block.load(Ordering::Acquire, &guard);
            let head = unsafe { head_ptr.deref() };
            let head_index = self.head.index.load(Ordering::SeqCst);

            // Calculate the index of the corresponding slot in the block.
            let offset = head_index.wrapping_sub(head.start_index);

            // Advance the current index one slot forward.
            let new_index = head_index.wrapping_add(1);

            // If `head_index` is pointing into `head`...
            if offset < BLOCK_CAP {
                let slot = unsafe { &*head.slots.get_unchecked(offset).get() };

                // If this slot does not contain a message...
                if !slot.ready.load(Ordering::Relaxed) {
                    let tail_index = self.tail.index.load(Ordering::SeqCst);

                    // If the tail equals the head, that means the channel is empty.
                    if tail_index == head_index {
                        // If the channel is closed...
                        if self.is_closed() {
                            // ...and still empty...
                            if self.tail.index.load(Ordering::SeqCst) == tail_index {
                                // ...then receive `None`.
                                token.list.slot = ptr::null();
                                return true;
                            }
                        } else {
                            // Otherwise, the receive operation is not ready.
                            return false;
                        }
                    }
                }

                // Try moving the head index forward.
                if self
                    .head
                    .index
                    .compare_exchange_weak(
                        head_index,
                        new_index,
                        Ordering::SeqCst,
                        Ordering::Relaxed,
                    )
                    .is_ok()
                {
                    // If this was the last slot in the block, schedule its destruction.
                    if offset + 1 == BLOCK_CAP {
                        // Wait until the next pointer becomes non-null.
                        loop {
                            let next_ptr = head.next.load(Ordering::Acquire, &guard);
                            if !next_ptr.is_null() {
                                self.head.block.store(next_ptr, Ordering::Release);
                                break;
                            }
                            backoff.step();
                        }

                        unsafe {
                            guard.defer_destroy(head_ptr);
                        }
                    }

                    token.list.slot = slot as *const Slot<T> as *const u8;
                    break;
                }
            }

            backoff.step();
        }

        token.list.guard = Some(guard);
        true
    }
/// Attempts to reserve a slot for receiving a message.
Attempts to reserve a slot for receiving a message.
Attempts to reserve a slot for receiving a message .
fn start_recv(&self, token: &mut Token, backoff: &mut Backoff) -> bool {
        let guard = epoch::pin();
        loop {
            // Loading the head block doesn't have to be a `SeqCst` operation. If we get a stale
            // value, the following CAS will fail or not even be attempted. Loading the head index
            // must be `SeqCst` because we need the up-to-date value when checking whether the
            // channel is empty.
            let head_ptr = self.head.block.load(Ordering::Acquire, &guard);
            let head = unsafe { head_ptr.deref() };
            let head_index = self.head.index.load(Ordering::SeqCst);
            // Calculate the index of the corresponding slot in the block.
            let offset = head_index.wrapping_sub(head.start_index);
            // Advance the current index one slot forward.
            let new_index = head_index.wrapping_add(1);
            // If `head_index` is pointing into `head`...
            if offset < BLOCK_CAP {
                let slot = unsafe { &*head.slots.get_unchecked(offset).get() };
                // If this slot does not contain a message...
                if !slot.ready.load(Ordering::Relaxed) {
                    let tail_index = self.tail.index.load(Ordering::SeqCst);
                    // If the tail equals the head, that means the channel is empty.
                    if tail_index == head_index {
                        // If the channel is closed...
                        if self.is_closed() {
                            // ...and still empty...
                            if self.tail.index.load(Ordering::SeqCst) == tail_index {
                                // ...then receive `None`.
                                token.list.slot = ptr::null();
                                return true;
                            }
                        } else {
                            // Otherwise, the receive operation is not ready.
                            return false;
                        }
                    }
                }
                // Try moving the head index forward.
                if self
                    .head
                    .index
                    .compare_exchange_weak(
                        head_index,
                        new_index,
                        Ordering::SeqCst,
                        Ordering::Relaxed,
                    )
                    .is_ok()
                {
                    // If this was the last slot in the block, schedule its destruction.
                    if offset + 1 == BLOCK_CAP {
                        // Wait until the next pointer becomes non-null.
                        loop {
                            let next_ptr = head.next.load(Ordering::Acquire, &guard);
                            if !next_ptr.is_null() {
                                self.head.block.store(next_ptr, Ordering::Release);
                                break;
                            }
                            backoff.step();
                        }
                        unsafe {
                            guard.defer_destroy(head_ptr);
                        }
                    }
                    token.list.slot = slot as *const Slot<T> as *const u8;
                    break;
                }
            }
            backoff.step();
        }
        token.list.guard = Some(guard);
        true
    }
fn start_recv ( & self , token : & mut Token , backoff : & mut Backoff ) -> bool { let guard = epoch :: pin ( ) ; loop { // Loading the head block doesn't have to be a `SeqCst` operation. If we get a stale // value, the following CAS will fail or not even be attempted. Loading the head index // must be `SeqCst` because we need the up-to-date value when checking whether the // channel is empty. let head_ptr = self . head . block . load ( Ordering :: Acquire , & guard ) ; let head = unsafe { head_ptr . deref ( ) } ; let head_index = self . head . index . load ( Ordering :: SeqCst ) ; // Calculate the index of the corresponding slot in the block. let offset = head_index . wrapping_sub ( head . start_index ) ; // Advance the current index one slot forward. let new_index = head_index . wrapping_add ( 1 ) ; // If `head_index` is pointing into `head`... if offset < BLOCK_CAP { let slot = unsafe { & * head . slots . get_unchecked ( offset ) . get ( ) } ; // If this slot does not contain a message... if ! slot . ready . load ( Ordering :: Relaxed ) { let tail_index = self . tail . index . load ( Ordering :: SeqCst ) ; // If the tail equals the head, that means the channel is empty. if tail_index == head_index { // If the channel is closed... if self . is_closed ( ) { // ...and still empty... if self . tail . index . load ( Ordering :: SeqCst ) == tail_index { // ...then receive `None`. token . list . slot = ptr :: null ( ) ; return true ; } } else { // Otherwise, the receive operation is not ready. return false ; } } } // Try moving the head index forward. if self . head . index . compare_exchange_weak ( head_index , new_index , Ordering :: SeqCst , Ordering :: Relaxed , ) . is_ok ( ) { // If this was the last slot in the block, schedule its destruction. if offset + 1 == BLOCK_CAP { // Wait until the next pointer becomes non-null. loop { let next_ptr = head . next . load ( Ordering :: Acquire , & guard ) ; if ! next_ptr . is_null ( ) { self . head . block . store ( next_ptr , Ordering :: Release ) ; break ; } backoff . step ( ) ; } unsafe { guard . defer_destroy ( head_ptr ) ; } } token . list . slot = slot as * const Slot < T > as * const u8 ; break ; } } backoff . step ( ) ; } token . list . guard = Some ( guard ) ; true }
Attempts to reserve a slot for receiving a message.
Attempts to reserve a slot for receiving a message .
&self
token
&mut Token
backoff
&mut Backoff