fn rendezvous_send<'a>(
        &'a self,
        mut data: MutexGuard<'a, Data<T>>,
        try: bool,
        val: T,
    ) -> SendOp<'a, T> {
        while data.waiting_send == 1 || data.user.len() == 1 {
            if try {
                return SendOp::blocked(data, val);
            }
            data = self.cond.wait(data).unwrap();
        }
        // invariant: at most one sender can be here.
        if data.closed {
            return SendOp::closed(data, val);
        }
        if try && data.waiting_recv == 0 {
            return SendOp::blocked(data, val);
        }
        data.user.push(val);
        // We need to wake up any blocked receivers so they get a chance to
        // grab the value we pushed.
        self.notify();
        while data.user.len() == 1 {
            data.waiting_send += 1;
            data = self.cond.wait(data).unwrap();
            data.waiting_send -= 1;
        }
        // And now we need to make sure we wake up any previous blocked
        // senders so they get a shot at synchronizing.
        self.notify();
        SendOp::ok(data)
    }
// Rendezvous send is the trickiest because we need to:
//
//  1) Make sure no other senders interfere. We do this by ensuring
//     that there are no other waiting senders before trying to
//     synchronize with a receiver.
//  2) Wait for a receiver to consume the sent value. We do this by
//     waiting on the condition variable until the value we put
//     in the buffer is gone.
Rendezvous send is the trickiest because we need to:
1) Make sure no other senders interfere. We do this by ensuring
that there are no other waiting senders before trying to
synchronize with a receiver.
2) Wait for a receiver to consume the sent value. We do this by
waiting on the condition variable until the value we put
in the buffer is gone.
Rendezvous send is the trickiest because we need to : 1 ) Make sure no other senders interfere . We do this by ensuring that there are no other waiting senders before trying to synchronize with a receiver . 2 ) Wait for a receiver to consume the sent value . We do this by waiting on the condition variable until the value we put in the buffer is gone .
fn rendezvous_send<'a>(
        &'a self,
        mut data: MutexGuard<'a, Data<T>>,
        try: bool,
        val: T,
    ) -> SendOp<'a, T> {
        while data.waiting_send == 1 || data.user.len() == 1 {
            if try {
                return SendOp::blocked(data, val);
            }
            data = self.cond.wait(data).unwrap();
        }
        // invariant: at most one sender can be here.
        if data.closed {
            return SendOp::closed(data, val);
        }
        if try && data.waiting_recv == 0 {
            return SendOp::blocked(data, val);
        }
        data.user.push(val);
        // We need to wake up any blocked receivers so they get a chance to
        // grab the value we pushed.
        self.notify();
        while data.user.len() == 1 {
            data.waiting_send += 1;
            data = self.cond.wait(data).unwrap();
            data.waiting_send -= 1;
        }
        // And now we need to make sure we wake up any previous blocked
        // senders so they get a shot at synchronizing.
        self.notify();
        SendOp::ok(data)
    }
fn rendezvous_send < ' a > ( & ' a self , mut data : MutexGuard < ' a , Data < T > > , try : bool , val : T , ) -> SendOp < ' a , T > { while data . waiting_send == 1 || data . user . len ( ) == 1 { if try { return SendOp :: blocked ( data , val ) ; } data = self . cond . wait ( data ) . unwrap ( ) ; } // invariant: at most one sender can be here. if data . closed { return SendOp :: closed ( data , val ) ; } if try && data . waiting_recv == 0 { return SendOp :: blocked ( data , val ) ; } data . user . push ( val ) ; // We need to wake up any blocked receivers so they get a chance to // grab the value we pushed. self . notify ( ) ; while data . user . len ( ) == 1 { data . waiting_send += 1 ; data = self . cond . wait ( data ) . unwrap ( ) ; data . waiting_send -= 1 ; } // And now we need to make sure we wake up any previous blocked // senders so they get a shot at synchronizing. self . notify ( ) ; SendOp :: ok ( data ) }
Rendezvous send is the trickiest because we need to:
1) Make sure no other senders interfere.
Rendezvous send is the trickiest because we need to : 1 ) Make sure no other senders interfere .
&'a self
data
MutexGuard<'a, Data<T>>
try
bool
val
T
&'a self
data
MutexGuard<'a, Data<T>>
try
bool
val
T