Skip to content

Commit 75014f7

Browse files
committed
libs: Fix miscellaneous fallout of librustrt
1 parent d743b88 commit 75014f7

34 files changed

+263
-288
lines changed

src/liballoc/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ pub mod owned;
9696
pub mod arc;
9797
pub mod rc;
9898

99+
// FIXME(#14344): When linking liballoc with libstd, this library will be linked
100+
// as an rlib (it only exists as an rlib). It turns out that an
101+
// optimized standard library doesn't actually use *any* symbols
102+
// from this library. Everything is inlined and optimized away.
103+
// This means that linkers will actually omit the object for this
104+
// file, even though it may be needed in the future.
105+
//
106+
// To get around this for now, we define a dummy symbol which
107+
// will never get inlined so the stdlib can call it. The stdlib's
108+
// reference to this symbol will cause this library's object file
109+
// to get linked in to libstd successfully (the linker won't
110+
// optimize it out).
111+
#[doc(hidden)]
112+
pub fn fixme_14344_be_sure_to_link_to_collections() {}
113+
99114
#[cfg(not(test))]
100115
#[doc(hidden)]
101116
mod std {

src/liballoc/util.rs

-17
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,3 @@ fn align_to(size: uint, align: uint) -> uint {
2828
assert!(align != 0);
2929
(size + align - 1) & !(align - 1)
3030
}
31-
32-
// FIXME(#14344): When linking liballoc with libstd, this library will be linked
33-
// as an rlib (it only exists as an rlib). It turns out that an
34-
// optimized standard library doesn't actually use *any* symbols
35-
// from this library. Everything is inlined and optimized away.
36-
// This means that linkers will actually omit the object for this
37-
// file, even though it may be needed in the future.
38-
//
39-
// To get around this for now, we define a dummy symbol which
40-
// will never get inlined so the stdlib can call it. The stdlib's
41-
// reference to this symbol will cause this library's object file
42-
// to get linked in to libstd successfully (the linker won't
43-
// optimize it out).
44-
#[deprecated]
45-
#[doc(hidden)]
46-
pub fn make_stdlib_link_work() {}
47-

src/libcollections/lib.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ fn expect<T>(a: core::option::Option<T>, b: &str) -> T {
7272
}
7373
}
7474

75+
// FIXME(#14344) this shouldn't be necessary
76+
#[doc(hidden)]
77+
pub fn fixme_14344_be_sure_to_link_to_collections() {}
78+
7579
#[cfg(not(test))]
7680
mod std {
7781
pub use core::fmt; // necessary for fail!()

src/libcollections/slice.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ mod tests {
862862
use std::prelude::*;
863863
use std::rand::{Rng, task_rng};
864864
use std::rc::Rc;
865-
use std::unstable;
865+
use std::rt;
866866
use slice::*;
867867

868868
use vec::Vec;
@@ -1104,9 +1104,9 @@ mod tests {
11041104
#[test]
11051105
fn test_swap_remove_noncopyable() {
11061106
// Tests that we don't accidentally run destructors twice.
1107-
let mut v = vec![unstable::sync::Exclusive::new(()),
1108-
unstable::sync::Exclusive::new(()),
1109-
unstable::sync::Exclusive::new(())];
1107+
let mut v = vec![rt::exclusive::Exclusive::new(()),
1108+
rt::exclusive::Exclusive::new(()),
1109+
rt::exclusive::Exclusive::new(())];
11101110
let mut _e = v.swap_remove(0);
11111111
assert_eq!(v.len(), 2);
11121112
_e = v.swap_remove(1);

src/libgreen/basic.rs

+20-33
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::atomics;
2020
use std::mem;
2121
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback};
2222
use std::rt::rtio::{PausableIdleCallback, Callback};
23-
use std::unstable::sync::Exclusive;
23+
use std::rt::exclusive::Exclusive;
2424

2525
/// This is the only exported function from this module.
2626
pub fn event_loop() -> Box<EventLoop:Send> {
@@ -31,7 +31,7 @@ struct BasicLoop {
3131
work: Vec<proc():Send>, // pending work
3232
remotes: Vec<(uint, Box<Callback:Send>)>,
3333
next_remote: uint,
34-
messages: Exclusive<Vec<Message>>,
34+
messages: Arc<Exclusive<Vec<Message>>>,
3535
idle: Option<Box<Callback:Send>>,
3636
idle_active: Option<Arc<atomics::AtomicBool>>,
3737
}
@@ -46,7 +46,7 @@ impl BasicLoop {
4646
idle_active: None,
4747
next_remote: 0,
4848
remotes: vec![],
49-
messages: Exclusive::new(vec![]),
49+
messages: Arc::new(Exclusive::new(Vec::new())),
5050
}
5151
}
5252

@@ -61,19 +61,10 @@ impl BasicLoop {
6161

6262
fn remote_work(&mut self) {
6363
let messages = unsafe {
64-
self.messages.with(|messages| {
65-
if messages.len() > 0 {
66-
Some(mem::replace(messages, vec![]))
67-
} else {
68-
None
69-
}
70-
})
71-
};
72-
let messages = match messages {
73-
Some(m) => m, None => return
64+
mem::replace(&mut *self.messages.lock(), Vec::new())
7465
};
75-
for message in messages.iter() {
76-
self.message(*message);
66+
for message in messages.move_iter() {
67+
self.message(message);
7768
}
7869
}
7970

@@ -125,13 +116,13 @@ impl EventLoop for BasicLoop {
125116
}
126117

127118
unsafe {
119+
let mut messages = self.messages.lock();
128120
// We block here if we have no messages to process and we may
129121
// receive a message at a later date
130-
self.messages.hold_and_wait(|messages| {
131-
self.remotes.len() > 0 &&
132-
messages.len() == 0 &&
133-
self.work.len() == 0
134-
})
122+
if self.remotes.len() > 0 && messages.len() == 0 &&
123+
self.work.len() == 0 {
124+
messages.wait()
125+
}
135126
}
136127
}
137128
}
@@ -165,33 +156,29 @@ impl EventLoop for BasicLoop {
165156
}
166157

167158
struct BasicRemote {
168-
queue: Exclusive<Vec<Message>>,
159+
queue: Arc<Exclusive<Vec<Message>>>,
169160
id: uint,
170161
}
171162

172163
impl BasicRemote {
173-
fn new(queue: Exclusive<Vec<Message>>, id: uint) -> BasicRemote {
164+
fn new(queue: Arc<Exclusive<Vec<Message>>>, id: uint) -> BasicRemote {
174165
BasicRemote { queue: queue, id: id }
175166
}
176167
}
177168

178169
impl RemoteCallback for BasicRemote {
179170
fn fire(&mut self) {
180-
unsafe {
181-
self.queue.hold_and_signal(|queue| {
182-
queue.push(RunRemote(self.id));
183-
})
184-
}
171+
let mut queue = unsafe { self.queue.lock() };
172+
queue.push(RunRemote(self.id));
173+
queue.signal();
185174
}
186175
}
187176

188177
impl Drop for BasicRemote {
189178
fn drop(&mut self) {
190-
unsafe {
191-
self.queue.hold_and_signal(|queue| {
192-
queue.push(RemoveRemote(self.id));
193-
})
194-
}
179+
let mut queue = unsafe { self.queue.lock() };
180+
queue.push(RemoveRemote(self.id));
181+
queue.signal();
195182
}
196183
}
197184

@@ -216,7 +203,7 @@ impl Drop for BasicPausable {
216203

217204
#[cfg(test)]
218205
mod test {
219-
use std::task::TaskOpts;
206+
use std::rt::task::TaskOpts;
220207

221208
use basic;
222209
use PoolConfig;

src/libgreen/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@
160160
//! # Using a scheduler pool
161161
//!
162162
//! ```rust
163-
//! use std::task::TaskOpts;
163+
//! use std::rt::task::TaskOpts;
164164
//! use green::{SchedPool, PoolConfig};
165165
//! use green::sched::{PinnedTask, TaskFromFriend};
166166
//!
@@ -221,10 +221,10 @@ use std::mem::replace;
221221
use std::os;
222222
use std::rt::rtio;
223223
use std::rt::thread::Thread;
224+
use std::rt::task::TaskOpts;
224225
use std::rt;
225226
use std::sync::atomics::{SeqCst, AtomicUint, INIT_ATOMIC_UINT};
226227
use std::sync::deque;
227-
use std::task::TaskOpts;
228228

229229
use sched::{Shutdown, Scheduler, SchedHandle, TaskFromFriend, NewNeighbor};
230230
use sleeper_list::SleeperList;
@@ -319,7 +319,7 @@ pub fn run(event_loop_factory: fn() -> Box<rtio::EventLoop:Send>,
319319
let mut pool = SchedPool::new(cfg);
320320
let (tx, rx) = channel();
321321
let mut opts = TaskOpts::new();
322-
opts.notify_chan = Some(tx);
322+
opts.on_exit = Some(proc(r) tx.send(r));
323323
opts.name = Some("<main>".into_maybe_owned());
324324
pool.spawn(opts, main);
325325

src/libgreen/sched.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
use std::mem;
1212
use std::rt::local::Local;
13+
use std::rt::mutex::NativeMutex;
1314
use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
1415
use std::rt::task::BlockedTask;
1516
use std::rt::task::Task;
1617
use std::sync::deque;
17-
use std::unstable::mutex::NativeMutex;
1818
use std::raw;
1919

2020
use std::rand::{XorShiftRng, Rng, Rand};
@@ -1022,7 +1022,7 @@ fn new_sched_rng() -> XorShiftRng {
10221022
mod test {
10231023
use rustuv;
10241024

1025-
use std::task::TaskOpts;
1025+
use std::rt::task::TaskOpts;
10261026
use std::rt::task::Task;
10271027
use std::rt::local::Local;
10281028

@@ -1475,7 +1475,7 @@ mod test {
14751475

14761476
#[test]
14771477
fn test_spawn_sched_blocking() {
1478-
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
1478+
use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
14791479
static mut LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
14801480

14811481
// Testing that a task in one scheduler can block in foreign code

src/libgreen/simple.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ use std::any::Any;
1515
use std::mem;
1616
use std::rt::Runtime;
1717
use std::rt::local::Local;
18+
use std::rt::mutex::NativeMutex;
1819
use std::rt::rtio;
19-
use std::rt::task::{Task, BlockedTask};
20-
use std::task::TaskOpts;
21-
use std::unstable::mutex::NativeMutex;
20+
use std::rt::task::{Task, BlockedTask, TaskOpts};
2221

2322
struct SimpleTask {
2423
lock: NativeMutex,

src/libgreen/stack.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::rt::env::max_cached_stacks;
11+
use std::sync::atomics;
1212
use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable,
13-
MapNonStandardFlags, MapVirtual};
13+
MapNonStandardFlags, MapVirtual, getenv};
1414
use libc;
1515

1616
/// A task's stack. The name "Stack" is a vestige of segmented stacks.
@@ -151,6 +151,22 @@ impl StackPool {
151151
}
152152
}
153153

154+
fn max_cached_stacks() -> uint {
155+
static mut AMT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT;
156+
match unsafe { AMT.load(atomics::SeqCst) } {
157+
0 => {}
158+
n => return n - 1,
159+
}
160+
let amt = getenv("RUST_MAX_CACHED_STACKS").and_then(|s| from_str(s.as_slice()));
161+
// This default corresponds to 20M of cache per scheduler (at the
162+
// default size).
163+
let amt = amt.unwrap_or(10);
164+
// 0 is our sentinel value, so ensure that we'll never see 0 after
165+
// initialization has run
166+
unsafe { AMT.store(amt + 1, atomics::SeqCst); }
167+
return amt;
168+
}
169+
154170
extern {
155171
fn rust_valgrind_stack_register(start: *libc::uintptr_t,
156172
end: *libc::uintptr_t) -> libc::c_uint;

src/libgreen/task.rs

+9-20
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@ use std::any::Any;
2222
use std::mem;
2323
use std::raw;
2424
use std::rt::Runtime;
25-
use std::rt::env;
2625
use std::rt::local::Local;
26+
use std::rt::mutex::NativeMutex;
2727
use std::rt::rtio;
2828
use std::rt::stack;
29-
use std::rt::task::{Task, BlockedTask, SendMessage};
30-
use std::task::TaskOpts;
31-
use std::unstable::mutex::NativeMutex;
29+
use std::rt::task::{Task, BlockedTask, TaskOpts};
30+
use std::rt;
3231

3332
use context::Context;
3433
use coroutine::Coroutine;
@@ -142,7 +141,7 @@ impl GreenTask {
142141
let mut ops = GreenTask::new_typed(None, TypeGreen(Some(home)));
143142

144143
// Allocate a stack for us to run on
145-
let stack_size = stack_size.unwrap_or_else(|| env::min_stack());
144+
let stack_size = stack_size.unwrap_or_else(|| rt::min_stack());
146145
let mut stack = stack_pool.take_stack(stack_size);
147146
let context = Context::new(bootstrap_green_task, ops.as_uint(), start,
148147
&mut stack);
@@ -176,23 +175,13 @@ impl GreenTask {
176175
pub fn configure(pool: &mut StackPool,
177176
opts: TaskOpts,
178177
f: proc():Send) -> Box<GreenTask> {
179-
let TaskOpts {
180-
notify_chan, name, stack_size,
181-
stderr, stdout,
182-
} = opts;
178+
let TaskOpts { name, stack_size, on_exit } = opts;
183179

184180
let mut green = GreenTask::new(pool, stack_size, f);
185181
{
186182
let task = green.task.get_mut_ref();
187183
task.name = name;
188-
task.stderr = stderr;
189-
task.stdout = stdout;
190-
match notify_chan {
191-
Some(chan) => {
192-
task.death.on_exit = Some(SendMessage(chan));
193-
}
194-
None => {}
195-
}
184+
task.death.on_exit = on_exit;
196185
}
197186
return green;
198187
}
@@ -490,7 +479,7 @@ mod tests {
490479
use std::rt::local::Local;
491480
use std::rt::task::Task;
492481
use std::task;
493-
use std::task::TaskOpts;
482+
use std::rt::task::TaskOpts;
494483

495484
use super::super::{PoolConfig, SchedPool};
496485
use super::GreenTask;
@@ -529,7 +518,7 @@ mod tests {
529518
opts.name = Some("test".into_maybe_owned());
530519
opts.stack_size = Some(20 * 4096);
531520
let (tx, rx) = channel();
532-
opts.notify_chan = Some(tx);
521+
opts.on_exit = Some(proc(r) tx.send(r));
533522
spawn_opts(opts, proc() {});
534523
assert!(rx.recv().is_ok());
535524
}
@@ -538,7 +527,7 @@ mod tests {
538527
fn smoke_opts_fail() {
539528
let mut opts = TaskOpts::new();
540529
let (tx, rx) = channel();
541-
opts.notify_chan = Some(tx);
530+
opts.on_exit = Some(proc(r) tx.send(r));
542531
spawn_opts(opts, proc() { fail!() });
543532
assert!(rx.recv().is_err());
544533
}

0 commit comments

Comments
 (0)