Skip to content

Commit 9a6ad57

Browse files
committed
---
yaml --- r: 63461 b: refs/heads/snap-stage3 c: 5b2dc52 h: refs/heads/master i: 63459: f1ce931 v: v3
1 parent aefc548 commit 9a6ad57

File tree

2 files changed

+77
-17
lines changed

2 files changed

+77
-17
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: b5fbec9c1e519c7e6fa45e2157f6e746ef3f6849
4+
refs/heads/snap-stage3: 5b2dc520340103491088616ba4f58095948f5821
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/rt/mod.rs

Lines changed: 76 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,21 @@ Several modules in `core` are clients of `rt`:
6060
#[deny(unused_variable)];
6161

6262
use cell::Cell;
63+
use clone::Clone;
64+
use container::Container;
65+
use from_str::FromStr;
66+
use iterator::IteratorUtil;
67+
use option::{Some, None};
68+
use os;
6369
use ptr::RawPtr;
70+
use uint;
71+
use rt::sched::{Scheduler, Coroutine, Shutdown};
72+
use rt::sleeper_list::SleeperList;
73+
use rt::task::Task;
74+
use rt::thread::Thread;
75+
use rt::work_queue::WorkQueue;
76+
use rt::uv::uvio::UvEventLoop;
77+
use vec::{OwnedVector, MutableVector};
6478

6579
/// The global (exchange) heap.
6680
pub mod global_heap;
@@ -159,23 +173,8 @@ pub mod util;
159173
/// The return value is used as the process return code. 0 on success, 101 on error.
160174
pub fn start(_argc: int, _argv: **u8, crate_map: *u8, main: ~fn()) -> int {
161175

162-
use self::sched::{Scheduler, Coroutine};
163-
use self::work_queue::WorkQueue;
164-
use self::uv::uvio::UvEventLoop;
165-
use self::sleeper_list::SleeperList;
166-
167176
init(crate_map);
168-
169-
let loop_ = ~UvEventLoop::new();
170-
let work_queue = WorkQueue::new();
171-
let sleepers = SleeperList::new();
172-
let mut sched = ~Scheduler::new(loop_, work_queue, sleepers);
173-
sched.no_sleep = true;
174-
let main_task = ~Coroutine::new_root(&mut sched.stack_pool, main);
175-
176-
sched.enqueue_task(main_task);
177-
sched.run();
178-
177+
run(main);
179178
cleanup();
180179

181180
return 0;
@@ -191,6 +190,67 @@ pub fn cleanup() {
191190
global_heap::cleanup();
192191
}
193192

193+
pub fn run(main: ~fn()) {
194+
let nthreads = match os::getenv("RUST_THREADS") {
195+
Some(nstr) => FromStr::from_str(nstr).get(),
196+
None => unsafe {
197+
// Using more threads than cores in test code
198+
// to force the OS to preempt them frequently.
199+
// Assuming that this help stress test concurrent types.
200+
util::num_cpus() * 2
201+
}
202+
};
203+
204+
let sleepers = SleeperList::new();
205+
let work_queue = WorkQueue::new();
206+
207+
let mut handles = ~[];
208+
let mut scheds = ~[];
209+
210+
for uint::range(0, nthreads) |_| {
211+
let loop_ = ~UvEventLoop::new();
212+
let mut sched = ~Scheduler::new(loop_, work_queue.clone(), sleepers.clone());
213+
let handle = sched.make_handle();
214+
215+
handles.push(handle);
216+
scheds.push(sched);
217+
}
218+
219+
let main_cell = Cell::new(main);
220+
let handles = Cell::new(handles);
221+
let mut new_task = ~Task::new_root();
222+
let on_exit: ~fn(bool) = |exit_status| {
223+
224+
let mut handles = handles.take();
225+
// Tell schedulers to exit
226+
for handles.mut_iter().advance |handle| {
227+
handle.send(Shutdown);
228+
}
229+
230+
rtassert!(exit_status);
231+
};
232+
new_task.on_exit = Some(on_exit);
233+
let main_task = ~Coroutine::with_task(&mut scheds[0].stack_pool,
234+
new_task, main_cell.take());
235+
scheds[0].enqueue_task(main_task);
236+
237+
let mut threads = ~[];
238+
239+
while !scheds.is_empty() {
240+
let sched = scheds.pop();
241+
let sched_cell = Cell::new(sched);
242+
let thread = do Thread::start {
243+
let sched = sched_cell.take();
244+
sched.run();
245+
};
246+
247+
threads.push(thread);
248+
}
249+
250+
// Wait for schedulers
251+
let _threads = threads;
252+
}
253+
194254
/// Possible contexts in which Rust code may be executing.
195255
/// Different runtime services are available depending on context.
196256
/// Mostly used for determining if we're using the new scheduler

0 commit comments

Comments
 (0)