mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
register_space: use sync::Mutex instead of std::sync::Mutex
Then we don't need to unwrap BUG=chromium:831850 TEST=cargo test CQ-DEPEND=CL:1506828 Change-Id: I4200ea6351d61df1974e5e4c8583e783b21ea0eb Reviewed-on: https://chromium-review.googlesource.com/1509514 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Jingkui Wang <jkwang@google.com> Reviewed-by: Jingkui Wang <jkwang@google.com>
This commit is contained in:
parent
b771521aa6
commit
9fc96ec8fb
2 changed files with 11 additions and 9 deletions
|
@ -6,7 +6,8 @@ use std;
|
|||
use std::boxed::Box;
|
||||
use std::cmp::{max, min, Ord, Ordering, PartialEq, PartialOrd};
|
||||
use std::mem::size_of;
|
||||
use std::sync::{Arc, Mutex, MutexGuard};
|
||||
use std::sync::{Arc, MutexGuard};
|
||||
use sync::Mutex;
|
||||
|
||||
use data_model::DataInit;
|
||||
|
||||
|
@ -216,7 +217,7 @@ impl<T: RegisterValue> Register<T> {
|
|||
}
|
||||
|
||||
fn lock(&self) -> MutexGuard<RegisterInner<T>> {
|
||||
self.inner.lock().expect("fail to lock register")
|
||||
self.inner.lock()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,16 +563,16 @@ mod tests {
|
|||
|
||||
let s2 = state.clone();
|
||||
r.set_write_cb(move |val: u8| {
|
||||
*s2.lock().unwrap() = val as u8;
|
||||
*s2.lock() = val as u8;
|
||||
val
|
||||
});
|
||||
let data: [u8; 4] = [0, 0, 0, 0xff];
|
||||
r.write_bar(0, &data);
|
||||
assert_eq!(*state.lock().unwrap(), 0xf);
|
||||
assert_eq!(*state.lock(), 0xf);
|
||||
r.set_value(0xab);
|
||||
assert_eq!(*state.lock().unwrap(), 0xf);
|
||||
assert_eq!(*state.lock(), 0xf);
|
||||
let data: [u8; 1] = [0xfc];
|
||||
r.write_bar(3, &data);
|
||||
assert_eq!(*state.lock().unwrap(), 0xc);
|
||||
assert_eq!(*state.lock(), 0xc);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,8 @@ impl MMIOSpace {
|
|||
mod tests {
|
||||
use super::super::{RegisterSpec, StaticRegister, StaticRegisterSpec};
|
||||
use super::*;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Arc;
|
||||
use sync::Mutex;
|
||||
|
||||
#[test]
|
||||
fn mmio_no_reg() {
|
||||
|
@ -216,7 +217,7 @@ mod tests {
|
|||
mmio.add_register(reg.clone());
|
||||
let state_clone = state.clone();
|
||||
reg.set_write_cb(move |val: u32| {
|
||||
*state_clone.lock().unwrap() = val;
|
||||
*state_clone.lock() = val;
|
||||
val
|
||||
});
|
||||
|
||||
|
@ -224,7 +225,7 @@ mod tests {
|
|||
mmio.read_bar(0, &mut data);
|
||||
assert_eq!([8, 7, 0xdd, 0xcc, 0xbb, 0xaa, 2, 1], data);
|
||||
mmio.write_bar(0, &[0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
assert_eq!(0xaa0bccd0, *state.lock().unwrap());
|
||||
assert_eq!(0xaa0bccd0, *state.lock());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue