diff options
| author | ckrenslehner <[email protected]> | 2025-04-26 20:07:30 +0200 |
|---|---|---|
| committer | ckrenslehner <[email protected]> | 2025-04-26 20:11:25 +0200 |
| commit | c2173591aa77ab7aa0a1b3d921883667fb9881f4 (patch) | |
| tree | 558b2c0a6dad1df3f6a570f4167e9e88cc7caaa0 | |
| parent | 572e788b2e878436bde527ad66cf561775cebc66 (diff) | |
docs: extend the waker documentation
| -rw-r--r-- | embassy-sync/README.md | 2 | ||||
| -rw-r--r-- | embassy-sync/src/waitqueue/atomic_waker.rs | 3 | ||||
| -rw-r--r-- | embassy-sync/src/waitqueue/atomic_waker_turbo.rs | 3 | ||||
| -rw-r--r-- | embassy-sync/src/waitqueue/multi_waker.rs | 2 | ||||
| -rw-r--r-- | embassy-sync/src/waitqueue/waker_registration.rs | 4 |
5 files changed, 13 insertions, 1 deletions
diff --git a/embassy-sync/README.md b/embassy-sync/README.md index 6871bcabc..91c59884f 100644 --- a/embassy-sync/README.md +++ b/embassy-sync/README.md | |||
| @@ -12,7 +12,7 @@ Synchronization primitives and data structures with async support: | |||
| 12 | - [`Mutex`](mutex::Mutex) - Mutex for synchronizing state between asynchronous tasks. | 12 | - [`Mutex`](mutex::Mutex) - Mutex for synchronizing state between asynchronous tasks. |
| 13 | - [`Pipe`](pipe::Pipe) - Byte stream implementing `embedded_io` traits. | 13 | - [`Pipe`](pipe::Pipe) - Byte stream implementing `embedded_io` traits. |
| 14 | - [`WakerRegistration`](waitqueue::WakerRegistration) - Utility to register and wake a `Waker`. | 14 | - [`WakerRegistration`](waitqueue::WakerRegistration) - Utility to register and wake a `Waker`. |
| 15 | - [`AtomicWaker`](waitqueue::AtomicWaker) - A variant of `WakerRegistration` accessible using a non-mut API. | 15 | - [`AtomicWaker`](waitqueue::AtomicWaker) - Utility to register and wake a `Waker` from interrupt context. |
| 16 | - [`MultiWakerRegistration`](waitqueue::MultiWakerRegistration) - Utility registering and waking multiple `Waker`'s. | 16 | - [`MultiWakerRegistration`](waitqueue::MultiWakerRegistration) - Utility registering and waking multiple `Waker`'s. |
| 17 | - [`LazyLock`](lazy_lock::LazyLock) - A value which is initialized on the first access | 17 | - [`LazyLock`](lazy_lock::LazyLock) - A value which is initialized on the first access |
| 18 | 18 | ||
diff --git a/embassy-sync/src/waitqueue/atomic_waker.rs b/embassy-sync/src/waitqueue/atomic_waker.rs index 231902c5a..5a9910e7f 100644 --- a/embassy-sync/src/waitqueue/atomic_waker.rs +++ b/embassy-sync/src/waitqueue/atomic_waker.rs | |||
| @@ -5,6 +5,9 @@ use crate::blocking_mutex::raw::{CriticalSectionRawMutex, RawMutex}; | |||
| 5 | use crate::blocking_mutex::Mutex; | 5 | use crate::blocking_mutex::Mutex; |
| 6 | 6 | ||
| 7 | /// Utility struct to register and wake a waker. | 7 | /// Utility struct to register and wake a waker. |
| 8 | /// If a waker is registered, registering another waker will replace the previous one without waking it. | ||
| 9 | /// Intended to wake a task from an interrupt. Therefore, it is generally not expected, | ||
| 10 | /// that multiple tasks register try to register a waker simultaneously. | ||
| 8 | pub struct GenericAtomicWaker<M: RawMutex> { | 11 | pub struct GenericAtomicWaker<M: RawMutex> { |
| 9 | waker: Mutex<M, Cell<Option<Waker>>>, | 12 | waker: Mutex<M, Cell<Option<Waker>>>, |
| 10 | } | 13 | } |
diff --git a/embassy-sync/src/waitqueue/atomic_waker_turbo.rs b/embassy-sync/src/waitqueue/atomic_waker_turbo.rs index 5c6a96ec8..c06b83056 100644 --- a/embassy-sync/src/waitqueue/atomic_waker_turbo.rs +++ b/embassy-sync/src/waitqueue/atomic_waker_turbo.rs | |||
| @@ -4,6 +4,9 @@ use core::sync::atomic::{AtomicPtr, Ordering}; | |||
| 4 | use core::task::Waker; | 4 | use core::task::Waker; |
| 5 | 5 | ||
| 6 | /// Utility struct to register and wake a waker. | 6 | /// Utility struct to register and wake a waker. |
| 7 | /// If a waker is registered, registering another waker will replace the previous one without waking it. | ||
| 8 | /// The intended use case is to wake tasks from interrupts. Therefore, it is generally not expected, | ||
| 9 | /// that multiple tasks register try to register a waker simultaneously. | ||
| 7 | pub struct AtomicWaker { | 10 | pub struct AtomicWaker { |
| 8 | waker: AtomicPtr<()>, | 11 | waker: AtomicPtr<()>, |
| 9 | } | 12 | } |
diff --git a/embassy-sync/src/waitqueue/multi_waker.rs b/embassy-sync/src/waitqueue/multi_waker.rs index 0e520bf40..0384d6bed 100644 --- a/embassy-sync/src/waitqueue/multi_waker.rs +++ b/embassy-sync/src/waitqueue/multi_waker.rs | |||
| @@ -3,6 +3,8 @@ use core::task::Waker; | |||
| 3 | use heapless::Vec; | 3 | use heapless::Vec; |
| 4 | 4 | ||
| 5 | /// Utility struct to register and wake multiple wakers. | 5 | /// Utility struct to register and wake multiple wakers. |
| 6 | /// Queue of wakers with a maximum length of `N`. | ||
| 7 | /// Intended for waking multiple tasks. | ||
| 6 | pub struct MultiWakerRegistration<const N: usize> { | 8 | pub struct MultiWakerRegistration<const N: usize> { |
| 7 | wakers: Vec<Waker, N>, | 9 | wakers: Vec<Waker, N>, |
| 8 | } | 10 | } |
diff --git a/embassy-sync/src/waitqueue/waker_registration.rs b/embassy-sync/src/waitqueue/waker_registration.rs index 9b666e7c4..7f24f8fb6 100644 --- a/embassy-sync/src/waitqueue/waker_registration.rs +++ b/embassy-sync/src/waitqueue/waker_registration.rs | |||
| @@ -2,6 +2,10 @@ use core::mem; | |||
| 2 | use core::task::Waker; | 2 | use core::task::Waker; |
| 3 | 3 | ||
| 4 | /// Utility struct to register and wake a waker. | 4 | /// Utility struct to register and wake a waker. |
| 5 | /// If a waker is registered, registering another waker will replace the previous one. | ||
| 6 | /// The previous waker will be woken in this case, giving it a chance to reregister itself. | ||
| 7 | /// Although it is possible to wake multiple tasks this way, | ||
| 8 | /// this will cause them to wake each other in a loop registering themselves. | ||
| 5 | #[derive(Debug, Default)] | 9 | #[derive(Debug, Default)] |
| 6 | pub struct WakerRegistration { | 10 | pub struct WakerRegistration { |
| 7 | waker: Option<Waker>, | 11 | waker: Option<Waker>, |
