Skip to content

Commit 0b44475

Browse files
committed
---
yaml --- r: 95650 b: refs/heads/dist-snap c: baeed88 h: refs/heads/master v: v3
1 parent 820d319 commit 0b44475

File tree

19 files changed

+500
-131
lines changed

19 files changed

+500
-131
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: e8f72c38f4bf74e7291043917fdd0bae1404b407
9+
refs/heads/dist-snap: baeed886aa64943ad48121cc3b57dabec12bc835
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libextra/arc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,12 @@ pub struct Arc<T> { priv x: UnsafeArc<T> }
117117
*/
118118
impl<T:Freeze+Send> Arc<T> {
119119
/// Create an atomically reference counted wrapper.
120+
#[inline]
120121
pub fn new(data: T) -> Arc<T> {
121122
Arc { x: UnsafeArc::new(data) }
122123
}
123124

125+
#[inline]
124126
pub fn get<'a>(&'a self) -> &'a T {
125127
unsafe { &*self.x.get_immut() }
126128
}
@@ -148,6 +150,7 @@ impl<T:Freeze + Send> Clone for Arc<T> {
148150
* object. However, one of the `arc` objects can be sent to another task,
149151
* allowing them to share the underlying data.
150152
*/
153+
#[inline]
151154
fn clone(&self) -> Arc<T> {
152155
Arc { x: self.x.clone() }
153156
}
@@ -167,6 +170,7 @@ pub struct MutexArc<T> { priv x: UnsafeArc<MutexArcInner<T>> }
167170

168171
impl<T:Send> Clone for MutexArc<T> {
169172
/// Duplicate a mutex-protected Arc. See arc::clone for more details.
173+
#[inline]
170174
fn clone(&self) -> MutexArc<T> {
171175
// NB: Cloning the underlying mutex is not necessary. Its reference
172176
// count would be exactly the same as the shared state's.
@@ -349,6 +353,7 @@ pub struct RWArc<T> {
349353

350354
impl<T:Freeze + Send> Clone for RWArc<T> {
351355
/// Duplicate a rwlock-protected Arc. See arc::clone for more details.
356+
#[inline]
352357
fn clone(&self) -> RWArc<T> {
353358
RWArc { x: self.x.clone() }
354359
}

branches/dist-snap/src/libextra/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ pub fn rendezvous<T: Send>() -> (SyncPort<T>, SyncChan<T>) {
136136
#[cfg(test)]
137137
mod test {
138138
use comm::{DuplexStream, rendezvous};
139-
use std::rt::test::run_in_newsched_task;
139+
use std::rt::test::run_in_uv_task;
140140
use std::task::spawn_unlinked;
141141

142142

@@ -165,7 +165,7 @@ mod test {
165165
#[test]
166166
fn recv_a_lot() {
167167
// Rendezvous streams should be able to handle any number of messages being sent
168-
do run_in_newsched_task {
168+
do run_in_uv_task {
169169
let (port, chan) = rendezvous();
170170
do spawn {
171171
do 1000000.times { chan.send(()) }

branches/dist-snap/src/librustc/middle/trans/base.rs

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -288,37 +288,6 @@ pub fn get_extern_const(externs: &mut ExternMap, llmod: ModuleRef,
288288
return c;
289289
}
290290
}
291-
pub fn umax(cx: @mut Block, a: ValueRef, b: ValueRef) -> ValueRef {
292-
let _icx = push_ctxt("umax");
293-
let cond = ICmp(cx, lib::llvm::IntULT, a, b);
294-
return Select(cx, cond, b, a);
295-
}
296-
297-
pub fn umin(cx: @mut Block, a: ValueRef, b: ValueRef) -> ValueRef {
298-
let _icx = push_ctxt("umin");
299-
let cond = ICmp(cx, lib::llvm::IntULT, a, b);
300-
return Select(cx, cond, a, b);
301-
}
302-
303-
// Given a pointer p, returns a pointer sz(p) (i.e., inc'd by sz bytes).
304-
// The type of the returned pointer is always i8*. If you care about the
305-
// return type, use bump_ptr().
306-
pub fn ptr_offs(bcx: @mut Block, base: ValueRef, sz: ValueRef) -> ValueRef {
307-
let _icx = push_ctxt("ptr_offs");
308-
let raw = PointerCast(bcx, base, Type::i8p());
309-
InBoundsGEP(bcx, raw, [sz])
310-
}
311-
312-
// Increment a pointer by a given amount and then cast it to be a pointer
313-
// to a given type.
314-
pub fn bump_ptr(bcx: @mut Block, t: ty::t, base: ValueRef, sz: ValueRef) ->
315-
ValueRef {
316-
let _icx = push_ctxt("bump_ptr");
317-
let ccx = bcx.ccx();
318-
let bumped = ptr_offs(bcx, base, sz);
319-
let typ = type_of(ccx, t).ptr_to();
320-
PointerCast(bcx, bumped, typ)
321-
}
322291

323292
// Returns a pointer to the body for the box. The box may be an opaque
324293
// box. The result will be casted to the type of body_t, if it is statically
@@ -434,10 +403,6 @@ pub fn malloc_general(bcx: @mut Block, t: ty::t, heap: heap) -> MallocResult {
434403
assert!(heap != heap_exchange);
435404
malloc_general_dyn(bcx, t, heap, llsize_of(bcx.ccx(), ty))
436405
}
437-
pub fn malloc_boxed(bcx: @mut Block, t: ty::t)
438-
-> MallocResult {
439-
malloc_general(bcx, t, heap_managed)
440-
}
441406

442407
pub fn heap_for_unique(bcx: @mut Block, t: ty::t) -> heap {
443408
if ty::type_contents(bcx.tcx(), t).contains_managed() {
@@ -534,12 +499,6 @@ pub fn set_no_split_stack(f: ValueRef) {
534499
}
535500
}
536501

537-
pub fn set_glue_inlining(f: ValueRef, t: ty::t) {
538-
if ty::type_is_structural(t) {
539-
set_optimize_for_size(f);
540-
} else { set_always_inline(f); }
541-
}
542-
543502
// Double-check that we never ask LLVM to declare the same symbol twice. It
544503
// silently mangles such symbols, breaking our linkage model.
545504
pub fn note_unique_llvm_symbol(ccx: &mut CrateContext, sym: @str) {

branches/dist-snap/src/librustc/middle/trans/glue.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,6 @@ pub fn declare_generic_glue(ccx: &mut CrateContext, t: ty::t, llfnty: Type,
674674
debug!("{} is for type {}", fn_nm, ppaux::ty_to_str(ccx.tcx, t));
675675
note_unique_llvm_symbol(ccx, fn_nm);
676676
let llfn = decl_cdecl_fn(ccx.llmod, fn_nm, llfnty);
677-
set_glue_inlining(llfn, t);
678677
return llfn;
679678
}
680679

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
//! This is a basic event loop implementation not meant for any "real purposes"
12+
//! other than testing the scheduler and proving that it's possible to have a
13+
//! pluggable event loop.
14+
15+
use prelude::*;
16+
17+
use cast;
18+
use rt::rtio::{EventLoop, IoFactory, RemoteCallback, PausibleIdleCallback};
19+
use unstable::sync::Exclusive;
20+
use util;
21+
22+
/// This is the only exported function from this module.
23+
pub fn event_loop() -> ~EventLoop {
24+
~BasicLoop::new() as ~EventLoop
25+
}
26+
27+
struct BasicLoop {
28+
work: ~[~fn()], // pending work
29+
idle: Option<*BasicPausible>, // only one is allowed
30+
remotes: ~[(uint, ~fn())],
31+
next_remote: uint,
32+
messages: Exclusive<~[Message]>
33+
}
34+
35+
enum Message { RunRemote(uint), RemoveRemote(uint) }
36+
37+
struct Time {
38+
sec: u64,
39+
nsec: u64,
40+
}
41+
42+
impl Ord for Time {
43+
fn lt(&self, other: &Time) -> bool {
44+
self.sec < other.sec || self.nsec < other.nsec
45+
}
46+
}
47+
48+
impl BasicLoop {
49+
fn new() -> BasicLoop {
50+
BasicLoop {
51+
work: ~[],
52+
idle: None,
53+
next_remote: 0,
54+
remotes: ~[],
55+
messages: Exclusive::new(~[]),
56+
}
57+
}
58+
59+
/// Process everything in the work queue (continually)
60+
fn work(&mut self) {
61+
while self.work.len() > 0 {
62+
for work in util::replace(&mut self.work, ~[]).move_iter() {
63+
work();
64+
}
65+
}
66+
}
67+
68+
fn remote_work(&mut self) {
69+
let messages = unsafe {
70+
do self.messages.with |messages| {
71+
if messages.len() > 0 {
72+
Some(util::replace(messages, ~[]))
73+
} else {
74+
None
75+
}
76+
}
77+
};
78+
let messages = match messages {
79+
Some(m) => m, None => return
80+
};
81+
for message in messages.iter() {
82+
self.message(*message);
83+
}
84+
}
85+
86+
fn message(&mut self, message: Message) {
87+
match message {
88+
RunRemote(i) => {
89+
match self.remotes.iter().find(|& &(id, _)| id == i) {
90+
Some(&(_, ref f)) => (*f)(),
91+
None => unreachable!()
92+
}
93+
}
94+
RemoveRemote(i) => {
95+
match self.remotes.iter().position(|&(id, _)| id == i) {
96+
Some(i) => { self.remotes.remove(i); }
97+
None => unreachable!()
98+
}
99+
}
100+
}
101+
}
102+
103+
/// Run the idle callback if one is registered
104+
fn idle(&mut self) {
105+
unsafe {
106+
match self.idle {
107+
Some(idle) => {
108+
if (*idle).active {
109+
(*(*idle).work.get_ref())();
110+
}
111+
}
112+
None => {}
113+
}
114+
}
115+
}
116+
117+
fn has_idle(&self) -> bool {
118+
unsafe { self.idle.is_some() && (**self.idle.get_ref()).active }
119+
}
120+
}
121+
122+
impl EventLoop for BasicLoop {
123+
fn run(&mut self) {
124+
// Not exactly efficient, but it gets the job done.
125+
while self.remotes.len() > 0 || self.work.len() > 0 || self.has_idle() {
126+
127+
self.work();
128+
self.remote_work();
129+
130+
if self.has_idle() {
131+
self.idle();
132+
continue
133+
}
134+
135+
unsafe {
136+
// We block here if we have no messages to process and we may
137+
// receive a message at a later date
138+
do self.messages.hold_and_wait |messages| {
139+
self.remotes.len() > 0 &&
140+
messages.len() == 0 &&
141+
self.work.len() == 0
142+
}
143+
}
144+
}
145+
}
146+
147+
fn callback(&mut self, f: ~fn()) {
148+
self.work.push(f);
149+
}
150+
151+
// XXX: Seems like a really weird requirement to have an event loop provide.
152+
fn pausible_idle_callback(&mut self) -> ~PausibleIdleCallback {
153+
let callback = ~BasicPausible::new(self);
154+
rtassert!(self.idle.is_none());
155+
unsafe {
156+
let cb_ptr: &*BasicPausible = cast::transmute(&callback);
157+
self.idle = Some(*cb_ptr);
158+
}
159+
return callback as ~PausibleIdleCallback;
160+
}
161+
162+
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback {
163+
let id = self.next_remote;
164+
self.next_remote += 1;
165+
self.remotes.push((id, f));
166+
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
167+
}
168+
169+
/// This has no bindings for local I/O
170+
fn io<'a>(&'a mut self, _: &fn(&'a mut IoFactory)) {}
171+
}
172+
173+
struct BasicRemote {
174+
queue: Exclusive<~[Message]>,
175+
id: uint,
176+
}
177+
178+
impl BasicRemote {
179+
fn new(queue: Exclusive<~[Message]>, id: uint) -> BasicRemote {
180+
BasicRemote { queue: queue, id: id }
181+
}
182+
}
183+
184+
impl RemoteCallback for BasicRemote {
185+
fn fire(&mut self) {
186+
unsafe {
187+
do self.queue.hold_and_signal |queue| {
188+
queue.push(RunRemote(self.id));
189+
}
190+
}
191+
}
192+
}
193+
194+
impl Drop for BasicRemote {
195+
fn drop(&mut self) {
196+
unsafe {
197+
do self.queue.hold_and_signal |queue| {
198+
queue.push(RemoveRemote(self.id));
199+
}
200+
}
201+
}
202+
}
203+
204+
struct BasicPausible {
205+
eloop: *mut BasicLoop,
206+
work: Option<~fn()>,
207+
active: bool,
208+
}
209+
210+
impl BasicPausible {
211+
fn new(eloop: &mut BasicLoop) -> BasicPausible {
212+
BasicPausible {
213+
active: false,
214+
work: None,
215+
eloop: eloop,
216+
}
217+
}
218+
}
219+
220+
impl PausibleIdleCallback for BasicPausible {
221+
fn start(&mut self, f: ~fn()) {
222+
rtassert!(!self.active && self.work.is_none());
223+
self.active = true;
224+
self.work = Some(f);
225+
}
226+
fn pause(&mut self) {
227+
self.active = false;
228+
}
229+
fn resume(&mut self) {
230+
self.active = true;
231+
}
232+
fn close(&mut self) {
233+
self.active = false;
234+
self.work = None;
235+
}
236+
}
237+
238+
impl Drop for BasicPausible {
239+
fn drop(&mut self) {
240+
unsafe {
241+
(*self.eloop).idle = None;
242+
}
243+
}
244+
}
245+
246+
fn time() -> Time {
247+
#[fixed_stack_segment]; #[inline(never)];
248+
extern {
249+
fn get_time(sec: &mut i64, nsec: &mut i32);
250+
}
251+
let mut sec = 0;
252+
let mut nsec = 0;
253+
unsafe { get_time(&mut sec, &mut nsec) }
254+
255+
Time { sec: sec as u64, nsec: nsec as u64 }
256+
}

0 commit comments

Comments
 (0)