diff options
author | David Tolnay <dtolnay@chromium.org> | 2018-12-03 23:37:46 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-12-05 01:13:41 -0800 |
commit | 1d4d44a8e229d63aa16d05615ed33100f949863e (patch) | |
tree | 773bb9b2e6eb29b64d0d68e4985c6e2daf3bb7cc /aarch64 | |
parent | 2ea8f3d0aa7230da41b3e6beba27ff9140f661d3 (diff) | |
download | crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar.gz crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar.bz2 crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar.lz crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar.xz crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.tar.zst crosvm-1d4d44a8e229d63aa16d05615ed33100f949863e.zip |
sync: Mutex type with methods that panic instead of return error
This CL adds a crate `sync` containing a type sync::Mutex which wraps the standard library Mutex and mirrors the same methods, except that they panic where the standard library would return a PoisonError. This API codifies our error handling strategy around poisoned mutexes in crosvm. - Crosvm releases are built with panic=abort so poisoning never occurs. A panic while a mutex is held (or ever) takes down the entire process. Thus we would like for code not to have to consider the possibility of poison. - We could ask developers to always write `.lock().unwrap()` on a standard library mutex. However, we would like to stigmatize the use of unwrap. It is confusing to permit unwrap but only on mutex lock results. During code review it may not always be obvious whether a particular unwrap is unwrapping a mutex lock result or a different error that should be handled in a more principled way. Developers should feel free to use sync::Mutex anywhere in crosvm that they would otherwise be using std::sync::Mutex. TEST=boot linux Change-Id: I9727b6f8fee439edb4a8d52cf19d59acf04d990f Reviewed-on: https://chromium-review.googlesource.com/1359923 Commit-Ready: David Tolnay <dtolnay@chromium.org> Tested-by: David Tolnay <dtolnay@chromium.org> Reviewed-by: Zach Reizner <zachr@chromium.org>
Diffstat (limited to 'aarch64')
-rw-r--r-- | aarch64/Cargo.toml | 1 | ||||
-rw-r--r-- | aarch64/src/lib.rs | 4 |
2 files changed, 4 insertions, 1 deletions
diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml index 5845982..ab5bf55 100644 --- a/aarch64/Cargo.toml +++ b/aarch64/Cargo.toml @@ -13,5 +13,6 @@ kvm_sys = { path = "../kvm_sys" } kvm = { path = "../kvm" } sys_util = { path = "../sys_util" } resources = { path = "../resources" } +sync = { path = "../sync" } libc = "*" byteorder = "*" diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs index fe80534..7c15ef1 100644 --- a/aarch64/src/lib.rs +++ b/aarch64/src/lib.rs @@ -12,6 +12,7 @@ extern crate kvm; extern crate kvm_sys; extern crate libc; extern crate resources; +extern crate sync; extern crate sys_util; use std::error::{self, Error as Aarch64Error}; @@ -20,12 +21,13 @@ use std::fmt::{self, Display}; use std::fs::File; use std::io::{self, stdout}; use std::os::unix::io::FromRawFd; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use arch::{RunnableLinuxVm, VmComponents}; use devices::{Bus, BusError, PciConfigMmio, PciDevice, PciInterruptPin}; use io_jail::Minijail; use resources::{AddressRanges, SystemAllocator}; +use sync::Mutex; use sys_util::{EventFd, GuestAddress, GuestMemory}; use kvm::*; |