Skip to content

Commit 5163a26

Browse files
committed
test: Update all tests with the sync changes
1 parent eff0257 commit 5163a26

27 files changed

+80
-324
lines changed

src/doc/guide-tasks.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ fn main() {
359359
360360
spawn(proc() {
361361
let local_arc : Arc<~[f64]> = rx.recv();
362-
let task_numbers = local_arc.get();
362+
let task_numbers = &*local_arc;
363363
println!("{}-norm = {}", num, pnorm(task_numbers, num));
364364
});
365365
}
@@ -411,7 +411,7 @@ Each task recovers the underlying data by
411411
# let (tx, rx) = channel();
412412
# tx.send(numbers_arc.clone());
413413
# let local_arc : Arc<~[f64]> = rx.recv();
414-
let task_numbers = local_arc.get();
414+
let task_numbers = &*local_arc;
415415
# }
416416
~~~
417417

src/librustdoc/html/format.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
208208
let loc = loc.unwrap();
209209

210210
local_data::get(cache_key, |cache| {
211-
let cache = cache.unwrap().get();
212-
let abs_root = root(cache, loc.as_slice());
211+
let cache = cache.unwrap();
212+
let abs_root = root(&**cache, loc.as_slice());
213213
let rel_root = match path.segments.get(0).name.as_slice() {
214214
"self" => Some(~"./"),
215215
_ => None,
@@ -241,7 +241,7 @@ fn path(w: &mut io::Writer, path: &clean::Path, print_all: bool,
241241
}
242242
}
243243

244-
match info(cache) {
244+
match info(&**cache) {
245245
// This is a documented path, link to it!
246246
Some((ref fqp, shortty)) if abs_root.is_some() => {
247247
let mut url = abs_root.unwrap();
@@ -301,7 +301,7 @@ impl fmt::Show for clean::Type {
301301
match *self {
302302
clean::TyParamBinder(id) | clean::Generic(id) => {
303303
local_data::get(cache_key, |cache| {
304-
let m = cache.unwrap().get();
304+
let m = cache.unwrap();
305305
f.buf.write(m.typarams.get(&id).as_bytes())
306306
})
307307
}

src/librustdoc/html/render.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ fn item_trait(w: &mut Writer, it: &clean::Item,
12651265
}
12661266

12671267
local_data::get(cache_key, |cache| {
1268-
let cache = cache.unwrap().get();
1268+
let cache = cache.unwrap();
12691269
match cache.implementors.find(&it.id) {
12701270
Some(implementors) => {
12711271
try!(write!(w, "
@@ -1496,7 +1496,7 @@ fn render_struct(w: &mut Writer, it: &clean::Item,
14961496

14971497
fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
14981498
local_data::get(cache_key, |cache| {
1499-
let c = cache.unwrap().get();
1499+
let c = cache.unwrap();
15001500
match c.impls.find(&it.id) {
15011501
Some(v) => {
15021502
let mut non_trait = v.iter().filter(|p| {
@@ -1576,7 +1576,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
15761576
Some(id) => id,
15771577
};
15781578
try!(local_data::get(cache_key, |cache| {
1579-
let cache = cache.unwrap().get();
1579+
let cache = cache.unwrap();
15801580
match cache.traits.find(&trait_id) {
15811581
Some(t) => {
15821582
let name = meth.name.clone();
@@ -1606,7 +1606,7 @@ fn render_impl(w: &mut Writer, i: &clean::Impl,
16061606
None => {}
16071607
Some(id) => {
16081608
try!(local_data::get(cache_key, |cache| {
1609-
let cache = cache.unwrap().get();
1609+
let cache = cache.unwrap();
16101610
match cache.traits.find(&id) {
16111611
Some(t) => {
16121612
for method in t.methods.iter() {

src/libworkcache/lib.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ extern crate sync;
2626
use serialize::json;
2727
use serialize::json::ToJson;
2828
use serialize::{Encoder, Encodable, Decoder, Decodable};
29-
use sync::{Arc,RWArc};
29+
use sync::{Arc, RWLock};
3030
use collections::TreeMap;
3131
use std::str;
3232
use std::io;
@@ -225,7 +225,7 @@ pub type FreshnessMap = TreeMap<~str,extern fn(&str,&str)->bool>;
225225

226226
#[deriving(Clone)]
227227
pub struct Context {
228-
db: RWArc<Database>,
228+
db: Arc<RWLock<Database>>,
229229
priv cfg: Arc<json::Object>,
230230
/// Map from kinds (source, exe, url, etc.) to a freshness function.
231231
/// The freshness function takes a name (e.g. file path) and value
@@ -269,12 +269,12 @@ fn json_decode<T:Decodable<json::Decoder>>(s: &str) -> T {
269269

270270
impl Context {
271271

272-
pub fn new(db: RWArc<Database>,
272+
pub fn new(db: Arc<RWLock<Database>>,
273273
cfg: Arc<json::Object>) -> Context {
274274
Context::new_with_freshness(db, cfg, Arc::new(TreeMap::new()))
275275
}
276276

277-
pub fn new_with_freshness(db: RWArc<Database>,
277+
pub fn new_with_freshness(db: Arc<RWLock<Database>>,
278278
cfg: Arc<json::Object>,
279279
freshness: Arc<FreshnessMap>) -> Context {
280280
Context {
@@ -364,7 +364,7 @@ impl<'a> Prep<'a> {
364364
fn is_fresh(&self, cat: &str, kind: &str,
365365
name: &str, val: &str) -> bool {
366366
let k = kind.to_owned();
367-
let f = self.ctxt.freshness.get().find(&k);
367+
let f = self.ctxt.freshness.deref().find(&k);
368368
debug!("freshness for: {}/{}/{}/{}", cat, kind, name, val)
369369
let fresh = match f {
370370
None => fail!("missing freshness-function for '{}'", kind),
@@ -406,9 +406,10 @@ impl<'a> Prep<'a> {
406406

407407
debug!("exec_work: looking up {} and {:?}", self.fn_name,
408408
self.declared_inputs);
409-
let cached = self.ctxt.db.read(|db| {
410-
db.prepare(self.fn_name, &self.declared_inputs)
411-
});
409+
let cached = {
410+
let db = self.ctxt.db.deref().read();
411+
db.deref().prepare(self.fn_name, &self.declared_inputs)
412+
};
412413

413414
match cached {
414415
Some((ref disc_in, ref disc_out, ref res))
@@ -460,13 +461,12 @@ impl<'a, T:Send +
460461
WorkFromTask(prep, port) => {
461462
let (exe, v) = port.recv();
462463
let s = json_encode(&v);
463-
prep.ctxt.db.write(|db| {
464-
db.cache(prep.fn_name,
465-
&prep.declared_inputs,
466-
&exe.discovered_inputs,
467-
&exe.discovered_outputs,
468-
s)
469-
});
464+
let mut db = prep.ctxt.db.deref().write();
465+
db.deref_mut().cache(prep.fn_name,
466+
&prep.declared_inputs,
467+
&exe.discovered_inputs,
468+
&exe.discovered_outputs,
469+
s);
470470
v
471471
}
472472
}
@@ -496,7 +496,7 @@ fn test() {
496496

497497
let db_path = make_path(~"db.json");
498498

499-
let cx = Context::new(RWArc::new(Database::new(db_path)),
499+
let cx = Context::new(Arc::new(RWLock::new(Database::new(db_path))),
500500
Arc::new(TreeMap::new()));
501501

502502
let s = cx.with_prep("test1", |prep| {

src/test/bench/msgsend-ring-mutex-arcs.rs

+10-18
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,28 @@
1818
extern crate sync;
1919
extern crate time;
2020

21-
use sync::Arc;
22-
use sync::MutexArc;
23-
use sync::Future;
21+
use sync::{Arc, Future, Mutex};
2422
use std::os;
2523
use std::uint;
2624

2725
// A poor man's pipe.
28-
type pipe = MutexArc<Vec<uint> >;
26+
type pipe = Arc<Mutex<Vec<uint>>>;
2927

3028
fn send(p: &pipe, msg: uint) {
31-
unsafe {
32-
p.access_cond(|state, cond| {
33-
state.push(msg);
34-
cond.signal();
35-
})
36-
}
29+
let mut arr = p.lock();
30+
arr.push(msg);
31+
arr.cond.signal();
3732
}
3833
fn recv(p: &pipe) -> uint {
39-
unsafe {
40-
p.access_cond(|state, cond| {
41-
while state.is_empty() {
42-
cond.wait();
43-
}
44-
state.pop().unwrap()
45-
})
34+
let mut arr = p.lock();
35+
while arr.is_empty() {
36+
arr.cond.wait();
4637
}
38+
arr.pop().unwrap()
4739
}
4840

4941
fn init() -> (pipe,pipe) {
50-
let m = MutexArc::new(Vec::new());
42+
let m = Arc::new(Mutex::new(Vec::new()));
5143
((&m).clone(), m)
5244
}
5345

src/test/bench/msgsend-ring-rw-arcs.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -18,31 +18,29 @@
1818
extern crate sync;
1919
extern crate time;
2020

21-
use sync::RWArc;
21+
use sync::{RWLock, Arc};
2222
use sync::Future;
2323
use std::os;
2424
use std::uint;
2525

2626
// A poor man's pipe.
27-
type pipe = RWArc<Vec<uint> >;
27+
type pipe = Arc<RWLock<Vec<uint>>>;
2828

2929
fn send(p: &pipe, msg: uint) {
30-
p.write_cond(|state, cond| {
31-
state.push(msg);
32-
cond.signal();
33-
})
30+
let mut arr = p.write();
31+
arr.push(msg);
32+
arr.cond.signal();
3433
}
3534
fn recv(p: &pipe) -> uint {
36-
p.write_cond(|state, cond| {
37-
while state.is_empty() {
38-
cond.wait();
39-
}
40-
state.pop().unwrap()
41-
})
35+
let mut arr = p.write();
36+
while arr.is_empty() {
37+
arr.cond.wait();
38+
}
39+
arr.pop().unwrap()
4240
}
4341

4442
fn init() -> (pipe,pipe) {
45-
let x = RWArc::new(Vec::new());
43+
let x = Arc::new(RWLock::new(Vec::new()));
4644
((&x).clone(), x)
4745
}
4846

src/test/bench/shootout-spectralnorm.rs

+18-17
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ use std::from_str::FromStr;
1414
use std::iter::count;
1515
use std::cmp::min;
1616
use std::os;
17-
use sync::RWArc;
17+
use std::slice::from_elem;
18+
use sync::{Arc, RWLock};
1819

1920
fn A(i: uint, j: uint) -> f64 {
2021
((i + j) * (i + j + 1) / 2 + i + 1) as f64
@@ -28,17 +29,16 @@ fn dot(v: &[f64], u: &[f64]) -> f64 {
2829
sum
2930
}
3031

31-
fn mult(v: RWArc<Vec<f64>>,
32-
out: RWArc<Vec<f64>>,
32+
fn mult(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>,
3333
f: fn(&Vec<f64>, uint) -> f64) {
34-
// We launch in different tasks the work to be done. To finish
34+
// We lanch in different tasks the work to be done. To finish
3535
// this fuction, we need to wait for the completion of every
3636
// tasks. To do that, we give to each tasks a wait_chan that we
3737
// drop at the end of the work. At the end of this function, we
3838
// wait until the channel hang up.
3939
let (tx, rx) = channel();
4040

41-
let len = out.read(|out| out.len());
41+
let len = out.read().len();
4242
let chunk = len / 100 + 1;
4343
for chk in count(0, chunk) {
4444
if chk >= len {break;}
@@ -47,8 +47,8 @@ fn mult(v: RWArc<Vec<f64>>,
4747
let out = out.clone();
4848
spawn(proc() {
4949
for i in range(chk, min(len, chk + chunk)) {
50-
let val = v.read(|v| f(v, i));
51-
out.write(|out| *out.get_mut(i) = val);
50+
let val = f(&*v.read(), i);
51+
*out.write().get_mut(i) = val;
5252
}
5353
drop(tx)
5454
});
@@ -67,7 +67,7 @@ fn mult_Av_impl(v: &Vec<f64> , i: uint) -> f64 {
6767
sum
6868
}
6969

70-
fn mult_Av(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
70+
fn mult_Av(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>) {
7171
mult(v, out, mult_Av_impl);
7272
}
7373

@@ -79,11 +79,12 @@ fn mult_Atv_impl(v: &Vec<f64> , i: uint) -> f64 {
7979
sum
8080
}
8181

82-
fn mult_Atv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >) {
82+
fn mult_Atv(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>) {
8383
mult(v, out, mult_Atv_impl);
8484
}
8585

86-
fn mult_AtAv(v: RWArc<Vec<f64> >, out: RWArc<Vec<f64> >, tmp: RWArc<Vec<f64> >) {
86+
fn mult_AtAv(v: Arc<RWLock<Vec<f64>>>, out: Arc<RWLock<Vec<f64>>>,
87+
tmp: Arc<RWLock<Vec<f64>>>) {
8788
mult_Av(v, tmp.clone());
8889
mult_Atv(tmp, out);
8990
}
@@ -97,16 +98,16 @@ fn main() {
9798
} else {
9899
FromStr::from_str(args[1]).unwrap()
99100
};
100-
let u = RWArc::new(Vec::from_elem(n, 1.));
101-
let v = RWArc::new(Vec::from_elem(n, 1.));
102-
let tmp = RWArc::new(Vec::from_elem(n, 1.));
101+
let u = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
102+
let v = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
103+
let tmp = Arc::new(RWLock::new(Vec::from_elem(n, 1.)));
103104
for _ in range(0, 10) {
104105
mult_AtAv(u.clone(), v.clone(), tmp.clone());
105106
mult_AtAv(v.clone(), u.clone(), tmp.clone());
106107
}
107108

108-
u.read(|u| v.read(|v| {
109-
println!("{:.9f}",
110-
(dot(u.as_slice(), v.as_slice()) / dot(v.as_slice(), v.as_slice())).sqrt());
111-
}))
109+
let u = u.read();
110+
let v = v.read();
111+
println!("{:.9f}", (dot(u.as_slice(), v.as_slice()) /
112+
dot(v.as_slice(), v.as_slice())).sqrt());
112113
}

src/test/compile-fail/arc-cant-nest-rw-arc-3177.rs

-17
This file was deleted.

src/test/compile-fail/arc-rw-cond-shouldnt-escape.rs

-19
This file was deleted.

0 commit comments

Comments
 (0)