preempt_rt/lib.rs
1//! Rust friendly bindings to the scheduler related functionality in libc.
2//!
3//! The `sched` module contains types and lightweight wrappers around libc functions. For example:
4//! ```rust,no_run
5//! use preempt_rt::sched;
6//! use preempt_rt::sched::{Pid, Scheduler, SchedulerParams};
7//! let sched = sched::get_scheduler(Pid::current_thread()).unwrap();
8//! sched::set_scheduler(Pid::current_thread(), Scheduler::SCHED_FIFO, SchedulerParams {
9//! priority: 80
10//! }).expect("failed to set scheduler");
11//! ```
12//!
13//! The `thread` module has wrappers around `thread::spawn` for creating threads with a given
14//! scheduler and priority.
15//!
16//! ```rust,no_run
17//! use preempt_rt::sched::{RtResult, Scheduler};
18//! use preempt_rt::thread;
19//! thread::spawn(Scheduler::SCHED_FIFO, 80, move || {
20//! println!("this code is running on a thread with fifo scheduler & priority of 80");
21//! });
22//! // setting scheduler requires linux + preempt_rt kernel + appropriate permissions so may fail
23//! thread::try_spawn(Scheduler::SCHED_FIFO, 80, move |sched_result| {
24//! match sched_result {
25//! Ok(()) => {}
26//! Err(e) => eprintln!("failed to set scheduler: {e}")
27//! }
28//! });
29//! ```
30pub mod sched;
31pub mod thread;