Skip to content

Commit 8bdf06b

Browse files
author
Eric Reed
committed
---
yaml --- r: 63486 b: refs/heads/snap-stage3 c: 083c692 h: refs/heads/master v: v3
1 parent ffa1f50 commit 8bdf06b

File tree

19 files changed

+521
-721
lines changed

19 files changed

+521
-721
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: b548c781aa959085474d9e16f11a4dffb8420af5
4+
refs/heads/snap-stage3: 083c692565340791b06ab67d66c4c95d63b222cb
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/macros.rs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,18 @@
1010

1111
#[macro_escape];
1212

13-
macro_rules! rterrln (
14-
($( $arg:expr),+) => ( {
15-
::rt::util::dumb_println(fmt!( $($arg),+ ));
16-
} )
17-
)
18-
1913
// Some basic logging
2014
macro_rules! rtdebug_ (
2115
($( $arg:expr),+) => ( {
22-
rterrln!( $($arg),+ )
16+
dumb_println(fmt!( $($arg),+ ));
17+
18+
fn dumb_println(s: &str) {
19+
use io::WriterUtil;
20+
let dbg = ::libc::STDERR_FILENO as ::io::fd_t;
21+
dbg.write_str(s);
22+
dbg.write_str("\n");
23+
}
24+
2325
} )
2426
)
2527

@@ -31,15 +33,24 @@ macro_rules! rtdebug (
3133
macro_rules! rtassert (
3234
( $arg:expr ) => ( {
3335
if !$arg {
34-
rtabort!("assertion failed: %s", stringify!($arg));
36+
abort!("assertion failed: %s", stringify!($arg));
3537
}
3638
} )
3739
)
3840

3941

40-
macro_rules! rtabort(
42+
// The do_abort function was originally inside the abort macro, but
43+
// this was ICEing the compiler so it has been moved outside. Now this
44+
// seems to work?
45+
#[allow(missing_doc)]
46+
pub fn do_abort() -> ! {
47+
unsafe { ::libc::abort(); }
48+
}
49+
50+
macro_rules! abort(
4151
($( $msg:expr),+) => ( {
42-
::rt::util::abort(fmt!($($msg),+));
52+
rtdebug!($($msg),+);
53+
::macros::do_abort();
4354
} )
4455
)
4556

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

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use c_malloc = libc::malloc;
1414
use c_free = libc::free;
1515
use managed::raw::{BoxHeaderRepr, BoxRepr};
1616
use cast::transmute;
17-
use unstable::intrinsics::{atomic_xadd,atomic_xsub, atomic_load};
17+
use unstable::intrinsics::{atomic_xadd,atomic_xsub};
1818
use ptr::null;
1919
use intrinsic::TyDesc;
2020

@@ -34,7 +34,8 @@ pub unsafe fn malloc(td: *TypeDesc, size: uint) -> *c_void {
3434
box.header.prev = null();
3535
box.header.next = null();
3636

37-
inc_count();
37+
let exchange_count = &mut *exchange_count_ptr();
38+
atomic_xadd(exchange_count, 1);
3839

3940
return transmute(box);
4041
}
@@ -47,46 +48,21 @@ pub unsafe fn malloc_raw(size: uint) -> *c_void {
4748
if p.is_null() {
4849
fail!("Failure in malloc_raw: result ptr is null");
4950
}
50-
inc_count();
5151
p
5252
}
5353

5454
pub unsafe fn free(ptr: *c_void) {
55+
let exchange_count = &mut *exchange_count_ptr();
56+
atomic_xsub(exchange_count, 1);
57+
5558
assert!(ptr.is_not_null());
56-
dec_count();
5759
c_free(ptr);
5860
}
5961
///Thin wrapper around libc::free, as with exchange_alloc::malloc_raw
6062
pub unsafe fn free_raw(ptr: *c_void) {
61-
assert!(ptr.is_not_null());
62-
dec_count();
6363
c_free(ptr);
6464
}
6565

66-
fn inc_count() {
67-
unsafe {
68-
let exchange_count = &mut *exchange_count_ptr();
69-
atomic_xadd(exchange_count, 1);
70-
}
71-
}
72-
73-
fn dec_count() {
74-
unsafe {
75-
let exchange_count = &mut *exchange_count_ptr();
76-
atomic_xsub(exchange_count, 1);
77-
}
78-
}
79-
80-
pub fn cleanup() {
81-
unsafe {
82-
let count_ptr = exchange_count_ptr();
83-
let allocations = atomic_load(&*count_ptr);
84-
if allocations != 0 {
85-
rtabort!("exchange heap not empty on exit - %i dangling allocations", allocations);
86-
}
87-
}
88-
}
89-
9066
fn get_box_size(body_size: uint, body_align: uint) -> uint {
9167
let header_size = size_of::<BoxHeaderRepr>();
9268
// FIXME (#2699): This alignment calculation is suspicious. Is it right?

branches/snap-stage3/src/libstd/rt/io/net/ip.rs

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

11+
use std::cmp::{Eq, TotalEq};
12+
1113
pub enum IpAddr {
1214
Ipv4(u8, u8, u8, u8, u16),
1315
Ipv6
1416
}
17+
18+
impl Eq for IpAddr {
19+
fn eq(&self, other: &IpAddr) -> bool {
20+
match (*self, *other) {
21+
(Ipv4(a,b,c,d,e), Ipv4(f,g,h,i,j)) => (a,b,c,d,e) == (f,g,h,i,j),
22+
(Ipv6, Ipv6) => fail!(),
23+
_ => false
24+
}
25+
}
26+
fn ne(&self, other: &IpAddr) -> bool {
27+
!(self == other)
28+
}
29+
}
30+
31+
impl TotalEq for IpAddr {
32+
fn equals(&self, other: &IpAddr) -> bool {
33+
*self == *other
34+
}
35+
}

branches/snap-stage3/src/libstd/rt/io/net/udp.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,22 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use prelude::*;
12-
use super::super::*;
13-
use super::ip::IpAddr;
11+
use option::{Option};
12+
use rt::io::net::ip::IpAddr;
13+
use rt::io::{Reader, Writer, Listener};
14+
use rt::rtio::{RtioUdpStreamObject};
1415

15-
pub struct UdpStream;
16+
pub struct UdpStream {
17+
rtstream: ~RtioUdpStreamObject
18+
}
1619

1720
impl UdpStream {
21+
fn new(s: ~RtioUdpStreamObject) -> UdpStream {
22+
UdpStream {
23+
rtstream: s
24+
}
25+
}
26+
1827
pub fn connect(_addr: IpAddr) -> Option<UdpStream> {
1928
fail!()
2029
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ impl Local for Scheduler {
3838
}
3939
match res {
4040
Some(r) => { r }
41-
None => rtabort!("function failed!")
41+
None => abort!("function failed!")
4242
}
4343
}
4444
unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() }
45-
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> { rtabort!("unimpl") }
45+
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> { abort!("unimpl") }
4646
}
4747

4848
impl Local for Task {
49-
fn put(_value: ~Task) { rtabort!("unimpl") }
50-
fn take() -> ~Task { rtabort!("unimpl") }
51-
fn exists() -> bool { rtabort!("unimpl") }
49+
fn put(_value: ~Task) { abort!("unimpl") }
50+
fn take() -> ~Task { abort!("unimpl") }
51+
fn exists() -> bool { abort!("unimpl") }
5252
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
5353
do Local::borrow::<Scheduler, T> |sched| {
5454
match sched.current_task {
5555
Some(~ref mut task) => {
5656
f(&mut *task.task)
5757
}
5858
None => {
59-
rtabort!("no scheduler")
59+
abort!("no scheduler")
6060
}
6161
}
6262
}
@@ -69,7 +69,7 @@ impl Local for Task {
6969
}
7070
None => {
7171
// Don't fail. Infinite recursion
72-
rtabort!("no scheduler")
72+
abort!("no scheduler")
7373
}
7474
}
7575
}
@@ -84,16 +84,16 @@ impl Local for Task {
8484

8585
// XXX: This formulation won't work once ~IoFactoryObject is a real trait pointer
8686
impl Local for IoFactoryObject {
87-
fn put(_value: ~IoFactoryObject) { rtabort!("unimpl") }
88-
fn take() -> ~IoFactoryObject { rtabort!("unimpl") }
89-
fn exists() -> bool { rtabort!("unimpl") }
90-
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { rtabort!("unimpl") }
87+
fn put(_value: ~IoFactoryObject) { abort!("unimpl") }
88+
fn take() -> ~IoFactoryObject { abort!("unimpl") }
89+
fn exists() -> bool { abort!("unimpl") }
90+
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { abort!("unimpl") }
9191
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
9292
let sched = Local::unsafe_borrow::<Scheduler>();
9393
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();
9494
return io;
9595
}
96-
unsafe fn try_unsafe_borrow() -> Option<*mut IoFactoryObject> { rtabort!("unimpl") }
96+
unsafe fn try_unsafe_borrow() -> Option<*mut IoFactoryObject> { abort!("unimpl") }
9797
}
9898

9999
#[cfg(test)]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub unsafe fn unsafe_borrow<T>() -> *mut T {
109109
fn tls_key() -> tls::Key {
110110
match maybe_tls_key() {
111111
Some(key) => key,
112-
None => rtabort!("runtime tls key not initialized")
112+
None => abort!("runtime tls key not initialized")
113113
}
114114
}
115115

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

Lines changed: 15 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,7 @@ 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;
6963
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};
7864

7965
/// The global (exchange) heap.
8066
pub mod global_heap;
@@ -153,9 +139,6 @@ pub mod join_latch;
153139

154140
pub mod metrics;
155141

156-
// FIXME #5248 shouldn't be pub
157-
/// Just stuff
158-
pub mod util;
159142

160143
/// Set up a default runtime configuration, given compiler-supplied arguments.
161144
///
@@ -173,9 +156,22 @@ pub mod util;
173156
/// The return value is used as the process return code. 0 on success, 101 on error.
174157
pub fn start(_argc: int, _argv: **u8, crate_map: *u8, main: ~fn()) -> int {
175158

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

180176
return 0;
181177
}
@@ -186,71 +182,6 @@ pub fn init(crate_map: *u8) {
186182
logging::init(crate_map);
187183
}
188184

189-
pub fn cleanup() {
190-
global_heap::cleanup();
191-
}
192-
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-
254185
/// Possible contexts in which Rust code may be executing.
255186
/// Different runtime services are available depending on context.
256187
/// Mostly used for determining if we're using the new scheduler

0 commit comments

Comments
 (0)