macro_rules! rumtk_critical_section_write {
( $lock:expr, $function:expr ) => { ... };
}Expand description
Using a standard spin lock SafeLock, lock it and execute the critical section. The critical section itself is a synchronous function or closure. In this case, the critical section attempts to modify the internal state of a guarded dataset.
ยงExample
use rumtk_core::{rumtk_new_lock, rumtk_critical_section_write};
let data = 5;
let new_data = 10;
let lock = rumtk_new_lock!(data);
let result = rumtk_critical_section_write!(
lock,
|mut guard| {
*guard = new_data;
}
);
assert_eq!(result, (), "Critical section yielded invalid result!");