diff options
author | Martin Robinson <mrobinson@igalia.com> | 2024-03-22 09:16:39 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 08:16:39 +0000 |
commit | 34dd38b4cbe0f35000c45683d0c65daa78a15644 (patch) | |
tree | 0dd28e2d317c39682a0694a82630e9879b2671ec /components/remutex/tests | |
parent | 8882507ad06b598fb43d8542c67ad76daeda739c (diff) | |
download | servo-34dd38b4cbe0f35000c45683d0c65daa78a15644.tar.gz servo-34dd38b4cbe0f35000c45683d0c65daa78a15644.zip |
Replace `remutex` with `parking_lot`'s `ReentrantMutex` (#31817)
Many things in Servo depend on `parking_lot`, so we can replace our
homegrown remutex with `parking_lot`'s version.
Fixes #12641.
Diffstat (limited to 'components/remutex/tests')
-rw-r--r-- | components/remutex/tests/smoke.rs | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/components/remutex/tests/smoke.rs b/components/remutex/tests/smoke.rs deleted file mode 100644 index 6d253e48501..00000000000 --- a/components/remutex/tests/smoke.rs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -// These tests came from https://github.com/rust-lang/rust/blob/master/src/libstd/sys/common/remutex.rs - -use std::cell::RefCell; -use std::sync::Arc; -use std::thread; - -use servo_remutex::{ReentrantMutex, ReentrantMutexGuard}; - -#[test] -fn smoke() { - let m = ReentrantMutex::new(()); - { - let a = m.lock().unwrap(); - { - let b = m.lock().unwrap(); - { - let c = m.lock().unwrap(); - assert_eq!(*c, ()); - } - assert_eq!(*b, ()); - } - assert_eq!(*a, ()); - } -} - -#[test] -fn is_mutex() { - let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); - let m2 = m.clone(); - let lock = m.lock().unwrap(); - let child = thread::spawn(move || { - let lock = m2.lock().unwrap(); - assert_eq!(*lock.borrow(), 4950); - }); - for i in 0..100 { - let lock = m.lock().unwrap(); - *lock.borrow_mut() += i; - } - drop(lock); - child.join().unwrap(); -} - -#[test] -fn trylock_works() { - let m = Arc::new(ReentrantMutex::new(())); - let m2 = m.clone(); - let _lock = m.try_lock().unwrap(); - let _lock2 = m.try_lock().unwrap(); - thread::spawn(move || { - let lock = m2.try_lock(); - assert!(lock.is_err()); - }) - .join() - .unwrap(); - let _lock3 = m.try_lock().unwrap(); -} - -pub struct Answer<'a>(pub ReentrantMutexGuard<'a, RefCell<u32>>); -impl<'a> Drop for Answer<'a> { - fn drop(&mut self) { - *self.0.borrow_mut() = 42; - } -} - -#[test] -fn poison_works() { - let m = Arc::new(ReentrantMutex::new(RefCell::new(0))); - let mc = m.clone(); - let result = thread::spawn(move || { - let lock = mc.lock().unwrap(); - *lock.borrow_mut() = 1; - let lock2 = mc.lock().unwrap(); - *lock.borrow_mut() = 2; - let _answer = Answer(lock2); - println!("Intentionally panicking."); - panic!("What the answer to my lifetimes dilemma is?"); - }) - .join(); - assert!(result.is_err()); - let r = m.lock().err().unwrap().into_inner(); - assert_eq!(*r.borrow(), 42); -} |