Auto merge of #36893 - apasel422:issue-32114, r=alexcrichton
Restore `DISCONNECTED` state in `oneshot::Packet::send` Closes #32114 I'm not sure if this is the best approach, but the current action of swapping `DISCONNECTED` with `DATA` seems wrong. Additionally, it is strange that the `send` method (and others in the `oneshot` module) takes `&mut self` despite performing atomic operations, as this requires extra discipline to avoid data races and lets us use methods like `AtomicUsize::get_mut` instead of methods that require a memory ordering.
This commit is contained in:
commit
46957f0577
@ -1940,6 +1940,13 @@ mod tests {
|
|||||||
// wait for the child thread to exit before we exit
|
// wait for the child thread to exit before we exit
|
||||||
rx2.recv().unwrap();
|
rx2.recv().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn issue_32114() {
|
||||||
|
let (tx, _) = channel();
|
||||||
|
let _ = tx.send(123);
|
||||||
|
assert_eq!(tx.send(123), Err(SendError(123)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(test, not(target_os = "emscripten")))]
|
#[cfg(all(test, not(target_os = "emscripten")))]
|
||||||
|
@ -113,6 +113,8 @@ impl<T> Packet<T> {
|
|||||||
// Couldn't send the data, the port hung up first. Return the data
|
// Couldn't send the data, the port hung up first. Return the data
|
||||||
// back up the stack.
|
// back up the stack.
|
||||||
DISCONNECTED => {
|
DISCONNECTED => {
|
||||||
|
self.state.swap(DISCONNECTED, Ordering::SeqCst);
|
||||||
|
self.upgrade = NothingSent;
|
||||||
Err(self.data.take().unwrap())
|
Err(self.data.take().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user