mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev.
This commit is contained in:
parent
ff8cbff810
commit
95fc29fa0d
255 changed files with 3550 additions and 3362 deletions
|
@ -3,33 +3,37 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::borrow::ToOwned;
|
||||
use std::task;
|
||||
use std::comm::Sender;
|
||||
use std::task::TaskBuilder;
|
||||
use task_state;
|
||||
use std::thread;
|
||||
use std::sync::mpsc::Sender;
|
||||
use std::thread::Builder;
|
||||
|
||||
pub fn spawn_named(name: String, f: proc():Send) {
|
||||
let builder = task::TaskBuilder::new().named(name);
|
||||
builder.spawn(proc() {
|
||||
f();
|
||||
pub fn spawn_named<F>(name: String, f: F)
|
||||
where F: FnOnce() + Send
|
||||
{
|
||||
let builder = thread::Builder::new().name(name);
|
||||
builder.spawn(move || {
|
||||
f()
|
||||
});
|
||||
}
|
||||
|
||||
/// Arrange to send a particular message to a channel if the task fails.
|
||||
pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
|
||||
state: task_state::TaskState,
|
||||
f: proc(): Send,
|
||||
msg: T,
|
||||
dest: Sender<T>) {
|
||||
let future_result = TaskBuilder::new().named(name).try_future(proc() {
|
||||
pub fn spawn_named_with_send_on_failure<F, T>(name: &'static str,
|
||||
state: task_state::TaskState,
|
||||
f: F,
|
||||
msg: T,
|
||||
dest: Sender<T>)
|
||||
where F: FnOnce() + Send,
|
||||
T: Send
|
||||
{
|
||||
let future_handle = thread::Builder::new().name(name.to_owned()).scoped(move || {
|
||||
task_state::initialize(state);
|
||||
f();
|
||||
f()
|
||||
});
|
||||
|
||||
let watched_name = name.to_owned();
|
||||
let watcher_name = format!("{}Watcher", watched_name);
|
||||
TaskBuilder::new().named(watcher_name).spawn(proc() {
|
||||
match future_result.into_inner() {
|
||||
let watcher_name = format!("{}Watcher", name);
|
||||
Builder::new().name(watcher_name).spawn(move || {
|
||||
match future_handle.join() {
|
||||
Ok(()) => (),
|
||||
Err(..) => {
|
||||
debug!("{} failed, notifying constellation", name);
|
||||
|
@ -38,3 +42,10 @@ pub fn spawn_named_with_send_on_failure<T: Send>(name: &'static str,
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spawn_named_test() {
|
||||
spawn_named("Test".to_owned(), move || {
|
||||
debug!("I can run!");
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue