Skip to content

Commit 11b1521

Browse files
committed
---
yaml --- r: 142701 b: refs/heads/try2 c: f74250e h: refs/heads/master i: 142699: 7c5c9d4 v: v3
1 parent 367a5aa commit 11b1521

Some content is hidden

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

53 files changed

+2110
-5648
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: 41dcec2fe16e272016ae77d10a6a5ff3a737f192
8+
refs/heads/try2: f74250e3a970f81388a73aeb8f3d53304d77c34b
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/test.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ use std::u64;
3636
use std::uint;
3737
use std::vec;
3838

39+
pub mod rustrt {
40+
use std::libc::size_t;
41+
42+
#[abi = "cdecl"]
43+
pub extern {
44+
pub unsafe fn rust_sched_threads() -> size_t;
45+
}
46+
}
3947

4048
// The name of a test. By convention this follows the rules for rust
4149
// paths; i.e. it should be a series of identifiers separated by double
@@ -485,10 +493,11 @@ static SCHED_OVERCOMMIT : uint = 1;
485493
static SCHED_OVERCOMMIT : uint = 4u;
486494
487495
fn get_concurrency() -> uint {
488-
use std::rt;
489-
let threads = rt::util::default_sched_threads();
490-
if threads == 1 { 1 }
491-
else { threads * SCHED_OVERCOMMIT }
496+
unsafe {
497+
let threads = rustrt::rust_sched_threads() as uint;
498+
if threads == 1 { 1 }
499+
else { threads * SCHED_OVERCOMMIT }
500+
}
492501
}
493502
494503
#[allow(non_implicitly_copyable_typarams)]

branches/try2/src/libstd/at_vec.rs

Lines changed: 26 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,23 @@ use vec::{ImmutableVector, OwnedVector};
2222
/// Code for dealing with @-vectors. This is pretty incomplete, and
2323
/// contains a bunch of duplication from the code for ~-vectors.
2424
25+
pub mod rustrt {
26+
use libc;
27+
use vec;
28+
#[cfg(stage0)]
29+
use intrinsic::{TyDesc};
30+
#[cfg(not(stage0))]
31+
use unstable::intrinsics::{TyDesc};
32+
33+
#[abi = "cdecl"]
34+
#[link_name = "rustrt"]
35+
pub extern {
36+
pub unsafe fn vec_reserve_shared_actual(t: *TyDesc,
37+
v: **vec::raw::VecRepr,
38+
n: libc::size_t);
39+
}
40+
}
41+
2542
/// Returns the number of elements the vector can hold without reallocating
2643
#[inline]
2744
pub fn capacity<T>(v: @[T]) -> uint {
@@ -175,17 +192,18 @@ pub mod traits {
175192
pub mod traits {}
176193

177194
pub mod raw {
178-
use at_vec::capacity;
179-
use cast;
195+
use at_vec::{capacity, rustrt};
180196
use cast::{transmute, transmute_copy};
181197
use libc;
182198
use ptr;
183199
use sys;
184200
use uint;
185-
use unstable::intrinsics;
186-
use unstable::intrinsics::{move_val_init, TyDesc};
201+
use unstable::intrinsics::{move_val_init};
187202
use vec;
188-
use vec::UnboxedVecRepr;
203+
#[cfg(stage0)]
204+
use intrinsic::{get_tydesc};
205+
#[cfg(not(stage0))]
206+
use unstable::intrinsics::{get_tydesc};
189207

190208
pub type VecRepr = vec::raw::VecRepr;
191209
pub type SliceRepr = vec::raw::SliceRepr;
@@ -246,49 +264,9 @@ pub mod raw {
246264
pub unsafe fn reserve<T>(v: &mut @[T], n: uint) {
247265
// Only make the (slow) call into the runtime if we have to
248266
if capacity(*v) < n {
249-
let ptr: *mut *mut VecRepr = transmute(v);
250-
let ty = intrinsics::get_tydesc::<T>();
251-
// XXX transmute shouldn't be necessary
252-
let ty = cast::transmute(ty);
253-
return reserve_raw(ty, ptr, n);
254-
}
255-
}
256-
257-
// Implementation detail. Shouldn't be public
258-
#[allow(missing_doc)]
259-
pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut VecRepr, n: uint) {
260-
261-
unsafe {
262-
let size_in_bytes = n * (*ty).size;
263-
if size_in_bytes > (**ptr).unboxed.alloc {
264-
let total_size = size_in_bytes + sys::size_of::<UnboxedVecRepr>();
265-
// XXX: UnboxedVecRepr has an extra u8 at the end
266-
let total_size = total_size - sys::size_of::<u8>();
267-
(*ptr) = local_realloc(*ptr as *(), total_size) as *mut VecRepr;
268-
(**ptr).unboxed.alloc = size_in_bytes;
269-
}
270-
}
271-
272-
fn local_realloc(ptr: *(), size: uint) -> *() {
273-
use rt;
274-
use rt::OldTaskContext;
275-
use rt::local::Local;
276-
use rt::task::Task;
277-
278-
if rt::context() == OldTaskContext {
279-
unsafe {
280-
return rust_local_realloc(ptr, size as libc::size_t);
281-
}
282-
283-
extern {
284-
#[fast_ffi]
285-
fn rust_local_realloc(ptr: *(), size: libc::size_t) -> *();
286-
}
287-
} else {
288-
do Local::borrow::<Task, *()> |task| {
289-
task.heap.realloc(ptr as *libc::c_void, size) as *()
290-
}
291-
}
267+
let ptr: **VecRepr = transmute(v);
268+
rustrt::vec_reserve_shared_actual(get_tydesc::<T>(),
269+
ptr, n as libc::size_t);
292270
}
293271
}
294272

branches/try2/src/libstd/cleanup.rs

Lines changed: 102 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,105 @@
1010

1111
#[doc(hidden)];
1212

13-
use libc::c_void;
13+
use libc::{c_char, intptr_t, uintptr_t};
1414
use ptr::{mut_null};
1515
use repr::BoxRepr;
1616
use cast::transmute;
1717
use unstable::intrinsics::TyDesc;
18+
#[cfg(not(test))] use unstable::lang::clear_task_borrow_list;
1819

19-
type DropGlue<'self> = &'self fn(**TyDesc, *c_void);
20+
/**
21+
* Runtime structures
22+
*
23+
* NB: These must match the representation in the C++ runtime.
24+
*/
25+
26+
type TaskID = uintptr_t;
27+
28+
struct StackSegment { priv opaque: () }
29+
struct Scheduler { priv opaque: () }
30+
struct SchedulerLoop { priv opaque: () }
31+
struct Kernel { priv opaque: () }
32+
struct Env { priv opaque: () }
33+
struct AllocHeader { priv opaque: () }
34+
struct MemoryRegion { priv opaque: () }
35+
36+
#[cfg(target_arch="x86")]
37+
struct Registers {
38+
data: [u32, ..16]
39+
}
40+
41+
#[cfg(target_arch="arm")]
42+
#[cfg(target_arch="mips")]
43+
struct Registers {
44+
data: [u32, ..32]
45+
}
46+
47+
#[cfg(target_arch="x86")]
48+
#[cfg(target_arch="arm")]
49+
#[cfg(target_arch="mips")]
50+
struct Context {
51+
regs: Registers,
52+
next: *Context,
53+
pad: [u32, ..3]
54+
}
55+
56+
#[cfg(target_arch="x86_64")]
57+
struct Registers {
58+
data: [u64, ..22]
59+
}
60+
61+
#[cfg(target_arch="x86_64")]
62+
struct Context {
63+
regs: Registers,
64+
next: *Context,
65+
pad: uintptr_t
66+
}
67+
68+
struct BoxedRegion {
69+
env: *Env,
70+
backing_region: *MemoryRegion,
71+
live_allocs: *BoxRepr
72+
}
73+
74+
#[cfg(target_arch="x86")]
75+
#[cfg(target_arch="arm")]
76+
#[cfg(target_arch="mips")]
77+
struct Task {
78+
// Public fields
79+
refcount: intptr_t, // 0
80+
id: TaskID, // 4
81+
pad: [u32, ..2], // 8
82+
ctx: Context, // 16
83+
stack_segment: *StackSegment, // 96
84+
runtime_sp: uintptr_t, // 100
85+
scheduler: *Scheduler, // 104
86+
scheduler_loop: *SchedulerLoop, // 108
87+
88+
// Fields known only to the runtime
89+
kernel: *Kernel, // 112
90+
name: *c_char, // 116
91+
list_index: i32, // 120
92+
boxed_region: BoxedRegion // 128
93+
}
94+
95+
#[cfg(target_arch="x86_64")]
96+
struct Task {
97+
// Public fields
98+
refcount: intptr_t,
99+
id: TaskID,
100+
ctx: Context,
101+
stack_segment: *StackSegment,
102+
runtime_sp: uintptr_t,
103+
scheduler: *Scheduler,
104+
scheduler_loop: *SchedulerLoop,
105+
106+
// Fields known only to the runtime
107+
kernel: *Kernel,
108+
name: *c_char,
109+
list_index: i32,
110+
boxed_region: BoxedRegion
111+
}
20112

21113
/*
22114
* Box annihilation
@@ -35,9 +127,9 @@ unsafe fn each_live_alloc(read_next_before: bool,
35127
//! Walks the internal list of allocations
36128
37129
use managed;
38-
use rt::local_heap;
39130

40-
let box = local_heap::live_allocs();
131+
let task: *Task = transmute(rustrt::rust_get_task());
132+
let box = (*task).boxed_region.live_allocs;
41133
let mut box: *mut BoxRepr = transmute(copy box);
42134
while box != mut_null() {
43135
let next_before = transmute(copy (*box).header.next);
@@ -59,13 +151,7 @@ unsafe fn each_live_alloc(read_next_before: bool,
59151

60152
#[cfg(unix)]
61153
fn debug_mem() -> bool {
62-
use rt;
63-
use rt::OldTaskContext;
64-
// XXX: Need to port the environment struct to newsched
65-
match rt::context() {
66-
OldTaskContext => ::rt::env::get().debug_mem,
67-
_ => false
68-
}
154+
::rt::env::get().debug_mem
69155
}
70156

71157
#[cfg(windows)]
@@ -87,12 +173,13 @@ unsafe fn call_drop_glue(tydesc: *TyDesc, data: *i8) {
87173
}
88174

89175
/// Destroys all managed memory (i.e. @ boxes) held by the current task.
176+
#[cfg(not(test))]
177+
#[lang="annihilate"]
90178
pub unsafe fn annihilate() {
91-
use rt::local_heap::local_free;
179+
use unstable::lang::local_free;
92180
use io::WriterUtil;
93181
use io;
94182
use libc;
95-
use rt::borrowck;
96183
use sys;
97184
use managed;
98185

@@ -104,7 +191,7 @@ pub unsafe fn annihilate() {
104191

105192
// Quick hack: we need to free this list upon task exit, and this
106193
// is a convenient place to do it.
107-
borrowck::clear_task_borrow_list();
194+
clear_task_borrow_list();
108195

109196
// Pass 1: Make all boxes immortal.
110197
//
@@ -126,7 +213,7 @@ pub unsafe fn annihilate() {
126213
// callback, as the original value may have been freed.
127214
for each_live_alloc(false) |box, uniq| {
128215
if !uniq {
129-
let tydesc: *TyDesc = transmute(copy (*box).header.type_desc);
216+
let tydesc = (*box).header.type_desc;
130217
let data = transmute(&(*box).data);
131218
call_drop_glue(tydesc, data);
132219
}

branches/try2/src/libstd/comm.rs

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,58 +220,48 @@ impl<T: Send> Peekable<T> for PortSet<T> {
220220

221221
/// A channel that can be shared between many senders.
222222
pub struct SharedChan<T> {
223-
inner: Either<Exclusive<pipesy::Chan<T>>, rtcomm::SharedChan<T>>
223+
ch: Exclusive<pipesy::Chan<T>>
224224
}
225225

226226
impl<T: Send> SharedChan<T> {
227227
/// Converts a `chan` into a `shared_chan`.
228228
pub fn new(c: Chan<T>) -> SharedChan<T> {
229229
let Chan { inner } = c;
230230
let c = match inner {
231-
Left(c) => Left(exclusive(c)),
232-
Right(c) => Right(rtcomm::SharedChan::new(c))
231+
Left(c) => c,
232+
Right(_) => fail!("SharedChan not implemented")
233233
};
234-
SharedChan { inner: c }
234+
SharedChan { ch: exclusive(c) }
235235
}
236236
}
237237

238238
impl<T: Send> GenericChan<T> for SharedChan<T> {
239239
fn send(&self, x: T) {
240-
match self.inner {
241-
Left(ref chan) => {
242-
unsafe {
243-
let mut xx = Some(x);
244-
do chan.with_imm |chan| {
245-
let x = replace(&mut xx, None);
246-
chan.send(x.unwrap())
247-
}
248-
}
240+
unsafe {
241+
let mut xx = Some(x);
242+
do self.ch.with_imm |chan| {
243+
let x = replace(&mut xx, None);
244+
chan.send(x.unwrap())
249245
}
250-
Right(ref chan) => chan.send(x)
251246
}
252247
}
253248
}
254249

255250
impl<T: Send> GenericSmartChan<T> for SharedChan<T> {
256251
fn try_send(&self, x: T) -> bool {
257-
match self.inner {
258-
Left(ref chan) => {
259-
unsafe {
260-
let mut xx = Some(x);
261-
do chan.with_imm |chan| {
262-
let x = replace(&mut xx, None);
263-
chan.try_send(x.unwrap())
264-
}
265-
}
252+
unsafe {
253+
let mut xx = Some(x);
254+
do self.ch.with_imm |chan| {
255+
let x = replace(&mut xx, None);
256+
chan.try_send(x.unwrap())
266257
}
267-
Right(ref chan) => chan.try_send(x)
268258
}
269259
}
270260
}
271261

272262
impl<T: Send> ::clone::Clone for SharedChan<T> {
273263
fn clone(&self) -> SharedChan<T> {
274-
SharedChan { inner: self.inner.clone() }
264+
SharedChan { ch: self.ch.clone() }
275265
}
276266
}
277267

0 commit comments

Comments
 (0)