pub fn send(self, t: T) {
        // The send method is iterative. At each iteration, the `EMPTY` flag is
        // checked. If set, the presence of a value is signaled immediately and
        // the function returns after sending a notification. If the `EMPTY`
        // flag is cleared, it is set again and the index of the current waker
        // becomes that of the redundant slot in the next iteration.
        //
        // Transitions:
        //
        // |  I  O  E  |  I  O  E  |
        // |-----------|-----------|
        // |  0  0  0  | unobserv. | -> Deallocate
        // |  x  1  1  |  x  0  0  | -> End
        // |  x  1  0  | !x  1  1  | -> Retry

        // It is necessary to make sure that the destructor is not run: since
        // the `OPEN` flag will be cleared once the value is sent,
        // `Sender::drop` would otherwise wrongly consider the channel as closed
        // by the receiver and would deallocate `inner` while the receiver is
        // alive.
        let this = ManuallyDrop::new(self);

        // Store the value.
        //
        // Note: there is no need to drop a previous value since the
        // `Receiver::sender` method would have dropped the value if there was
        // one.
        //
        // Safety: no race for accessing the value is possible since there can
        // be at most one sender alive at a time and the receiver will not read
        // the value before the `OPEN` flag is cleared. It is safe to access
        // `inner` since we did not clear the `OPEN` flag.
        unsafe { this.inner.as_ref().write_value(t) };

        // Retrieve the index of the current waker.
        //
        // Ordering: Relaxed ordering is sufficient since only the sender can
        // modify `INDEX`.
        //
        // Safety: it is safe to access `inner` since we did not clear the
        // `OPEN` flag.
        let mut idx = state_to_index(unsafe { this.inner.as_ref().state.load(Ordering::Relaxed) });

        loop {
            // Take the current waker.
            //
            // Safety: the receiver thread never accesses the waker stored at
            // `INDEX`. It is safe to access `inner` since we did not
            // clear the `OPEN` flag.
            let waker = unsafe { this.inner.as_ref().take_waker(idx) };

            // Rather than a Compare-And-Swap, a `fetch_sub` operation is used
            // as it is faster on many platforms. The specific order of the
            // flags and the wrapping underflow behavior of `fetch_sub` are
            // exploited to implement the transition table.
            //
            // Ordering: Acquire is necessary to synchronize with the Release
            // store in the `Receiver::poll` method in case an updated waker
            // needs to be taken. Release is in turn necessary to ensure the
            // visibility of both (i) the value and (ii) the consumption of the
            // waker in the previous loop iteration (if any). The Release
            // synchronizes with the Acquire load of the state in the receiver
            // `poll` and `sender` methods.
            //
            // Safety: it is safe to access `inner` since we did not clear the
            // `OPEN` flag.
            let state = unsafe {
                this.inner
                    .as_ref()
                    .state
                    .fetch_sub(OPEN | EMPTY, Ordering::AcqRel)
            };

            // Deallocate the channel if closed.
            //
            // Safety: it is safe to access `inner` since we did not clear the
            // `OPEN` flag. `inner` will no longer be used once deallocated. In
            // particular, the sender destructor will not be called.
            unsafe {
                if state & OPEN == 0 {
                    // Safety: a value was just written and there is no live
                    // receiver so no risk of a race.
                    this.inner.as_ref().drop_value_in_place();
                    drop(Box::from_raw(this.inner.as_ptr()));
                    return;
                }
            }

            // If the waker was not updated, notify the receiver and return.
            if state & EMPTY == EMPTY {
                if let Some(waker) = waker {
                    waker.wake()
                }
                return;
            }

            // Update the local waker index to the current value of `INDEX`.
            idx = 1 - idx;
        }
    }
/// Sends a value to the receiver and consume the sender.
Sends a value to the receiver and consume the sender.
Sends a value to the receiver and consume the sender .
pub fn send(self, t: T) {
        // The send method is iterative. At each iteration, the `EMPTY` flag is
        // checked. If set, the presence of a value is signaled immediately and
        // the function returns after sending a notification. If the `EMPTY`
        // flag is cleared, it is set again and the index of the current waker
        // becomes that of the redundant slot in the next iteration.
        //
        // Transitions:
        //
        // |  I  O  E  |  I  O  E  |
        // |-----------|-----------|
        // |  0  0  0  | unobserv. | -> Deallocate
        // |  x  1  1  |  x  0  0  | -> End
        // |  x  1  0  | !x  1  1  | -> Retry
        // It is necessary to make sure that the destructor is not run: since
        // the `OPEN` flag will be cleared once the value is sent,
        // `Sender::drop` would otherwise wrongly consider the channel as closed
        // by the receiver and would deallocate `inner` while the receiver is
        // alive.
        let this = ManuallyDrop::new(self);
        // Store the value.
        //
        // Note: there is no need to drop a previous value since the
        // `Receiver::sender` method would have dropped the value if there was
        // one.
        //
        // Safety: no race for accessing the value is possible since there can
        // be at most one sender alive at a time and the receiver will not read
        // the value before the `OPEN` flag is cleared. It is safe to access
        // `inner` since we did not clear the `OPEN` flag.
        unsafe { this.inner.as_ref().write_value(t) };
        // Retrieve the index of the current waker.
        //
        // Ordering: Relaxed ordering is sufficient since only the sender can
        // modify `INDEX`.
        //
        // Safety: it is safe to access `inner` since we did not clear the
        // `OPEN` flag.
        let mut idx = state_to_index(unsafe { this.inner.as_ref().state.load(Ordering::Relaxed) });
        loop {
            // Take the current waker.
            //
            // Safety: the receiver thread never accesses the waker stored at
            // `INDEX`. It is safe to access `inner` since we did not
            // clear the `OPEN` flag.
            let waker = unsafe { this.inner.as_ref().take_waker(idx) };
            // Rather than a Compare-And-Swap, a `fetch_sub` operation is used
            // as it is faster on many platforms. The specific order of the
            // flags and the wrapping underflow behavior of `fetch_sub` are
            // exploited to implement the transition table.
            //
            // Ordering: Acquire is necessary to synchronize with the Release
            // store in the `Receiver::poll` method in case an updated waker
            // needs to be taken. Release is in turn necessary to ensure the
            // visibility of both (i) the value and (ii) the consumption of the
            // waker in the previous loop iteration (if any). The Release
            // synchronizes with the Acquire load of the state in the receiver
            // `poll` and `sender` methods.
            //
            // Safety: it is safe to access `inner` since we did not clear the
            // `OPEN` flag.
            let state = unsafe {
                this.inner
                    .as_ref()
                    .state
                    .fetch_sub(OPEN | EMPTY, Ordering::AcqRel)
            };
            // Deallocate the channel if closed.
            //
            // Safety: it is safe to access `inner` since we did not clear the
            // `OPEN` flag. `inner` will no longer be used once deallocated. In
            // particular, the sender destructor will not be called.
            unsafe {
                if state & OPEN == 0 {
                    // Safety: a value was just written and there is no live
                    // receiver so no risk of a race.
                    this.inner.as_ref().drop_value_in_place();
                    drop(Box::from_raw(this.inner.as_ptr()));
                    return;
                }
            }
            // If the waker was not updated, notify the receiver and return.
            if state & EMPTY == EMPTY {
                if let Some(waker) = waker {
                    waker.wake()
                }
                return;
            }
            // Update the local waker index to the current value of `INDEX`.
            idx = 1 - idx;
        }
    }
pub fn send ( self , t : T ) { // The send method is iterative. At each iteration, the `EMPTY` flag is // checked. If set, the presence of a value is signaled immediately and // the function returns after sending a notification. If the `EMPTY` // flag is cleared, it is set again and the index of the current waker // becomes that of the redundant slot in the next iteration. // // Transitions: // // |  I  O  E  |  I  O  E  | // |-----------|-----------| // |  0  0  0  | unobserv. | -> Deallocate // |  x  1  1  |  x  0  0  | -> End // |  x  1  0  | !x  1  1  | -> Retry // It is necessary to make sure that the destructor is not run: since // the `OPEN` flag will be cleared once the value is sent, // `Sender::drop` would otherwise wrongly consider the channel as closed // by the receiver and would deallocate `inner` while the receiver is // alive. let this = ManuallyDrop :: new ( self ) ; // Store the value. // // Note: there is no need to drop a previous value since the // `Receiver::sender` method would have dropped the value if there was // one. // // Safety: no race for accessing the value is possible since there can // be at most one sender alive at a time and the receiver will not read // the value before the `OPEN` flag is cleared. It is safe to access // `inner` since we did not clear the `OPEN` flag. unsafe { this . inner . as_ref ( ) . write_value ( t ) } ; // Retrieve the index of the current waker. // // Ordering: Relaxed ordering is sufficient since only the sender can // modify `INDEX`. // // Safety: it is safe to access `inner` since we did not clear the // `OPEN` flag. let mut idx = state_to_index ( unsafe { this . inner . as_ref ( ) . state . load ( Ordering :: Relaxed ) } ) ; loop { // Take the current waker. // // Safety: the receiver thread never accesses the waker stored at // `INDEX`. It is safe to access `inner` since we did not // clear the `OPEN` flag. let waker = unsafe { this . inner . as_ref ( ) . take_waker ( idx ) } ; // Rather than a Compare-And-Swap, a `fetch_sub` operation is used // as it is faster on many platforms. The specific order of the // flags and the wrapping underflow behavior of `fetch_sub` are // exploited to implement the transition table. // // Ordering: Acquire is necessary to synchronize with the Release // store in the `Receiver::poll` method in case an updated waker // needs to be taken. Release is in turn necessary to ensure the // visibility of both (i) the value and (ii) the consumption of the // waker in the previous loop iteration (if any). The Release // synchronizes with the Acquire load of the state in the receiver // `poll` and `sender` methods. // // Safety: it is safe to access `inner` since we did not clear the // `OPEN` flag. let state = unsafe { this . inner . as_ref ( ) . state . fetch_sub ( OPEN | EMPTY , Ordering :: AcqRel ) } ; // Deallocate the channel if closed. // // Safety: it is safe to access `inner` since we did not clear the // `OPEN` flag. `inner` will no longer be used once deallocated. In // particular, the sender destructor will not be called. unsafe { if state & OPEN == 0 { // Safety: a value was just written and there is no live // receiver so no risk of a race. this . inner . as_ref ( ) . drop_value_in_place ( ) ; drop ( Box :: from_raw ( this . inner . as_ptr ( ) ) ) ; return ; } } // If the waker was not updated, notify the receiver and return. if state & EMPTY == EMPTY { if let Some ( waker ) = waker { waker . wake ( ) } return ; } // Update the local waker index to the current value of `INDEX`. idx = 1 - idx ; } }
Sends a value to the receiver and consume the sender.
Sends a value to the receiver and consume the sender .
self
t
T