Skip to content

Commit

Permalink
Fallout from libgreen and libnative removal
Browse files Browse the repository at this point in the history
  • Loading branch information
aturon committed Nov 21, 2014
1 parent a68ec98 commit 40c78ab
Show file tree
Hide file tree
Showing 28 changed files with 47 additions and 349 deletions.
5 changes: 2 additions & 3 deletions mk/crates.mk
Expand Up @@ -37,7 +37,7 @@
#
# DEPS_<crate>
# These lists are the dependencies of the <crate> that is to be built.
# Rust dependencies are listed bare (i.e. std, green) and native
# Rust dependencies are listed bare (i.e. std) and native
# dependencies have a "native:" prefix (i.e. native:hoedown). All deps
# will be built before the crate itself is built.
#
Expand All @@ -49,7 +49,7 @@
# automatically generated for all stage/host/target combinations.
################################################################################

TARGET_CRATES := libc std green flate arena term \
TARGET_CRATES := libc std flate arena term \
serialize sync getopts collections test time rand \
log regex graphviz core rbml alloc rustrt \
unicode
Expand All @@ -66,7 +66,6 @@ DEPS_rustrt := alloc core libc collections native:rustrt_native
DEPS_std := core libc rand alloc collections rustrt sync unicode \
native:rust_builtin native:backtrace
DEPS_graphviz := std
DEPS_green := std native:context_switch
DEPS_syntax := std term serialize log fmt_macros arena libc
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
DEPS_rustc := syntax flate arena serialize getopts rbml \
Expand Down
2 changes: 0 additions & 2 deletions src/README.md
Expand Up @@ -9,8 +9,6 @@ Source layout:
| `libcore/` | The Rust core library |
| `libdebug/` | Debugging utilities |
| `libstd/` | The standard library (imported and linked by default) |
| `libgreen/` | The M:N runtime library |
| `libnative/` | The 1:1 runtime library |
| `libsyntax/` | The Rust parser and pretty-printer |
| `libtest/` | Rust's test-runner code |
| ------------------- | --------------------------------------------------------- |
Expand Down
8 changes: 4 additions & 4 deletions src/doc/reference.md
Expand Up @@ -999,14 +999,14 @@ An example of what will and will not work for `use` items:

```
# #![allow(unused_imports)]
use foo::native::start; // good: foo is at the root of the crate
use foo::core::iter; // good: foo is at the root of the crate
use foo::baz::foobaz; // good: foo is at the root of the crate
mod foo {
extern crate native;
extern crate core;
use foo::native::start; // good: foo is at crate root
// use native::start; // bad: native is not at the crate root
use foo::core::iter; // good: foo is at crate root
// use core::iter; // bad: native is not at the crate root
use self::baz::foobaz; // good: self refers to module 'foo'
use foo::bar::foobar; // good: foo is at crate root
Expand Down
1 change: 0 additions & 1 deletion src/liballoc/lib.rs
Expand Up @@ -73,7 +73,6 @@ extern crate libc;

// Allow testing this library

#[cfg(test)] extern crate native;
#[cfg(test)] #[phase(plugin, link)] extern crate std;
#[cfg(test)] #[phase(plugin, link)] extern crate log;

Expand Down
1 change: 0 additions & 1 deletion src/libcollections/lib.rs
Expand Up @@ -31,7 +31,6 @@
extern crate unicode;
extern crate alloc;

#[cfg(test)] extern crate native;
#[cfg(test)] extern crate test;

#[cfg(test)] #[phase(plugin, link)] extern crate std;
Expand Down
1 change: 0 additions & 1 deletion src/liblibc/lib.rs
Expand Up @@ -83,7 +83,6 @@ extern crate core;

#[cfg(test)] extern crate std;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate native;

pub use self::Nullable::*;

Expand Down
1 change: 0 additions & 1 deletion src/librand/lib.rs
Expand Up @@ -33,7 +33,6 @@ extern crate core;

#[cfg(test)] #[phase(plugin, link)] extern crate std;
#[cfg(test)] #[phase(plugin, link)] extern crate log;
#[cfg(test)] extern crate native;

use core::prelude::*;

Expand Down
1 change: 0 additions & 1 deletion src/librustrt/lib.rs
Expand Up @@ -30,7 +30,6 @@ extern crate collections;

#[cfg(test)] extern crate "rustrt" as realrustrt;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate native;

#[cfg(test)] #[phase(plugin, link)] extern crate std;

Expand Down
9 changes: 1 addition & 8 deletions src/librustrt/stack_overflow.rs
Expand Up @@ -65,14 +65,7 @@ pub unsafe fn report() {
#[cfg(any(windows, target_os = "linux", target_os = "macos"))]
unsafe fn get_task_guard_page() -> Option<uint> {
let task: Option<*mut Task> = Local::try_unsafe_borrow();

task.map(|task| {
let runtime = (*task).take_runtime();
let guard = runtime.stack_guard();
(*task).put_runtime(runtime);

guard.unwrap_or(0)
})
task.map(|task| (&*task).stack_guard().unwrap_or(0))
}

#[cfg(windows)]
Expand Down
2 changes: 0 additions & 2 deletions src/libstd/io/process.rs
Expand Up @@ -740,8 +740,6 @@ impl Drop for Process {
mod tests {
#![allow(unused_imports)]

extern crate native;

use super::*;
use prelude::*;
use io::timer::*;
Expand Down
1 change: 0 additions & 1 deletion src/libstd/lib.rs
Expand Up @@ -117,7 +117,6 @@

#![reexport_test_harness_main = "test_main"]

#[cfg(test)] extern crate green;
#[cfg(test)] #[phase(plugin, link)] extern crate log;

extern crate alloc;
Expand Down
12 changes: 6 additions & 6 deletions src/libstd/rt/mod.rs
Expand Up @@ -58,17 +58,17 @@ Several modules in `core` are clients of `rt`:

use failure;
use rustrt;
use startup;
use os;

// Reexport some of our utilities which are expected by other crates.
pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};

// Reexport functionality from librustrt and other crates underneath the
// standard library which work together to create the entire runtime.
pub use alloc::heap;
pub use rustrt::{task, local, mutex, exclusive, stack, args, rtio, thread};
pub use rustrt::{task, local, mutex, exclusive, stack, args, thread};
pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt};
pub use rustrt::{bookkeeping, at_exit, unwind, DEFAULT_ERROR_CODE, Runtime};
pub use rustrt::{at_exit, unwind, DEFAULT_ERROR_CODE};

// Simple backtrace functionality (to print on panic)
pub mod backtrace;
Expand All @@ -95,7 +95,7 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20);
#[cfg(not(test))]
#[lang = "start"]
fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
use std::mem;
use mem;
start(argc, argv, proc() {
let main: extern "Rust" fn() = unsafe { mem::transmute(main) };
main();
Expand Down Expand Up @@ -147,8 +147,8 @@ pub fn start(argc: int, argv: *const *const u8, main: proc()) -> int {
init(argc, argv);
let mut exit_code = None;
let mut main = Some(main);
let mut task = task::new((my_stack_bottom, my_stack_top),
rt::thread::main_guard_page());
let mut task = Task::new(Some((my_stack_bottom, my_stack_top)),
Some(rt::thread::main_guard_page()));
task.name = Some(str::Slice("<main>"));
drop(task.run(|| {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/helper_thread.rs
Expand Up @@ -21,7 +21,7 @@
//! time.

use mem;
use rt::bookkeeping;
use rustrt::bookkeeping;
use rt::mutex::StaticNativeMutex;
use rt;
use cell::UnsafeCell;
Expand Down
126 changes: 12 additions & 114 deletions src/libstd/task.rs
Expand Up @@ -11,11 +11,7 @@
//! Task creation
//!
//! An executing Rust program consists of a collection of tasks, each
//! with their own stack and local state. A Rust task is typically
//! backed by an operating system thread, making tasks 'just threads',
//! but may also be implemented via other strategies as well
//! (e.g. Rust comes with the [`green`](../../green/index.html)
//! scheduling crate for creating tasks backed by green threads).
//! with their own stack and local state.
//!
//! Tasks generally have their memory *isolated* from each other by
//! virtue of Rust's owned types (which of course may only be owned by
Expand All @@ -36,60 +32,13 @@
//! the main task panics the application will exit with a non-zero
//! exit code.
//!
//! # Basic task scheduling
//!
//! By default, every task is created with the same "flavor" as the calling task.
//! This flavor refers to the scheduling mode, with two possibilities currently
//! being 1:1 and M:N modes. Green (M:N) tasks are cooperatively scheduled and
//! native (1:1) tasks are scheduled by the OS kernel.
//!
//! ## Example
//!
//! ```rust
//! spawn(proc() {
//! println!("Hello, World!");
//! })
//! ```
//!
//! # Advanced task scheduling
//!
//! Task spawning can also be configured to use a particular scheduler, to
//! redirect the new task's output, or to yield a `future` representing the
//! task's final result. The configuration is established using the
//! `TaskBuilder` API:
//!
//! ## Example
//!
//! ```rust
//! extern crate green;
//! extern crate native;
//!
//! use std::task::TaskBuilder;
//! use green::{SchedPool, PoolConfig, GreenTaskBuilder};
//! use native::NativeTaskBuilder;
//!
//! # fn main() {
//! // Create a green scheduler pool with the default configuration
//! let mut pool = SchedPool::new(PoolConfig::new());
//!
//! // Spawn a task in the green pool
//! let mut fut_green = TaskBuilder::new().green(&mut pool).try_future(proc() {
//! /* ... */
//! });
//!
//! // Spawn a native task
//! let mut fut_native = TaskBuilder::new().native().try_future(proc() {
//! /* ... */
//! });
//!
//! // Wait for both tasks to finish, recording their outcome
//! let res_green = fut_green.unwrap();
//! let res_native = fut_native.unwrap();
//!
//! // Shut down the green scheduler pool
//! pool.shutdown();
//! # }
//! ```

#![unstable = "The task spawning model will be changed as part of runtime reform, and the module \
will likely be renamed from `task` to `thread`."]
Expand All @@ -108,26 +57,6 @@ use str::{Str, SendStr, IntoMaybeOwned};
use string::{String, ToString};
use sync::Future;

/// A means of spawning a task
pub trait Spawner {
/// Spawn a task, given low-level task options.
fn spawn(self, opts: task::TaskOpts, f: proc():Send);
}

/// The default task spawner, which spawns siblings to the current task.
pub struct SiblingSpawner;

impl Spawner for SiblingSpawner {
fn spawn(self, opts: task::TaskOpts, f: proc():Send) {
// bind tb to provide type annotation
let tb: Option<Box<Task>> = Local::try_take();
match tb {
Some(t) => t.spawn_sibling(opts, f),
None => panic!("need a local task to spawn a sibling task"),
};
}
}

/// The task builder type.
///
/// Provides detailed control over the properties and behavior of new tasks.
Expand All @@ -139,7 +68,7 @@ impl Spawner for SiblingSpawner {
// when you try to reuse the builder to spawn a new task. We'll just
// sidestep that whole issue by making builders uncopyable and making
// the run function move them in.
pub struct TaskBuilder<S = SiblingSpawner> {
pub struct TaskBuilder {
// A name for the task-to-be, for identification in panic messages
name: Option<SendStr>,
// The size of the stack for the spawned task
Expand All @@ -148,88 +77,60 @@ pub struct TaskBuilder<S = SiblingSpawner> {
stdout: Option<Box<Writer + Send>>,
// Task-local stderr
stderr: Option<Box<Writer + Send>>,
// The mechanics of actually spawning the task (i.e.: green or native)
spawner: S,
// Optionally wrap the eventual task body
gen_body: Option<proc(v: proc():Send):Send -> proc():Send>,
nocopy: marker::NoCopy,
}

impl TaskBuilder<SiblingSpawner> {
impl TaskBuilder {
/// Generate the base configuration for spawning a task, off of which more
/// configuration methods can be chained.
pub fn new() -> TaskBuilder<SiblingSpawner> {
pub fn new() -> TaskBuilder {
TaskBuilder {
name: None,
stack_size: None,
stdout: None,
stderr: None,
spawner: SiblingSpawner,
gen_body: None,
nocopy: marker::NoCopy,
}
}
}

impl<S: Spawner> TaskBuilder<S> {
impl TaskBuilder {
/// Name the task-to-be. Currently the name is used for identification
/// only in panic messages.
#[unstable = "IntoMaybeOwned will probably change."]
pub fn named<T: IntoMaybeOwned<'static>>(mut self, name: T) -> TaskBuilder<S> {
pub fn named<T: IntoMaybeOwned<'static>>(mut self, name: T) -> TaskBuilder {
self.name = Some(name.into_maybe_owned());
self
}

/// Set the size of the stack for the new task.
pub fn stack_size(mut self, size: uint) -> TaskBuilder<S> {
pub fn stack_size(mut self, size: uint) -> TaskBuilder {
self.stack_size = Some(size);
self
}

/// Redirect task-local stdout.
#[experimental = "May not want to make stdio overridable here."]
pub fn stdout(mut self, stdout: Box<Writer + Send>) -> TaskBuilder<S> {
pub fn stdout(mut self, stdout: Box<Writer + Send>) -> TaskBuilder {
self.stdout = Some(stdout);
self
}

/// Redirect task-local stderr.
#[experimental = "May not want to make stdio overridable here."]
pub fn stderr(mut self, stderr: Box<Writer + Send>) -> TaskBuilder<S> {
pub fn stderr(mut self, stderr: Box<Writer + Send>) -> TaskBuilder {
self.stderr = Some(stderr);
self
}

/// Set the spawning mechanism for the task.
///
/// The `TaskBuilder` API configures a task to be spawned, but defers to the
/// "spawner" to actually create and spawn the task. The `spawner` method
/// should not be called directly by `TaskBuiler` clients. It is intended
/// for use by downstream crates (like `native` and `green`) that implement
/// tasks. These downstream crates then add extension methods to the
/// builder, like `.native()` and `.green(pool)`, that actually set the
/// spawner.
pub fn spawner<T: Spawner>(self, spawner: T) -> TaskBuilder<T> {
// repackage the entire TaskBuilder since its type is changing.
let TaskBuilder {
name, stack_size, stdout, stderr, spawner: _, gen_body, nocopy
} = self;
TaskBuilder {
name: name,
stack_size: stack_size,
stdout: stdout,
stderr: stderr,
spawner: spawner,
gen_body: gen_body,
nocopy: nocopy,
}
}

// Where spawning actually happens (whether yielding a future or not)
fn spawn_internal(self, f: proc():Send,
on_exit: Option<proc(Result<(), Box<Any + Send>>):Send>) {
let TaskBuilder {
name, stack_size, stdout, stderr, spawner, mut gen_body, nocopy: _
name, stack_size, stdout, stderr, mut gen_body, nocopy: _
} = self;
let f = match gen_body.take() {
Some(gen) => gen(f),
Expand Down Expand Up @@ -348,11 +249,8 @@ pub fn name() -> Option<String> {
/// Yield control to the task scheduler.
#[unstable = "Name will change."]
pub fn deschedule() {
use rt::local::Local;

// FIXME(#7544): Optimize this, since we know we won't block.
let task: Box<Task> = Local::take();
task.yield_now();
use rt::task::Task;
Task::yield_now();
}

/// True if the running task is currently panicking (e.g. will return `true` inside a
Expand Down

0 comments on commit 40c78ab

Please sign in to comment.