rtic/
lib.rs

1//! Real-Time Interrupt-driven Concurrency (RTIC) framework for real-time Linux
2//!
3//! **IMPORTANT**: This crate is published as [`linux-rtic`] on crates.io but the name of the
4//! library is `rtic`.
5//!
6//! [`linux-rtic`]: https://crates.io/crates/linux-rtic
7//!
8//! The user level documentation is limited, but can be found in README and examples.
9//!
10
11pub use ctrlc;
12pub use futex_queue as mpsc;
13pub use lazy_static;
14pub use linux_rtic_macros::app;
15pub use pcp_mutex::PcpMutex;
16pub use rtic_core::{prelude as mutex_prelude, Exclusive, Mutex};
17
18use std::cell::UnsafeCell;
19
20#[cfg(feature = "profiling")]
21pub use tracing;
22#[cfg(feature = "profiling")]
23pub use tracing_chrome;
24#[cfg(feature = "profiling")]
25pub use tracing_subscriber;
26
27pub mod slab;
28
29pub fn init_thread_state(priority: pcp_mutex::Priority) {
30    #[cfg(feature = "rt")]
31    pcp_mutex::thread::init_fifo_priority(priority).expect("Error setting thread priority");
32}
33
34/// Internal replacement for `static mut T`
35#[repr(transparent)]
36pub struct RacyCell<T>(UnsafeCell<T>);
37
38impl<T> RacyCell<T> {
39    /// Create a RacyCell
40    #[inline(always)]
41    pub const fn new(value: T) -> Self {
42        RacyCell(UnsafeCell::new(value))
43    }
44
45    /// Get `&mut T`
46    #[inline(always)]
47    pub unsafe fn get_mut_unchecked(&self) -> &mut T {
48        &mut *self.0.get()
49    }
50
51    /// Get `&T`
52    #[inline(always)]
53    pub unsafe fn get_unchecked(&self) -> &T {
54        &*self.0.get()
55    }
56}
57
58unsafe impl<T> Sync for RacyCell<T> {}