* Add internal DynamicChannel trait implemented by Channel that allows
polling for internal state in a lock safe manner and does not require
knowing the channel size.
* Existing usage of Sender and Receiver is preserved and does not use
dynamic dispatch.
* Add DynamicSender and DynamicReceiver types that references the
channel using the DynamicChannel trait and does not require the const
generic channel size parameter.
696: Add async Mutex. r=Dirbaio a=Dirbaio
What it says on the tin :)
It allows sharing data between tasks when you want to `.await` stuff while holding it locked.
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
- Allow initializing in a static, without Forever.
- Remove ability to close, since in embedded enviromnents channels usually live forever and don't get closed.
- Remove MPSC restriction, it's MPMC now. Rename "mpsc" to "channel".
- `Sender` and `Receiver` are still available if you want to enforce a piece of code only has send/receive access, but are optional: you can send/receive directly into the Channel if you want.
Due to not requiring Unpin, it's not really possible to call it
after having polled it, you can only call it right after constructing it,
so in practice it's not very useful.
As per Tokio and others, this commit provides a `poll_flush` method on `AsyncWrite` so that a best-effort attempt at wakening once all bytes are flushed can be made.
467: docs: fix some `cargo doc` warnings r=lulf a=numero-744
There are still 3 warnings (below)
```
Documenting embassy v0.1.0 (embassy)
warning: unresolved link to `channel`
--> src/channel/mpsc.rs:241:22
|
241 | /// [`channel`]: channel
| ^^^^^^^ no item named `channel` in scope
|
= note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `Task::spawn`
--> src/executor/raw/mod.rs:105:12
|
105 | /// with [`Task::spawn()`], which will fail if it is already spawned.
| ^^^^^^^^^^^^^ no item named `Task` in scope
warning: public documentation for `spawn` links to private item `Executor::spawn`
--> src/executor/raw/mod.rs:156:17
|
156 | /// cause [`Executor::spawn()`] to return the error.
| ^^^^^^^^^^^^^^^^^ this item is private
|
= note: `#[warn(rustdoc::private_intra_doc_links)]` on by default
= note: this link will resolve properly if you pass `--document-private-items`
warning: `embassy` (lib doc) generated 3 warnings
```
Co-authored-by: Côme ALLART <come.allart@etu.emse.fr>
This prevents the std time driver from overflowing when setting the next
wakeup time. If an overflow occurs, default to sleeping up to 1 second.
Fixes#438
428: executor: Use critical sections instead of atomic CAS loops r=lulf a=Dirbaio
Optimize executor wakes.
CAS loops (either `fetch_update`, or manual `load + compare_exchange_weak`) generate surprisingly horrible code: https://godbolt.org/z/zhscnM1cb
This switches to using critical sections, which makes it faster. On thumbv6 (Cortex-M0) it should make it even faster, as it is currently using `atomic-polyfill`, which will make many critical sections for each `compare_exchange_weak` anyway.
```
opt-level=3 opt-level=s
atmics: 105 cycles 101 cycles
CS: 76 cycles 72 cycles
CS+inline: 72 cycles 64 cycles
```
Measured in nrf52 with icache disabled, with this code:
```rust
poll_fn(|cx| {
let task = unsafe { task_from_waker(cx.waker()) };
compiler_fence(Ordering::SeqCst);
let a = cortex_m::peripheral::DWT::get_cycle_count();
compiler_fence(Ordering::SeqCst);
unsafe { wake_task(task) }
compiler_fence(Ordering::SeqCst);
let b = cortex_m::peripheral::DWT::get_cycle_count();
compiler_fence(Ordering::SeqCst);
defmt::info!("cycles: {=u32}", b.wrapping_sub(a));
Poll::Ready(())
})
.await;
````
Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
That steal method has a TAKEN=true write [here](6b013138b7/src/peripheral/mod.rs (L180)).
This is not zero cost, we don't want it. Transmute instead, which is zero cost.
* Adds an executor for WASM runtimes based on wasm_bindgen.
* Add time driver based on JS time handling.
* Add example that can run in browser locally.
* Update to critical-section version that supports 'std' flag
Portal is very niche, I've only ever used it in `nrf-softdevice` and in a very particular case:
sending event raw-pointers across tasks but "synchronously", because the destination task must process
it now, so it's not deallocated. For most usecases, Signal or channels is enough.
It's unclear to me whether it can be made ub-free. It has problems with reentrancy. It's also not leak-safe, which is quite annoying.
So, remove it for now. We can always add it back later.
An MPSC inspired by Tokio and Crossbeam. The MPSC is designed to support both single and multi core processors, with only single core implemented at this time. The allocation of the channel’s buffer is inspired by the const generic parameters that Heapless provides.