Skip to content

Commit 7c6ab14

Browse files
committed
---
yaml --- r: 142583 b: refs/heads/try2 c: 5043ea2 h: refs/heads/master i: 142581: fba5925 142579: 428b586 142575: 9208e89 v: v3
1 parent 574589b commit 7c6ab14

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ed8c3594bc86dd366e729d02c34915c783e6ac81
8+
refs/heads/try2: 5043ea269da73e96fbadc7c443aec01f087dabe9
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libcore/rt/test.rs

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,20 @@
99
// except according to those terms.
1010

1111
use uint;
12-
use option::*;
12+
use option::{Option, Some, None};
1313
use cell::Cell;
14+
use clone::Clone;
15+
use container::Container;
16+
use vec::OwnedVector;
1417
use result::{Result, Ok, Err};
18+
use unstable::run_in_bare_thread;
1519
use super::io::net::ip::{IpAddr, Ipv4};
1620
use rt::task::Task;
1721
use rt::thread::Thread;
1822
use rt::local::Local;
19-
use rt::sched::Scheduler;
23+
use rt::sched::{Scheduler, Coroutine};
24+
use rt::sleeper_list::SleeperList;
25+
use rt::work_queue::WorkQueue;
2026

2127
pub fn new_test_uv_sched() -> Scheduler {
2228
use rt::uv::uvio::UvEventLoop;
@@ -46,6 +52,59 @@ pub fn run_in_newsched_task(f: ~fn()) {
4652
}
4753
}
4854

55+
/// Create more than one scheduler and run a function in a task
56+
/// in one of the schedulers. The schedulers will stay alive
57+
/// until the function `f` returns.
58+
pub fn run_in_mt_newsched_task(f: ~fn()) {
59+
use rt::uv::uvio::UvEventLoop;
60+
61+
let f_cell = Cell(f);
62+
63+
do run_in_bare_thread {
64+
static N: uint = 2;
65+
66+
let sleepers = SleeperList::new();
67+
let work_queue = WorkQueue::new();
68+
69+
let mut handles = ~[];
70+
let mut scheds = ~[];
71+
72+
for uint::range(0, N) |i| {
73+
let loop_ = ~UvEventLoop::new();
74+
let mut sched = ~Scheduler::new(loop_, work_queue.clone(), sleepers.clone());
75+
let handle = sched.make_handle();
76+
handles.push(handle);
77+
scheds.push(sched);
78+
}
79+
80+
let f_cell = Cell(f_cell.take());
81+
let handles = handles; // Freeze
82+
let main_task = ~do Coroutine::new(&mut scheds[0].stack_pool) {
83+
f_cell.take()();
84+
// Hold on to handles until the function exits. This keeps the schedulers alive.
85+
let _captured_handles = &handles;
86+
};
87+
88+
scheds[0].enqueue_task(main_task);
89+
90+
let mut threads = ~[];
91+
92+
while !scheds.is_empty() {
93+
let sched = scheds.pop();
94+
let sched_cell = Cell(sched);
95+
let thread = do Thread::start {
96+
let mut sched = sched_cell.take();
97+
sched.run();
98+
};
99+
100+
threads.push(thread);
101+
}
102+
103+
// Wait for schedulers
104+
let _threads = threads;
105+
}
106+
}
107+
49108
/// Test tasks will abort on failure instead of unwinding
50109
pub fn spawntask(f: ~fn()) {
51110
use super::sched::*;

0 commit comments

Comments
 (0)