-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
auto merge of #8645 : alexcrichton/rust/issue-6436-run-non-blocking, …
…r=brson This overhauls `std::run` to instead run on top of libuv. This is *not* in a mergeable state, I've been attempting to diagnose failures in the compiletest suite. I've managed to find a fair number of bugs so far, but I still don't seem to be done yet. Notable changes: * This requires upgrading libuv. From the discussion on #6567, I took libuv master from a few days ago, applied one patch to fix process spawning with multiple event loops in libuv, and pushed to my own fork * The build system for libuv has changed since we last used it. There's some extra checkout from a google build system which apparently does all the magic if you don't want to require autotools, and the google system just requires python. I updated the Makefile to get this build system and build libuv with it instead. This is untested on windows and arm, and both will probably need to see some improvement. * This required adding some pipe bindings to libuv as well. Currently the support is pretty simple and probably completely unsafe for pipes, but you at least get read/write methods. This is necessary for capturing output of processes. * I didn't redesign `std::run` at all, I simply tried to reimplement all the existing functionality on top of libuv. Some functions ended up dying, but nothing major. All uses of `std::run` in the compiler still work just fine. I'm not quite sure how the rest of the runtime deals with this, but I marked process structures as `no_send` because the waiting/waking up has to happen in the same event loop right now. If processes start migrating between event loops then very bad things can happen. This may be what threadsafe I/O would fix, and I would be more than willing to rebase on that if it lands first. Anyway, for now I wanted to put this up for review, I'm still investigating the corruption/deadlock bugs, but this is in an *almost* workable state. Once I find the bugs I'll also rebase on the current master.
- Loading branch information
Showing
27 changed files
with
1,151 additions
and
1,126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
//! Synchronous, in-memory pipes. | ||
//! | ||
//! Currently these aren't particularly useful, there only exists bindings | ||
//! enough so that pipes can be created to child processes. | ||
use prelude::*; | ||
use super::{Reader, Writer}; | ||
use rt::io::{io_error, read_error, EndOfFile}; | ||
use rt::local::Local; | ||
use rt::rtio::{RtioPipeObject, RtioStream, IoFactoryObject, IoFactory}; | ||
use rt::uv::pipe; | ||
|
||
pub struct PipeStream(~RtioPipeObject); | ||
|
||
impl PipeStream { | ||
/// Creates a new pipe initialized, but not bound to any particular | ||
/// source/destination | ||
pub fn new() -> Option<PipeStream> { | ||
let pipe = unsafe { | ||
let io: *mut IoFactoryObject = Local::unsafe_borrow(); | ||
(*io).pipe_init(false) | ||
}; | ||
match pipe { | ||
Ok(p) => Some(PipeStream(p)), | ||
Err(ioerr) => { | ||
io_error::cond.raise(ioerr); | ||
None | ||
} | ||
} | ||
} | ||
|
||
/// Extracts the underlying libuv pipe to be bound to another source. | ||
pub fn uv_pipe(&self) -> pipe::Pipe { | ||
// Did someone say multiple layers of indirection? | ||
(**self).uv_pipe() | ||
} | ||
} | ||
|
||
impl Reader for PipeStream { | ||
fn read(&mut self, buf: &mut [u8]) -> Option<uint> { | ||
match (***self).read(buf) { | ||
Ok(read) => Some(read), | ||
Err(ioerr) => { | ||
// EOF is indicated by returning None | ||
if ioerr.kind != EndOfFile { | ||
read_error::cond.raise(ioerr); | ||
} | ||
return None; | ||
} | ||
} | ||
} | ||
|
||
fn eof(&mut self) -> bool { fail!() } | ||
} | ||
|
||
impl Writer for PipeStream { | ||
fn write(&mut self, buf: &[u8]) { | ||
match (***self).write(buf) { | ||
Ok(_) => (), | ||
Err(ioerr) => { | ||
io_error::cond.raise(ioerr); | ||
} | ||
} | ||
} | ||
|
||
fn flush(&mut self) { fail!() } | ||
} |
Oops, something went wrong.