rt: use sugary functions rather than manual range loops.
This commit is contained in:
parent
54e7bdc48e
commit
440f1e2dad
@ -55,10 +55,11 @@ pub fn clone() -> Option<~[~str]> {
|
|||||||
mod imp {
|
mod imp {
|
||||||
use libc;
|
use libc;
|
||||||
use option::{Option, Some, None};
|
use option::{Option, Some, None};
|
||||||
use iterator::{Iterator, range};
|
use iterator::Iterator;
|
||||||
use str;
|
use str;
|
||||||
use unstable::finally::Finally;
|
use unstable::finally::Finally;
|
||||||
use util;
|
use util;
|
||||||
|
use vec;
|
||||||
|
|
||||||
pub unsafe fn init(argc: int, argv: **u8) {
|
pub unsafe fn init(argc: int, argv: **u8) {
|
||||||
let args = load_argc_and_argv(argc, argv);
|
let args = load_argc_and_argv(argc, argv);
|
||||||
@ -111,11 +112,9 @@ mod imp {
|
|||||||
|
|
||||||
// Copied from `os`.
|
// Copied from `os`.
|
||||||
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] {
|
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~str] {
|
||||||
let mut args = ~[];
|
do vec::from_fn(argc as uint) |i| {
|
||||||
for i in range(0u, argc as uint) {
|
str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int))
|
||||||
args.push(str::raw::from_c_str(*(argv as **libc::c_char).offset(i as int)));
|
|
||||||
}
|
}
|
||||||
args
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(stage0)]
|
#[cfg(stage0)]
|
||||||
|
@ -59,7 +59,7 @@ Several modules in `core` are clients of `rt`:
|
|||||||
use cell::Cell;
|
use cell::Cell;
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use container::Container;
|
use container::Container;
|
||||||
use iterator::{Iterator, range};
|
use iterator::Iterator;
|
||||||
use option::{Option, None, Some};
|
use option::{Option, None, Some};
|
||||||
use ptr::RawPtr;
|
use ptr::RawPtr;
|
||||||
use rt::local::Local;
|
use rt::local::Local;
|
||||||
@ -71,7 +71,8 @@ use rt::work_queue::WorkQueue;
|
|||||||
use rt::uv::uvio::UvEventLoop;
|
use rt::uv::uvio::UvEventLoop;
|
||||||
use unstable::atomics::{AtomicInt, SeqCst};
|
use unstable::atomics::{AtomicInt, SeqCst};
|
||||||
use unstable::sync::UnsafeArc;
|
use unstable::sync::UnsafeArc;
|
||||||
use vec::{OwnedVector, MutableVector};
|
use vec;
|
||||||
|
use vec::{OwnedVector, MutableVector, ImmutableVector};
|
||||||
|
|
||||||
/// The global (exchange) heap.
|
/// The global (exchange) heap.
|
||||||
pub mod global_heap;
|
pub mod global_heap;
|
||||||
@ -251,11 +252,7 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
|
|||||||
|
|
||||||
// Create a work queue for each scheduler, ntimes. Create an extra
|
// Create a work queue for each scheduler, ntimes. Create an extra
|
||||||
// for the main thread if that flag is set. We won't steal from it.
|
// for the main thread if that flag is set. We won't steal from it.
|
||||||
let mut work_queues = ~[];
|
let work_queues: ~[WorkQueue<~Task>] = vec::from_fn(nscheds, |_| WorkQueue::new());
|
||||||
for _ in range(0u, nscheds) {
|
|
||||||
let work_queue: WorkQueue<~Task> = WorkQueue::new();
|
|
||||||
work_queues.push(work_queue);
|
|
||||||
}
|
|
||||||
|
|
||||||
// The schedulers.
|
// The schedulers.
|
||||||
let mut scheds = ~[];
|
let mut scheds = ~[];
|
||||||
@ -263,13 +260,13 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
|
|||||||
// sent the Shutdown message to terminate the schedulers.
|
// sent the Shutdown message to terminate the schedulers.
|
||||||
let mut handles = ~[];
|
let mut handles = ~[];
|
||||||
|
|
||||||
for i in range(0u, nscheds) {
|
for work_queue in work_queues.iter() {
|
||||||
rtdebug!("inserting a regular scheduler");
|
rtdebug!("inserting a regular scheduler");
|
||||||
|
|
||||||
// Every scheduler is driven by an I/O event loop.
|
// Every scheduler is driven by an I/O event loop.
|
||||||
let loop_ = ~UvEventLoop::new();
|
let loop_ = ~UvEventLoop::new();
|
||||||
let mut sched = ~Scheduler::new(loop_,
|
let mut sched = ~Scheduler::new(loop_,
|
||||||
work_queues[i].clone(),
|
work_queue.clone(),
|
||||||
work_queues.clone(),
|
work_queues.clone(),
|
||||||
sleepers.clone());
|
sleepers.clone());
|
||||||
let handle = sched.make_handle();
|
let handle = sched.make_handle();
|
||||||
@ -358,9 +355,8 @@ fn run_(main: ~fn(), use_main_sched: bool) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run each remaining scheduler in a thread.
|
// Run each remaining scheduler in a thread.
|
||||||
while !scheds.is_empty() {
|
for sched in scheds.move_rev_iter() {
|
||||||
rtdebug!("creating regular schedulers");
|
rtdebug!("creating regular schedulers");
|
||||||
let sched = scheds.pop();
|
|
||||||
let sched_cell = Cell::new(sched);
|
let sched_cell = Cell::new(sched);
|
||||||
let thread = do Thread::start {
|
let thread = do Thread::start {
|
||||||
let mut sched = sched_cell.take();
|
let mut sched = sched_cell.take();
|
||||||
|
Loading…
Reference in New Issue
Block a user