Module rtic::mutex_prelude
source · Expand description
Makes locks work on N-tuples, locks the mutexes from left-to-right in the tuple. These are used to reduce rightward drift in code and to help make intentions clearer.
§Example
use rtic_core::prelude::*;
fn normal_lock(
a: &mut impl Mutex<T = i32>,
b: &mut impl Mutex<T = i32>,
c: &mut impl Mutex<T = i32>
) {
// A lot of rightward drift...
a.lock(|a| {
b.lock(|b| {
c.lock(|c| {
*a += 1;
*b += 1;
*c += 1;
});
});
});
}
Has a shorthand as:
use rtic_core::prelude::*;
fn tuple_lock(
a: &mut impl Mutex<T = i32>,
b: &mut impl Mutex<T = i32>,
c: &mut impl Mutex<T = i32>
) {
// Look! Single indent and less to write
(a, b, c).lock(|a, b, c| {
*a += 1;
*b += 1;
*c += 1;
});
}
Traits§
- Memory safe access to shared resources
- Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details. - Auto-generated tuple implementation, see
Mutex
for details.