cros_sync_hack/lib.rs
1// Copyright 2018 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! Sync primitive types whose methods panic rather than returning error in case of poison.
6//!
7//! The Mutex/Condvar type in this crates wraps the standard library versions and mirrors the same
8//! methods, except that they panic where the standard library would return an Error. This API
9//! codifies our error handling strategy around poisoned mutexes in crosvm.
10//!
11//! - Crosvm releases are built with panic=abort so poisoning never occurs. A panic while a mutex is
12//! held (or ever) takes down the entire process. Thus we would like for code not to have to
13//! consider the possibility of poison.
14//!
15//! - We could ask developers to always write `.lock().unwrap()` on a standard library mutex.
16//! However, we would like to stigmatize the use of unwrap. It is confusing to permit unwrap but
17//! only on mutex lock results. During code review it may not always be obvious whether a
18//! particular unwrap is unwrapping a mutex lock result or a different error that should be
19//! handled in a more principled way.
20//!
21//! Developers should feel free to use types defined in this crate anywhere in crosvm that they
22//! would otherwise be using the corresponding types in std::sync.
23
24mod condvar;
25mod mutex;
26
27pub use crate::condvar::Condvar;
28pub use crate::mutex::Mutex;
29pub use crate::mutex::WouldBlock;