API referencestd/embedded

std/embedded/sync

Public declarations, types, methods, and source contracts for std/embedded/sync.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/embedded/sync"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
cpu core/cpu sync.dodo
hal std/embedded/hal sync.dodo
ptr core/ptr sync.dodo

set_core_lock

Function · Source

Install the lock that keeps the other cores out of every section: a chip’s multicore support calls this before it starts a second core. acquire is called with interrupts masked and waits until the calling core holds the lock; release frees it. SAFETY: call while only one core runs, outside any section.

pub unsafe fn set_core_lock(acquire: fn(), release: fn())

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

has_core_lock

Function · Source

True once a cross-core lock is installed.

pub fn has_core_lock() -> bool

abandon_core

Function · Source

Forget the sections that a stopped core held, releasing the cross-core lock if it held that: a chip calls this after holding a core in reset. SAFETY: core stopped must be stopped, and its sections never resumed.

pub unsafe fn abandon_core(stopped: u32)

Requires an unsafe context. Follow the source safety preconditions and the linked guide before calling this API.

Section

Struct · Source

The system-wide critical section that mutexes lock through; see the package comment. It ends when dropped, and sections nest.

pub struct Section {
    // Private implementation fields omitted.
}

enter

Function · Source

Enter the system-wide critical section: mask interrupts on this core and, with a cross-core lock installed, wait until no other core is in a section.

pub fn enter() -> Section

Mutex

Struct · Source

A value that interrupt handlers, tasks, and cores share; see the package comment. Declare it in a plain static, initialized with Mutex.new.

pub struct Mutex<T> {
    // Private implementation fields omitted.
}

Mutex.new

Function · Source

pub fn new(value: T) -> Mutex<T>

Mutex.lock

Function · Source

Exclusive access to the value until the guard is dropped, inside a section. Traps if this core holds the mutex already.

pub fn lock(&self) -> Guard<T> from(self)

Mutex.try_lock

Function · Source

Exclusive access to the value if this core does not hold the mutex already, for code that may run while it does: none instead of trapping.

pub fn try_lock(&self) -> Option<Guard<T>> from(self)

Mutex.with

Function · Source

Run action on the value while holding the mutex. A result leaves through a local the closure changes.

pub fn with(&self, action: &mut dyn fn(&mut T))

Mutex.replace

Function · Source

Store value and return the one it replaces.

pub fn replace(&self, value: T) -> T

Mutex.set

Function · Source

Store value, dropping the one it replaces outside the section.

pub fn set(&self, value: T)

Mutex.is_locked

Function · Source

True while some code holds the mutex.

pub fn is_locked(&self) -> bool

Guard

Struct · Source

A held mutex, from Mutex.lock or try_lock. Dropping it unlocks the mutex, then ends the section, unmasking interrupts if they were enabled before.

pub struct Guard<T> {
    // Private implementation fields omitted.
}

Guard.get

Function · Source

pub fn get(&self) -> &T from(self)

Guard.get_mut

Function · Source

pub fn get_mut(&mut self) -> &mut T from(self)

Guard.set

Function · Source

Store value in the held mutex, dropping the old one.

pub fn set(&mut self, value: T)

Search every guide, reference page, and API declaration.