[][src]Module drone_core::thr

The Threads module.

NOTE A Drone platform crate may re-export this module with its own additions under the same name, in which case it should be used instead.

Drone is a hard real-time operating system. It uses interrupt-based preemptive priority scheduling, where tasks with same priorities are executed cooperatively. A task unit, called Fiber in Drone, is a stack-less co-routine programmed with Rust async/await and/or generator syntax.

A Drone application maps available prioritized interrupts to Drone threads. The number of threads is always static but configurable. Any number of fibers can be attached to particular threads, see fib for details. The Drone application configures its own thread type, which implements Thread, and creates a continuous array of this type.

use drone_core::thr;

thr! {
    // Path to the array of threads.
    array => THREADS;

    /// The thread object.
    thread => pub Thr {
        // You can add your own fields to the thread object. These fields will be
        // accessible through `to_thr` method of thread tokens. The types of
        // these fields should be `Sync`.
        pub foo: bool = false;
    };

    // This is a part of `Thr` that can be accessed with `thr::local` function.
    /// The thread-local storage.
    local => pub ThrLocal {
        // You can add your own fields here with the same syntax as above.
        // Note that the initializer uses the special `index` variable, that
        // has the value of the position of the thread within the threads array.
        // The types of these fields shouldn't necessarily be `Sync`.
        pub bar: usize = index;
    };
}

// This is for example only. Platform crates should provide macros to
// automatically generate this.
static mut THREADS: [Thr; 2] = [Thr::new(0), Thr::new(1)];

Modules

prelude

The Threads prelude.

Structs

PreemptedCell

Thread-local previous thread index cell.

Traits

ThrToken

The base trait for a thread token.

Thread

Generic thread.

ThreadLocal

Generic thread-local storage.

Functions

local

Returns a reference to the thread-local storage of the current thread.

thread_call

Runs the function f inside the thread number thr_idx.

thread_resume

Runs the fiber chain of the thread number thr_hum.