NoneBlocked => {}
_ => unreachable!(),
}
- drop(guard); // unlock
- wait_token.wait(); // block
- lock.lock() // relock
+ drop(guard); // unlock
+ wait_token.wait(); // block
+ lock.lock().unwrap() // relock
}
/// Wakes up a thread, dropping the lock at the correct time
tail: 0 as *mut Node,
},
buf: Buffer {
- buf: Vec::from_fn(cap + if cap == 0 {1} else {0}, |_| None),
+ buf: range(0, cap + if cap == 0 {1} else {0}).map(|_| None).collect(),
start: 0,
size: 0,
},
fn acquire_send_slot(&self) -> MutexGuard<State<T>> {
let mut node = Node { token: None, next: 0 as *mut Node };
loop {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
// are we ready to go?
if guard.disconnected || guard.buf.size() < guard.buf.cap() {
return guard;
}
pub fn try_send(&self, t: T) -> Result<(), super::TrySendError<T>> {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
if guard.disconnected {
Err(super::TrySendError::Disconnected(t))
} else if guard.buf.size() == guard.buf.cap() {
// When reading this, remember that there can only ever be one receiver at
// time.
pub fn recv(&self) -> Result<T, ()> {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
// Wait for the buffer to have something in it. No need for a while loop
// because we're the only receiver.
}
pub fn try_recv(&self) -> Result<T, Failure> {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
// Easy cases first
if guard.disconnected { return Err(Disconnected) }
}
// Not much to do other than wake up a receiver if one's there
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
if guard.disconnected { return }
guard.disconnected = true;
match mem::replace(&mut guard.blocker, NoneBlocked) {
}
pub fn drop_port(&self) {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
if guard.disconnected { return }
guard.disconnected = true;
// If Ok, the value is whether this port has data, if Err, then the upgraded
// port needs to be checked instead of this one.
pub fn can_recv(&self) -> bool {
- let guard = self.lock.lock();
+ let guard = self.lock.lock().unwrap();
guard.disconnected || guard.buf.size() > 0
}
// Attempts to start selection on this port. This can either succeed or fail
// because there is data waiting.
pub fn start_selection(&self, token: SignalToken) -> StartResult {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
if guard.disconnected || guard.buf.size() > 0 {
Abort
} else {
//
// The return value indicates whether there's data on this port.
pub fn abort_selection(&self) -> bool {
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
match mem::replace(&mut guard.blocker, NoneBlocked) {
NoneBlocked => true,
BlockedSender(token) => {
impl<T: Send> Drop for Packet<T> {
fn drop(&mut self) {
assert_eq!(self.channels.load(atomic::SeqCst), 0);
- let mut guard = self.lock.lock();
+ let mut guard = self.lock.lock().unwrap();
assert!(guard.queue.dequeue().is_none());
assert!(guard.canceled.is_none());
}