Skip to content

Commit 3ee479f

Browse files
committed
auto merge of #6577 : brson/rust/io-upstream, r=pcwalton
r? This is all of my scheduler work on #4419 from the last 3 weeks or so. I've had a few failed pull requests so far but I think the problems are ironed out. * TCP * The beginnings of runtime embedding APIs * Porting various corners of core to be compatible with both schedulers * libuv timer bindings * Further refinement of I/O error handling, including a new, incomplete, `read_error` condition * Incomplete refactoring to make tasks work without coroutines and user-space scheduling * Implementations of Reader/Writer extension methods * Implementations of the most important part of core::comm I'm particularly happy with how easy the [comm types on top of the scheduler](https://github.com/brson/rust/blob/io-upstream/src/libcore/rt/comm.rs). Note that these implementations do not use pipes. If anything here needs careful review though it's this code. This branch passes 95% of the run-pass tests (with `TESTARGS=--newrt`) In the next week I'll probably spend some time adding preliminary multithreading and seeing how close we are to removing the old runtime.
2 parents 24c2be3 + 8daa5ec commit 3ee479f

Some content is hidden

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

54 files changed

+4138
-1413
lines changed

src/libcore/comm.rs

Lines changed: 436 additions & 245 deletions
Large diffs are not rendered by default.

src/libcore/core.rc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,11 @@ mod unicode;
205205
#[path = "num/cmath.rs"]
206206
mod cmath;
207207
mod stackwalk;
208+
209+
// XXX: This shouldn't be pub, and it should be reexported under 'unstable'
210+
// but name resolution doesn't work without it being pub.
208211
#[path = "rt/mod.rs"]
209-
mod rt;
212+
pub mod rt;
210213

211214
// A curious inner-module that's not exported that contains the binding
212215
// 'core' so that macro-expanded references to core::error and such

src/libcore/logging.rs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010

1111
//! Logging
1212
13-
pub mod rustrt {
14-
use libc;
15-
16-
pub extern {
17-
unsafe fn rust_log_console_on();
18-
unsafe fn rust_log_console_off();
19-
unsafe fn rust_log_str(level: u32,
20-
string: *libc::c_char,
21-
size: libc::size_t);
22-
}
23-
}
13+
use option::*;
14+
use either::*;
15+
use rt;
16+
use rt::logging::{Logger, StdErrLogger};
17+
use io;
18+
use libc;
19+
use repr;
20+
use vec;
21+
use cast;
22+
use str;
2423

2524
/// Turns on logging to stdout globally
2625
pub fn console_on() {
@@ -55,8 +54,46 @@ pub fn log_type<T>(level: u32, object: &T) {
5554
let bytes = do io::with_bytes_writer |writer| {
5655
repr::write_repr(writer, object);
5756
};
57+
58+
match rt::context() {
59+
rt::OldTaskContext => {
60+
unsafe {
61+
let len = bytes.len() as libc::size_t;
62+
rustrt::rust_log_str(level, cast::transmute(vec::raw::to_ptr(bytes)), len);
63+
}
64+
}
65+
_ => {
66+
// XXX: Bad allocation
67+
let msg = str::from_bytes(bytes);
68+
newsched_log_str(msg);
69+
}
70+
}
71+
}
72+
73+
fn newsched_log_str(msg: ~str) {
5874
unsafe {
59-
let len = bytes.len() as libc::size_t;
60-
rustrt::rust_log_str(level, transmute(vec::raw::to_ptr(bytes)), len);
75+
match rt::local_services::unsafe_try_borrow_local_services() {
76+
Some(local) => {
77+
// Use the available logger
78+
(*local).logger.log(Left(msg));
79+
}
80+
None => {
81+
// There is no logger anywhere, just write to stderr
82+
let mut logger = StdErrLogger;
83+
logger.log(Left(msg));
84+
}
85+
}
86+
}
87+
}
88+
89+
pub mod rustrt {
90+
use libc;
91+
92+
pub extern {
93+
unsafe fn rust_log_console_on();
94+
unsafe fn rust_log_console_off();
95+
unsafe fn rust_log_str(level: u32,
96+
string: *libc::c_char,
97+
size: libc::size_t);
6198
}
6299
}

src/libcore/macros.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,24 @@ macro_rules! rtdebug (
3030
($( $arg:expr),+) => ( $(let _ = $arg)*; )
3131
)
3232

33+
macro_rules! rtassert (
34+
( $arg:expr ) => ( {
35+
if !$arg {
36+
abort!("assertion failed: %s", stringify!($arg));
37+
}
38+
} )
39+
)
40+
3341
macro_rules! abort(
3442
($( $msg:expr),+) => ( {
3543
rtdebug!($($msg),+);
3644

37-
unsafe { ::libc::abort(); }
45+
do_abort();
46+
47+
// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
48+
// which causes spurious 'unnecessary unsafe block' warnings.
49+
fn do_abort() -> ! {
50+
unsafe { ::libc::abort(); }
51+
}
3852
} )
3953
)

src/libcore/os.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,23 +147,25 @@ pub mod win32 {
147147

148148
/*
149149
Accessing environment variables is not generally threadsafe.
150-
This uses a per-runtime lock to serialize access.
151-
FIXME #4726: It would probably be appropriate to make this a real global
150+
Serialize access through a global lock.
152151
*/
153152
fn with_env_lock<T>(f: &fn() -> T) -> T {
154-
use unstable::global::global_data_clone_create;
155-
use unstable::sync::{Exclusive, exclusive};
156-
157-
struct SharedValue(());
158-
type ValueMutex = Exclusive<SharedValue>;
159-
fn key(_: ValueMutex) { }
153+
use unstable::finally::Finally;
160154

161155
unsafe {
162-
let lock: ValueMutex = global_data_clone_create(key, || {
163-
~exclusive(SharedValue(()))
164-
});
156+
return do (|| {
157+
rust_take_env_lock();
158+
f()
159+
}).finally {
160+
rust_drop_env_lock();
161+
};
162+
}
165163

166-
lock.with_imm(|_| f() )
164+
extern {
165+
#[fast_ffi]
166+
fn rust_take_env_lock();
167+
#[fast_ffi]
168+
fn rust_drop_env_lock();
167169
}
168170
}
169171

@@ -749,7 +751,7 @@ pub fn list_dir(p: &Path) -> ~[~str] {
749751
use os::win32::{
750752
as_utf16_p
751753
};
752-
use unstable::exchange_alloc::{malloc_raw, free_raw};
754+
use rt::global_heap::{malloc_raw, free_raw};
753755
#[nolink]
754756
extern {
755757
unsafe fn rust_list_dir_wfd_size() -> libc::size_t;

0 commit comments

Comments
 (0)