rtic/
lib.rs

1//! Real-Time Interrupt-driven Concurrency (RTIC) framework for ARM Cortex-M microcontrollers.
2//!
3//! The user level documentation can be found [here].
4//!
5//! [here]: https://rtic.rs
6//!
7//! Don't forget to check the documentation of the `#[app]` attribute (listed under the reexports
8//! section), which is the main component of the framework.
9//!
10//! # Minimum Supported Rust Version (MSRV)
11//!
12//! This crate is compiled and tested with the latest stable toolchain (rolling).
13//! If you run into compilation errors, try the latest stable release of the rust toolchain.
14//!
15//! # Semantic Versioning
16//!
17//! Like the Rust project, this crate adheres to [SemVer]: breaking changes in the API and semantics
18//! require a *semver bump* (since 1.0.0 a new major version release), with the exception of breaking changes
19//! that fix soundness issues -- those are considered bug fixes and can be landed in a new patch
20//! release.
21//!
22//! [SemVer]: https://semver.org/spec/v2.0.0.html
23
24#![deny(missing_docs)]
25#![deny(rust_2021_compatibility)]
26#![deny(rust_2018_compatibility)]
27#![deny(rust_2018_idioms)]
28#![no_std]
29#![doc(
30    html_logo_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg",
31    html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/rtic/master/book/en/src/RTIC.svg"
32)]
33#![allow(clippy::inline_always)]
34#![allow(unexpected_cfgs)]
35
36pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex};
37pub use rtic_macros::app;
38
39/// module `mutex::prelude` provides `Mutex` and multi-lock variants. Recommended over `mutex_prelude`
40pub mod mutex {
41    pub use rtic_core::prelude;
42    pub use rtic_core::Mutex;
43}
44
45#[doc(hidden)]
46pub mod export;
47
48pub use export::pend;
49
50use core::cell::UnsafeCell;
51
52/// Internal replacement for `static mut T`
53///
54/// Used to represent RTIC Resources
55///
56/// Soundness:
57/// 1) Unsafe API for internal use only
58/// 2) ``get_mut(&self) -> *mut T``
59///    returns a raw mutable pointer to the inner T
60///    casting to &mut T is under control of RTIC
61///    RTIC ensures &mut T to be unique under Rust aliasing rules.
62///
63///    Implementation uses the underlying ``UnsafeCell<T>``
64///    self.0.get() -> *mut T
65///
66/// 3) get(&self) -> *const T
67///    returns a raw immutable (const) pointer to the inner T
68///    casting to &T is under control of RTIC
69///    RTIC ensures &T to be shared under Rust aliasing rules.
70///
71///    Implementation uses the underlying ``UnsafeCell<T>``
72///    self.0.get() -> *mut T, demoted to *const T
73///
74#[repr(transparent)]
75pub struct RacyCell<T>(UnsafeCell<T>);
76
77impl<T> RacyCell<T> {
78    /// Create a ``RacyCell``
79    #[inline(always)]
80    pub const fn new(value: T) -> Self {
81        RacyCell(UnsafeCell::new(value))
82    }
83
84    /// Get `*mut T`
85    ///
86    /// # Safety
87    ///
88    /// See documentation notes for [`RacyCell`]
89    #[inline(always)]
90    pub unsafe fn get_mut(&self) -> *mut T {
91        self.0.get()
92    }
93
94    /// Get `*const T`
95    ///
96    /// # Safety
97    ///
98    /// See documentation notes for [`RacyCell`]
99    #[inline(always)]
100    pub unsafe fn get(&self) -> *const T {
101        self.0.get()
102    }
103}
104
105unsafe impl<T> Sync for RacyCell<T> {}