1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//! Abstractions for core-local storage.

/// A core-local storage cell.
///
/// This trait represents an architecture-specific mechanism for storing local
/// data for each CPU core.
pub trait CoreLocal<T: 'static> {
    /// Returns a new instance of `Self`, using the provided `init` function to
    /// generate the initial value for each CPU core.
    fn new(init: fn() -> T) -> Self;

    /// Accesses the value for the current CPU core.
    ///
    /// This method invokes the provided closure `f` with a reference to the
    /// `T`-typed local data for the current CPU core.
    fn with<F, U>(&self, f: F) -> U
    where
        F: FnOnce(&T) -> U;
}