mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #14835 - bholley:external_atomic_refcell, r=Manishearth
Switch to crates.io for atomic_refcell r? @Manishearth See #14828 for backstory. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14835) <!-- Reviewable:end -->
This commit is contained in:
commit
1e927ca88b
21 changed files with 30 additions and 481 deletions
|
@ -1,127 +0,0 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use style::atomic_refcell::{AtomicRef, AtomicRefCell, AtomicRefMut};
|
||||
use test::Bencher;
|
||||
|
||||
struct Foo {
|
||||
u: u32,
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
f: Foo,
|
||||
}
|
||||
|
||||
impl Default for Bar {
|
||||
fn default() -> Self {
|
||||
Bar { f: Foo { u: 42 } }
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME(bholley): Add tests to exercise this in concurrent scenarios.
|
||||
|
||||
#[test]
|
||||
fn immutable() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow();
|
||||
let _second = a.borrow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mutable() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _ = a.borrow_mut();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interleaved() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
{
|
||||
let _ = a.borrow_mut();
|
||||
}
|
||||
{
|
||||
let _first = a.borrow();
|
||||
let _second = a.borrow();
|
||||
}
|
||||
{
|
||||
let _ = a.borrow_mut();
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "already immutably borrowed")]
|
||||
fn immutable_then_mutable() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow();
|
||||
let _second = a.borrow_mut();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "already mutably borrowed")]
|
||||
fn mutable_then_immutable() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow_mut();
|
||||
let _second = a.borrow();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(expected = "already mutably borrowed")]
|
||||
fn double_mutable() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow_mut();
|
||||
let _second = a.borrow_mut();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let b = a.borrow();
|
||||
assert_eq!(b.f.u, 42);
|
||||
let c = AtomicRef::map(b, |x| &x.f);
|
||||
assert_eq!(c.u, 42);
|
||||
let d = AtomicRef::map(c, |x| &x.u);
|
||||
assert_eq!(*d, 42);
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn immutable_borrow(b: &mut Bencher) {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
b.iter(|| a.borrow());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn immutable_second_borrow(b: &mut Bencher) {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow();
|
||||
b.iter(|| a.borrow());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn immutable_third_borrow(b: &mut Bencher) {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let _first = a.borrow();
|
||||
let _second = a.borrow();
|
||||
b.iter(|| a.borrow());
|
||||
}
|
||||
|
||||
#[bench]
|
||||
fn mutable_borrow(b: &mut Bencher) {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
b.iter(|| a.borrow_mut());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn map_mut() {
|
||||
let a = AtomicRefCell::new(Bar::default());
|
||||
let mut b = a.borrow_mut();
|
||||
assert_eq!(b.f.u, 42);
|
||||
b.f.u = 43;
|
||||
let mut c = AtomicRefMut::map(b, |x| &mut x.f);
|
||||
assert_eq!(c.u, 43);
|
||||
c.u = 44;
|
||||
let mut d = AtomicRefMut::map(c, |x| &mut x.u);
|
||||
assert_eq!(*d, 44);
|
||||
*d = 45;
|
||||
assert_eq!(*d, 45);
|
||||
}
|
|
@ -23,7 +23,6 @@ extern crate style_traits;
|
|||
extern crate test;
|
||||
|
||||
mod animated_properties;
|
||||
mod atomic_refcell;
|
||||
mod attr;
|
||||
mod cache;
|
||||
mod logical_geometry;
|
||||
|
|
|
@ -13,6 +13,7 @@ doctest = false
|
|||
|
||||
[dependencies]
|
||||
app_units = "0.3"
|
||||
atomic_refcell = "0.1"
|
||||
cssparser = {version = "0.7"}
|
||||
env_logger = "0.3"
|
||||
euclid = "0.10.1"
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
extern crate app_units;
|
||||
extern crate atomic_refcell;
|
||||
extern crate cssparser;
|
||||
extern crate env_logger;
|
||||
extern crate euclid;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue