std: Second pass stabilization for comm
This commit is a second pass stabilization for the `std::comm` module,
performing the following actions:
* The entire `std::comm` module was moved under `std::sync::mpsc`. This movement
reflects that channels are just yet another synchronization primitive, and
they don't necessarily deserve a special place outside of the other
concurrency primitives that the standard library offers.
* The `send` and `recv` methods have all been removed.
* The `send_opt` and `recv_opt` methods have been renamed to `send` and `recv`.
This means that all send/receive operations return a `Result` now indicating
whether the operation was successful or not.
* The error type of `send` is now a `SendError` to implement a custom error
message and allow for `unwrap()`. The error type contains an `into_inner`
method to extract the value.
* The error type of `recv` is now `RecvError` for the same reasons as `send`.
* The `TryRecvError` and `TrySendError` types have had public reexports removed
of their variants and the variant names have been tweaked with enum
namespacing rules.
* The `Messages` iterator is renamed to `Iter`
This functionality is now all `#[stable]`:
* `Sender`
* `SyncSender`
* `Receiver`
* `std::sync::mpsc`
* `channel`
* `sync_channel`
* `Iter`
* `Sender::send`
* `Sender::clone`
* `SyncSender::send`
* `SyncSender::try_send`
* `SyncSender::clone`
* `Receiver::recv`
* `Receiver::try_recv`
* `Receiver::iter`
* `SendError`
* `RecvError`
* `TrySendError::{mod, Full, Disconnected}`
* `TryRecvError::{mod, Empty, Disconnected}`
* `SendError::into_inner`
* `TrySendError::into_inner`
This is a breaking change due to the modification of where this module is
located, as well as the changing of the semantics of `send` and `recv`. Most
programs just need to rename imports of `std::comm` to `std::sync::mpsc` and
add calls to `unwrap` after a send or a receive operation.
[breaking-change]
This commit is contained in:
parent
bb8f4fc3b7
commit
bc83a009f6
109 changed files with 1175 additions and 1206 deletions
|
|
@ -23,10 +23,10 @@
|
|||
use prelude::v1::*;
|
||||
|
||||
use cell::UnsafeCell;
|
||||
use comm::{channel, Sender, Receiver};
|
||||
use mem;
|
||||
use rt;
|
||||
use sync::{StaticMutex, StaticCondvar};
|
||||
use sync::mpsc::{channel, Sender, Receiver};
|
||||
use sys::helper_signal;
|
||||
|
||||
use thread::Thread;
|
||||
|
|
@ -118,7 +118,7 @@ impl<M: Send> Helper<M> {
|
|||
// message. Otherwise it could wake up and go to sleep before we
|
||||
// send the message.
|
||||
assert!(!self.chan.get().is_null());
|
||||
(**self.chan.get()).send(msg);
|
||||
(**self.chan.get()).send(msg).unwrap();
|
||||
helper_signal::signal(*self.signal.get() as helper_signal::signal);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ use self::Req::*;
|
|||
|
||||
use c_str::{CString, ToCStr};
|
||||
use collections;
|
||||
use comm::{channel, Sender, Receiver};
|
||||
use hash::Hash;
|
||||
use io::process::{ProcessExit, ExitStatus, ExitSignal};
|
||||
use io::{mod, IoResult, IoError, EndOfFile};
|
||||
|
|
@ -22,6 +21,7 @@ use mem;
|
|||
use os;
|
||||
use path::BytesContainer;
|
||||
use ptr;
|
||||
use sync::mpsc::{channel, Sender, Receiver};
|
||||
use sys::fs::FileDesc;
|
||||
use sys::{mod, retry, c, wouldblock, set_nonblocking, ms_to_timeval};
|
||||
use sys_common::helper_thread::Helper;
|
||||
|
|
@ -277,8 +277,8 @@ impl Process {
|
|||
}
|
||||
|
||||
pub fn wait(&self, deadline: u64) -> IoResult<ProcessExit> {
|
||||
use std::cmp;
|
||||
use std::comm;
|
||||
use cmp;
|
||||
use sync::mpsc::TryRecvError;
|
||||
|
||||
static mut WRITE_FD: libc::c_int = 0;
|
||||
|
||||
|
|
@ -337,9 +337,9 @@ impl Process {
|
|||
|
||||
let (tx, rx) = channel();
|
||||
unsafe { HELPER.send(NewChild(self.pid, tx, deadline)); }
|
||||
return match rx.recv_opt() {
|
||||
return match rx.recv() {
|
||||
Ok(e) => Ok(e),
|
||||
Err(()) => Err(timeout("wait timed out")),
|
||||
Err(..) => Err(timeout("wait timed out")),
|
||||
};
|
||||
|
||||
// Register a new SIGCHLD handler, returning the reading half of the
|
||||
|
|
@ -420,11 +420,11 @@ impl Process {
|
|||
Ok(NewChild(pid, tx, deadline)) => {
|
||||
active.push((pid, tx, deadline));
|
||||
}
|
||||
Err(comm::Disconnected) => {
|
||||
Err(TryRecvError::Disconnected) => {
|
||||
assert!(active.len() == 0);
|
||||
break 'outer;
|
||||
}
|
||||
Err(comm::Empty) => break,
|
||||
Err(TryRecvError::Empty) => break,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -460,7 +460,7 @@ impl Process {
|
|||
active.retain(|&(pid, ref tx, _)| {
|
||||
let pr = Process { pid: pid };
|
||||
match pr.try_wait() {
|
||||
Some(msg) => { tx.send(msg); false }
|
||||
Some(msg) => { tx.send(msg).unwrap(); false }
|
||||
None => true,
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -49,13 +49,13 @@
|
|||
use prelude::v1::*;
|
||||
use self::Req::*;
|
||||
|
||||
use comm::{mod, channel, Sender, Receiver};
|
||||
use io::IoResult;
|
||||
use libc;
|
||||
use mem;
|
||||
use os;
|
||||
use ptr;
|
||||
use sync::atomic;
|
||||
use sync::mpsc::{channel, Sender, Receiver, TryRecvError};
|
||||
use sys::c;
|
||||
use sys::fs::FileDesc;
|
||||
use sys_common::helper_thread::Helper;
|
||||
|
|
@ -168,7 +168,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
|||
1 => {
|
||||
loop {
|
||||
match messages.try_recv() {
|
||||
Err(comm::Disconnected) => {
|
||||
Err(TryRecvError::Disconnected) => {
|
||||
assert!(active.len() == 0);
|
||||
break 'outer;
|
||||
}
|
||||
|
|
@ -179,7 +179,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
|||
match dead.iter().position(|&(i, _)| id == i) {
|
||||
Some(i) => {
|
||||
let (_, i) = dead.remove(i).unwrap();
|
||||
ack.send(i);
|
||||
ack.send(i).unwrap();
|
||||
continue
|
||||
}
|
||||
None => {}
|
||||
|
|
@ -187,7 +187,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
|
|||
let i = active.iter().position(|i| i.id == id);
|
||||
let i = i.expect("no timer found");
|
||||
let t = active.remove(i).unwrap();
|
||||
ack.send(t);
|
||||
ack.send(t).unwrap();
|
||||
}
|
||||
Err(..) => break
|
||||
}
|
||||
|
|
@ -271,7 +271,7 @@ impl Timer {
|
|||
None => {
|
||||
let (tx, rx) = channel();
|
||||
HELPER.send(RemoveTimer(self.id, tx));
|
||||
rx.recv()
|
||||
rx.recv().unwrap()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue