Skip to content

Commit 8c6413b

Browse files
committed
---
yaml --- r: 42446 b: refs/heads/try c: 4688033 h: refs/heads/master v: v3
1 parent 85a8091 commit 8c6413b

File tree

11 files changed

+98
-319
lines changed

11 files changed

+98
-319
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: 19dfec2aaf746535de1521f68421f9980dbf25de
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 2f46b763da2c098913884f101b6d71d69af41b49
5-
refs/heads/try: ac435af73a0009daf22164ee2f081a7c98ca844c
5+
refs/heads/try: 46880337f497229e6c0ec0bf11d4af0e07c105e8
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: a810c03263670238bccd64cabb12a23a46e3a278

branches/try/src/libcore/private.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ use task;
2828
use task::{TaskBuilder, atomically};
2929
use uint;
3030

31-
#[path = "private/at_exit.rs"]
32-
pub mod at_exit;
33-
3431
extern mod rustrt {
3532
#[legacy_exports];
3633
unsafe fn rust_task_weaken(ch: rust_port_id);

branches/try/src/libcore/private/at_exit.rs

Lines changed: 0 additions & 86 deletions
This file was deleted.

branches/try/src/libcore/task/mod.rs

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use prelude::*;
5252
use ptr;
5353
use result;
5454
use task::local_data_priv::{local_get, local_set};
55-
use task::rt::{task_id, sched_id, rust_task};
55+
use task::rt::{task_id, rust_task};
5656
use task;
5757
use util;
5858
use util::replace;
@@ -62,12 +62,6 @@ pub mod local_data;
6262
pub mod rt;
6363
pub mod spawn;
6464

65-
/// A handle to a scheduler
66-
#[deriving_eq]
67-
pub enum Scheduler {
68-
SchedulerHandle(sched_id)
69-
}
70-
7165
/// A handle to a task
7266
#[deriving_eq]
7367
pub enum Task {
@@ -101,21 +95,7 @@ impl TaskResult : Eq {
10195
}
10296

10397
/// Scheduler modes
104-
#[deriving_eq]
10598
pub enum SchedMode {
106-
/// Run task on the default scheduler
107-
DefaultScheduler,
108-
/// Run task on the current scheduler
109-
CurrentScheduler,
110-
/// Run task on a specific scheduler
111-
ExistingScheduler(Scheduler),
112-
/**
113-
* Tasks are scheduled on the main OS thread
114-
*
115-
* The main OS thread is the thread used to launch the runtime which,
116-
* in most cases, is the process's initial thread as created by the OS.
117-
*/
118-
PlatformThread,
11999
/// All tasks run in the same OS thread
120100
SingleThreaded,
121101
/// Tasks are distributed among available CPUs
@@ -124,6 +104,53 @@ pub enum SchedMode {
124104
ThreadPerTask,
125105
/// Tasks are distributed among a fixed number of OS threads
126106
ManualThreads(uint),
107+
/**
108+
* Tasks are scheduled on the main OS thread
109+
*
110+
* The main OS thread is the thread used to launch the runtime which,
111+
* in most cases, is the process's initial thread as created by the OS.
112+
*/
113+
PlatformThread
114+
}
115+
116+
impl SchedMode : cmp::Eq {
117+
pure fn eq(&self, other: &SchedMode) -> bool {
118+
match (*self) {
119+
SingleThreaded => {
120+
match (*other) {
121+
SingleThreaded => true,
122+
_ => false
123+
}
124+
}
125+
ThreadPerCore => {
126+
match (*other) {
127+
ThreadPerCore => true,
128+
_ => false
129+
}
130+
}
131+
ThreadPerTask => {
132+
match (*other) {
133+
ThreadPerTask => true,
134+
_ => false
135+
}
136+
}
137+
ManualThreads(e0a) => {
138+
match (*other) {
139+
ManualThreads(e0b) => e0a == e0b,
140+
_ => false
141+
}
142+
}
143+
PlatformThread => {
144+
match (*other) {
145+
PlatformThread => true,
146+
_ => false
147+
}
148+
}
149+
}
150+
}
151+
pure fn ne(&self, other: &SchedMode) -> bool {
152+
!(*self).eq(other)
153+
}
127154
}
128155

129156
/**
@@ -177,7 +204,7 @@ pub type TaskOpts = {
177204
linked: bool,
178205
supervised: bool,
179206
mut notify_chan: Option<Chan<TaskResult>>,
180-
sched: SchedOpts,
207+
sched: Option<SchedOpts>,
181208
};
182209

183210
/**
@@ -343,7 +370,7 @@ impl TaskBuilder {
343370
linked: self.opts.linked,
344371
supervised: self.opts.supervised,
345372
mut notify_chan: move notify_chan,
346-
sched: { mode: mode, foreign_stack_size: None}
373+
sched: Some({ mode: mode, foreign_stack_size: None})
347374
},
348375
can_not_copy: None,
349376
.. self.consume()
@@ -459,10 +486,7 @@ pub fn default_task_opts() -> TaskOpts {
459486
linked: true,
460487
supervised: false,
461488
mut notify_chan: None,
462-
sched: {
463-
mode: DefaultScheduler,
464-
foreign_stack_size: None
465-
}
489+
sched: None
466490
}
467491
}
468492
@@ -515,9 +539,10 @@ pub fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
515539
516540
pub fn spawn_sched(mode: SchedMode, f: fn~()) {
517541
/*!
518-
* Creates a new task on a new or existing scheduler
519-
520-
* When there are no more tasks to execute the
542+
* Creates a new scheduler and executes a task on it
543+
*
544+
* Tasks subsequently spawned by that task will also execute on
545+
* the new scheduler. When there are no more tasks to execute the
521546
* scheduler terminates.
522547
*
523548
* # Failure
@@ -565,10 +590,6 @@ pub fn get_task() -> Task {
565590
TaskHandle(rt::get_task_id())
566591
}
567592

568-
pub fn get_scheduler() -> Scheduler {
569-
SchedulerHandle(rt::rust_get_sched_id())
570-
}
571-
572593
/**
573594
* Temporarily make the task unkillable
574595
*
@@ -906,19 +927,16 @@ fn test_spawn_sched() {
906927
}
907928

908929
#[test]
909-
fn test_spawn_sched_childs_on_default_sched() {
930+
fn test_spawn_sched_childs_on_same_sched() {
910931
let po = oldcomm::Port();
911932
let ch = oldcomm::Chan(&po);
912933

913-
// Assuming tests run on the default scheduler
914-
let default_id = rt::rust_get_sched_id();
915-
916934
do spawn_sched(SingleThreaded) {
917935
let parent_sched_id = rt::rust_get_sched_id();
918936
do spawn {
919937
let child_sched_id = rt::rust_get_sched_id();
920-
assert parent_sched_id != child_sched_id;
921-
assert child_sched_id == default_id;
938+
// This should be on the same scheduler
939+
assert parent_sched_id == child_sched_id;
922940
oldcomm::send(ch, ());
923941
};
924942
};
@@ -1188,7 +1206,7 @@ fn test_spawn_thread_on_demand() {
11881206

11891207
let (port2, chan2) = pipes::stream();
11901208

1191-
do spawn_sched(CurrentScheduler) |move chan2| {
1209+
do spawn() |move chan2| {
11921210
chan2.send(());
11931211
}
11941212

branches/try/src/libcore/task/spawn.rs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ use task::rt::rust_closure;
8888
use task::rt;
8989
use task::{Failure, ManualThreads, PlatformThread, SchedOpts, SingleThreaded};
9090
use task::{Success, TaskOpts, TaskResult, ThreadPerCore, ThreadPerTask};
91-
use task::{ExistingScheduler, SchedulerHandle};
9291
use task::{default_task_opts, unkillable};
9392
use uint;
9493
use util;
@@ -526,9 +525,9 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
526525
// Agh. Get move-mode items into the closure. FIXME (#2829)
527526
let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
528527
// Create child task.
529-
let new_task = match opts.sched.mode {
530-
DefaultScheduler => rt::new_task(),
531-
_ => new_task_in_sched(opts.sched)
528+
let new_task = match opts.sched {
529+
None => rt::new_task(),
530+
Some(sched_opts) => new_task_in_new_sched(sched_opts)
532531
};
533532
assert !new_task.is_null();
534533
// Getting killed after here would leak the task.
@@ -632,16 +631,12 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
632631
}
633632
}
634633

635-
fn new_task_in_sched(opts: SchedOpts) -> *rust_task {
634+
fn new_task_in_new_sched(opts: SchedOpts) -> *rust_task {
636635
if opts.foreign_stack_size != None {
637636
fail ~"foreign_stack_size scheduler option unimplemented";
638637
}
639638

640639
let num_threads = match opts.mode {
641-
DefaultScheduler
642-
| CurrentScheduler
643-
| ExistingScheduler(*)
644-
| PlatformThread => 0u, /* Won't be used */
645640
SingleThreaded => 1u,
646641
ThreadPerCore => rt::rust_num_threads(),
647642
ThreadPerTask => {
@@ -653,13 +648,13 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
653648
}
654649
threads
655650
}
651+
PlatformThread => 0u /* Won't be used */
656652
};
657653

658-
let sched_id = match opts.mode {
659-
CurrentScheduler => rt::rust_get_sched_id(),
660-
ExistingScheduler(SchedulerHandle(id)) => id,
661-
PlatformThread => rt::rust_osmain_sched_id(),
662-
_ => rt::rust_new_sched(num_threads)
654+
let sched_id = if opts.mode != PlatformThread {
655+
rt::rust_new_sched(num_threads)
656+
} else {
657+
rt::rust_osmain_sched_id()
663658
};
664659
rt::rust_new_task_in_sched(sched_id)
665660
}

branches/try/src/libstd/tempfile.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -19,26 +19,18 @@ use core::str;
1919

2020
pub fn mkdtemp(tmpdir: &Path, suffix: &str) -> Option<Path> {
2121
let r = rand::Rng();
22-
let mut i = 0u;
23-
while (i < 1000u) {
24-
let p = tmpdir.push(r.gen_str(16u) +
25-
str::from_slice(suffix));
26-
if os::make_dir(&p, 0x1c0i32) { // FIXME: u+rwx (#2349)
22+
for 1000.times {
23+
let p = tmpdir.push(r.gen_str(16) + suffix);
24+
if os::make_dir(&p, 0x1c0) { // 700
2725
return Some(p);
2826
}
29-
i += 1u;
3027
}
31-
return None;
28+
None
3229
}
3330

3431
#[test]
3532
fn test_mkdtemp() {
36-
let r = mkdtemp(&Path("."), "foobar");
37-
match r {
38-
Some(ref p) => {
39-
os::remove_dir(p);
40-
assert(str::ends_with(p.to_str(), "foobar"));
41-
}
42-
_ => assert(false)
43-
}
33+
let p = mkdtemp(&Path("."), "foobar").unwrap();
34+
os::remove_dir(&p);
35+
assert str::ends_with(p.to_str(), "foobar");
4436
}

0 commit comments

Comments
 (0)