Skip to content

Commit 71be94b

Browse files
committed
---
yaml --- r: 148973 b: refs/heads/try2 c: 29e500d h: refs/heads/master i: 148971: 49ece01 v: v3
1 parent b8011d4 commit 71be94b

File tree

335 files changed

+3060
-174
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

335 files changed

+3060
-174
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: ec2f047aa9a09926b9c4192c447f44dda484ee6d
8+
refs/heads/try2: 29e500db8a98a86b3de56688cd9fa6571a840470
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/mk/tests.mk

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,6 @@ ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
242242
tidy:
243243
@$(call E, check: formatting)
244244
$(Q)find $(S)src -name '*.r[sc]' \
245-
| grep '^$(S)src/test' -v \
246245
| grep '^$(S)src/libuv' -v \
247246
| grep '^$(S)src/llvm' -v \
248247
| grep '^$(S)src/gyp' -v \

branches/try2/src/doc/guide-runtime.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,9 +236,7 @@ extern mod green;
236236
237237
#[start]
238238
fn start(argc: int, argv: **u8) -> int {
239-
green::start(argc, argv, proc() {
240-
main();
241-
})
239+
green::start(argc, argv, main)
242240
}
243241
244242
fn main() {}

branches/try2/src/etc/tidy.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414

1515
err=0
1616
cols=100
17+
cr_flag="xfail-tidy-cr"
18+
tab_flag="xfail-tidy-tab"
19+
linelength_flag="xfail-tidy-linelength"
1720

1821
# Be careful to support Python 2.4, 2.6, and 3.x here!
1922
config_proc=subprocess.Popen([ "git", "config", "core.autocrlf" ],
@@ -46,12 +49,22 @@ def do_license_check(name, contents):
4649

4750
current_name = ""
4851
current_contents = ""
52+
check_tab = True
53+
check_cr = True
54+
check_linelength = True
55+
4956

5057
try:
5158
for line in fileinput.input(file_names,
5259
openhook=fileinput.hook_encoded("utf-8")):
5360

5461
if fileinput.filename().find("tidy.py") == -1:
62+
if line.find(cr_flag) != -1:
63+
check_cr = False
64+
if line.find(tab_flag) != -1:
65+
check_tab = False
66+
if line.find(linelength_flag) != -1:
67+
check_linelength = False
5568
if line.find("// XXX") != -1:
5669
report_err("XXX is no longer necessary, use FIXME")
5770
if line.find("TODO") != -1:
@@ -72,16 +85,16 @@ def do_license_check(name, contents):
7285
if "SNAP" in line:
7386
report_warn("unmatched SNAP line: " + line)
7487

75-
if (line.find('\t') != -1 and
88+
if check_tab and (line.find('\t') != -1 and
7689
fileinput.filename().find("Makefile") == -1):
7790
report_err("tab character")
78-
if not autocrlf and line.find('\r') != -1:
91+
if check_cr and not autocrlf and line.find('\r') != -1:
7992
report_err("CR character")
8093
if line.endswith(" \n") or line.endswith("\t\n"):
8194
report_err("trailing whitespace")
8295
line_len = len(line)-2 if autocrlf else len(line)-1
8396

84-
if line_len > cols:
97+
if check_linelength and line_len > cols:
8598
report_err("line longer than %d chars" % cols)
8699

87100
if fileinput.isfirstline() and current_name != "":
@@ -90,6 +103,9 @@ def do_license_check(name, contents):
90103
if fileinput.isfirstline():
91104
current_name = fileinput.filename()
92105
current_contents = ""
106+
check_cr = True
107+
check_tab = True
108+
check_linelength = True
93109

94110
current_contents += line
95111

branches/try2/src/libgreen/lib.rs

Lines changed: 149 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,156 @@
1212
//!
1313
//! This library provides M:N threading for rust programs. Internally this has
1414
//! the implementation of a green scheduler along with context switching and a
15-
//! stack-allocation strategy.
15+
//! stack-allocation strategy. This can be optionally linked in to rust
16+
//! programs in order to provide M:N functionality inside of 1:1 programs.
1617
//!
17-
//! This can be optionally linked in to rust programs in order to provide M:N
18-
//! functionality inside of 1:1 programs.
18+
//! # Architecture
19+
//!
20+
//! An M:N scheduling library implies that there are N OS thread upon which M
21+
//! "green threads" are multiplexed. In other words, a set of green threads are
22+
//! all run inside a pool of OS threads.
23+
//!
24+
//! With this design, you can achieve _concurrency_ by spawning many green
25+
//! threads, and you can achieve _parallelism_ by running the green threads
26+
//! simultaneously on multiple OS threads. Each OS thread is a candidate for
27+
//! being scheduled on a different core (the source of parallelism), and then
28+
//! all of the green threads cooperatively schedule amongst one another (the
29+
//! source of concurrency).
30+
//!
31+
//! ## Schedulers
32+
//!
33+
//! In order to coordinate among green threads, each OS thread is primarily
34+
//! running something which we call a Scheduler. Whenever a reference to a
35+
//! Scheduler is made, it is synonymous to referencing one OS thread. Each
36+
//! scheduler is bound to one and exactly one OS thread, and the thread that it
37+
//! is bound to never changes.
38+
//!
39+
//! Each scheduler is connected to a pool of other schedulers (a `SchedPool`)
40+
//! which is the thread pool term from above. A pool of schedulers all share the
41+
//! work that they create. Furthermore, whenever a green thread is created (also
42+
//! synonymously referred to as a green task), it is associated with a
43+
//! `SchedPool` forevermore. A green thread cannot leave its scheduler pool.
44+
//!
45+
//! Schedulers can have at most one green thread running on them at a time. When
46+
//! a scheduler is asleep on its event loop, there are no green tasks running on
47+
//! the OS thread or the scheduler. The term "context switch" is used for when
48+
//! the running green thread is swapped out, but this simply changes the one
49+
//! green thread which is running on the scheduler.
50+
//!
51+
//! ## Green Threads
52+
//!
53+
//! A green thread can largely be summarized by a stack and a register context.
54+
//! Whenever a green thread is spawned, it allocates a stack, and then prepares
55+
//! a register context for execution. The green task may be executed across
56+
//! multiple OS threads, but it will always use the same stack and it will carry
57+
//! its register context across OS threads.
58+
//!
59+
//! Each green thread is cooperatively scheduled with other green threads.
60+
//! Primarily, this means that there is no pre-emption of a green thread. The
61+
//! major consequence of this design is that a green thread stuck in an infinite
62+
//! loop will prevent all other green threads from running on that particular
63+
//! scheduler.
64+
//!
65+
//! Scheduling events for green threads occur on communication and I/O
66+
//! boundaries. For example, if a green task blocks waiting for a message on a
67+
//! channel some other green thread can now run on the scheduler. This also has
68+
//! the consequence that until a green thread performs any form of scheduling
69+
//! event, it will be running on the same OS thread (unconditionally).
70+
//!
71+
//! ## Work Stealing
72+
//!
73+
//! With a pool of schedulers, a new green task has a number of options when
74+
//! deciding where to run initially. The current implementation uses a concept
75+
//! called work stealing in order to spread out work among schedulers.
76+
//!
77+
//! In a work-stealing model, each scheduler maintains a local queue of tasks to
78+
//! run, and this queue is stolen from by other schedulers. Implementation-wise,
79+
//! work stealing has some hairy parts, but from a user-perspective, work
80+
//! stealing simply implies what with M green threads and N schedulers where
81+
//! M > N it is very likely that all schedulers will be busy executing work.
82+
//!
83+
//! # Considerations when using libgreen
84+
//!
85+
//! An M:N runtime has both pros and cons, and there is no one answer as to
86+
//! whether M:N or 1:1 is appropriate to use. As always, there are many
87+
//! advantages and disadvantages between the two. Regardless of the workload,
88+
//! however, there are some aspects of using green thread which you should be
89+
//! aware of:
90+
//!
91+
//! * The largest concern when using libgreen is interoperating with native
92+
//! code. Care should be taken when calling native code that will block the OS
93+
//! thread as it will prevent further green tasks from being scheduled on the
94+
//! OS thread.
95+
//!
96+
//! * Native code using thread-local-storage should be approached
97+
//! with care. Green threads may migrate among OS threads at any time, so
98+
//! native libraries using thread-local state may not always work.
99+
//!
100+
//! * Native synchronization primitives (e.g. pthread mutexes) will also not
101+
//! work for green threads. The reason for this is because native primitives
102+
//! often operate on a _os thread_ granularity whereas green threads are
103+
//! operating on a more granular unit of work.
104+
//!
105+
//! * A green threading runtime is not fork-safe. If the process forks(), it
106+
//! cannot expect to make reasonable progress by continuing to use green
107+
//! threads.
108+
//!
109+
//! Note that these concerns do not mean that operating with native code is a
110+
//! lost cause. These are simply just concerns which should be considered when
111+
//! invoking native code.
112+
//!
113+
//! # Starting with libgreen
114+
//!
115+
//! ```rust
116+
//! extern mod green;
117+
//!
118+
//! #[start]
119+
//! fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, main) }
120+
//!
121+
//! fn main() {
122+
//! // this code is running in a pool of schedulers
123+
//! }
124+
//! ```
125+
//!
126+
//! # Using a scheduler pool
127+
//!
128+
//! ```rust
129+
//! use std::task::TaskOpts;
130+
//! use green::{SchedPool, PoolConfig};
131+
//! use green::sched::{PinnedTask, TaskFromFriend};
132+
//!
133+
//! let config = PoolConfig::new();
134+
//! let mut pool = SchedPool::new(config);
135+
//!
136+
//! // Spawn tasks into the pool of schedulers
137+
//! pool.spawn(TaskOpts::new(), proc() {
138+
//! // this code is running inside the pool of schedulers
139+
//!
140+
//! spawn(proc() {
141+
//! // this code is also running inside the same scheduler pool
142+
//! });
143+
//! });
144+
//!
145+
//! // Dynamically add a new scheduler to the scheduler pool. This adds another
146+
//! // OS thread that green threads can be multiplexed on to.
147+
//! let mut handle = pool.spawn_sched();
148+
//!
149+
//! // Pin a task to the spawned scheduler
150+
//! let task = pool.task(TaskOpts::new(), proc() { /* ... */ });
151+
//! handle.send(PinnedTask(task));
152+
//!
153+
//! // Schedule a task on this new scheduler
154+
//! let task = pool.task(TaskOpts::new(), proc() { /* ... */ });
155+
//! handle.send(TaskFromFriend(task));
156+
//!
157+
//! // Handles keep schedulers alive, so be sure to drop all handles before
158+
//! // destroying the sched pool
159+
//! drop(handle);
160+
//!
161+
//! // Required to shut down this scheduler pool.
162+
//! // The task will fail if `shutdown` is not called.
163+
//! pool.shutdown();
164+
//! ```
19165
20166
#[crate_id = "green#0.10-pre"];
21167
#[license = "MIT/ASL2"];

branches/try2/src/libnative/lib.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,38 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
//! The native runtime crate
11+
//! The native I/O and threading crate
1212
//!
1313
//! This crate contains an implementation of 1:1 scheduling for a "native"
1414
//! runtime. In addition, all I/O provided by this crate is the thread blocking
1515
//! version of I/O.
16+
//!
17+
//! # Starting with libnative
18+
//!
19+
//! ```rust
20+
//! extern mod native;
21+
//!
22+
//! #[start]
23+
//! fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }
24+
//!
25+
//! fn main() {
26+
//! // this code is running on the main OS thread
27+
//! }
28+
//! ```
29+
//!
30+
//! # Force spawning a native task
31+
//!
32+
//! ```rust
33+
//! extern mod native;
34+
//!
35+
//! fn main() {
36+
//! // We're not sure whether this main function is run in 1:1 or M:N mode.
37+
//!
38+
//! native::task::spawn(proc() {
39+
//! // this code is guaranteed to be run on a native thread
40+
//! });
41+
//! }
42+
//! ```
1643
1744
#[crate_id = "native#0.10-pre"];
1845
#[license = "MIT/ASL2"];

branches/try2/src/libstd/ascii.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
//! Operations on ASCII strings and characters
1212
13-
use to_str::{ToStr,IntoStr};
13+
use to_str::{ToStr, IntoStr};
1414
use str;
1515
use str::Str;
1616
use str::StrSlice;

branches/try2/src/libstd/cell.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010

1111
//! Types dealing with dynamic mutability
1212
13-
use prelude::*;
13+
use clone::{Clone, DeepClone};
14+
use cmp::Eq;
15+
use ops::Drop;
16+
use option::{None, Option, Some};
1417
use cast;
1518
use kinds::{marker, Pod};
1619

branches/try2/src/libstd/local_data.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ local_data::get(key_vector, |opt| assert_eq!(*opt.unwrap(), ~[4]));
4141
// magic.
4242

4343
use cast;
44-
use prelude::*;
44+
use option::{None, Option, Some};
45+
use vec::{ImmutableVector, MutableVector, OwnedVector};
46+
use iter::{Iterator};
4547
use rt::task::{Task, LocalStorage};
4648
use util::replace;
4749

branches/try2/src/libstd/os.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,31 @@
2828

2929
#[allow(missing_doc)];
3030

31-
use clone::Clone;
32-
use container::Container;
3331
#[cfg(target_os = "macos")]
32+
#[cfg(windows)]
3433
use iter::range;
34+
35+
use clone::Clone;
36+
use container::Container;
3537
use libc;
3638
use libc::{c_char, c_void, c_int};
37-
use option::{Some, None};
39+
use option::{Some, None, Option};
3840
use os;
39-
use prelude::*;
41+
use ops::Drop;
42+
use result::{Err, Ok, Result};
4043
use ptr;
4144
use str;
45+
use str::{Str, StrSlice};
4246
use fmt;
4347
use unstable::finally::Finally;
4448
use sync::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
49+
use path::{Path, GenericPath};
50+
use iter::Iterator;
51+
use vec::{Vector, CloneableVector, ImmutableVector, MutableVector, OwnedVector};
52+
use ptr::RawPtr;
53+
54+
#[cfg(unix)]
55+
use c_str::ToCStr;
4556

4657
/// Delegates to the libc close() function, returning the same return value.
4758
pub fn close(fd: int) -> int {
@@ -396,6 +407,8 @@ pub fn self_exe_name() -> Option<Path> {
396407

397408
#[cfg(windows)]
398409
fn load_self() -> Option<~[u8]> {
410+
use str::OwnedStr;
411+
399412
unsafe {
400413
use os::win32::fill_utf16_buf_and_decode;
401414
fill_utf16_buf_and_decode(|buf, sz| {
@@ -967,6 +980,7 @@ impl MemoryMap {
967980
/// `ErrZeroLength`.
968981
pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError> {
969982
use libc::off_t;
983+
use cmp::Equiv;
970984

971985
if min_len == 0 {
972986
return Err(ErrZeroLength)

branches/try2/src/libstd/reference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Utilities for references
1212
1313
#[cfg(not(test))]
14-
use prelude::*;
14+
use cmp::{Eq, Ord, Ordering, TotalEq, TotalOrd};
1515

1616
// Equality for region pointers
1717
#[cfg(not(test))]

branches/try2/src/libstd/run.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@ use io::process;
2020
use io;
2121
use libc::{pid_t, c_int};
2222
use libc;
23-
use prelude::*;
23+
use option::{None, Option, Some};
24+
use task::spawn;
25+
use path::{Path, GenericPath};
26+
use result::Ok;
27+
use str::Str;
28+
use vec::Vector;
29+
use clone::Clone;
2430

2531
/**
2632
* A value representing a child process.

0 commit comments

Comments
 (0)