Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions embassy-executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ build = [
{target = "riscv32imac-unknown-none-elf", features = ["platform-riscv32"]},
{target = "riscv32imac-unknown-none-elf", features = ["platform-riscv32", "executor-thread"]},
{target = "riscv32imac-unknown-none-elf", features = ["platform-riscv32", "executor-thread", "trace"]},
{target = "riscv32imc-unknown-none-elf", features = ["platform-riscv32", "executor-thread", "rtos-trace"]},
{target = "riscv64imac-unknown-none-elf", features = ["platform-riscv64"]},
{target = "riscv64imac-unknown-none-elf", features = ["platform-riscv64", "executor-thread"]},
{target = "riscv64imac-unknown-none-elf", features = ["platform-riscv64", "executor-thread", "trace"]},
Expand Down
14 changes: 12 additions & 2 deletions embassy-executor/src/raw/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ impl TaskTracker {
/// Adds a task to the tracker
///
/// This method inserts a task at the head of the intrusive linked list.
/// The operation is thread-safe and lock-free, using atomic operations
/// to ensure consistency even when called from different contexts.
/// The operation is lock-free on targets with pointer compare-and-swap.
/// On targets without it, insertions are serialized by a critical section.
///
/// # Arguments
/// * `task` - The task reference to add to the tracker
pub fn add(&self, task: TaskRef) {
let task_ptr = task.as_ptr();

#[cfg(target_has_atomic = "ptr")]
loop {
let current_head = self.head.load(Ordering::Acquire);
unsafe {
Expand All @@ -144,6 +145,15 @@ impl TaskTracker {
break;
}
}

#[cfg(not(target_has_atomic = "ptr"))]
critical_section::with(|_| {
let current_head = self.head.load(Ordering::Acquire);
unsafe {
(*task_ptr).all_tasks_next.store(current_head, Ordering::Relaxed);
}
self.head.store(task_ptr.cast_mut(), Ordering::Release);
});
}

/// Performs an operation on each task in the tracker
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ targets = [
"thumbv7em-none-eabihf",
"thumbv8m.main-none-eabihf",
"riscv32imac-unknown-none-elf",
"riscv32imc-unknown-none-elf",
"riscv64imac-unknown-none-elf",
"riscv64gc-unknown-none-elf",
"wasm32-unknown-unknown",
Expand Down