Skip to content

Commit 49c6712

Browse files
committed
zephyr: various comment cleanups from review suggestions
Fix some typos and clarify safety in a few places. Signed-off-by: David Brown <[email protected]>
1 parent 51547ba commit 49c6712

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

zephyr/src/kio.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ where
4242
/// Arrange to have the given future run on the current worker thread. The resulting `JoinHandle`
4343
/// has `join` and `join_async` methods that can be used to wait for the given thread.
4444
///
45-
/// The main use for this is to allow work threads to use `Rc` and `Rc<RefCell<T>>` within async
46-
/// tasks. The main constraint is that references inside cannot be held across an `.await`.
45+
/// By constraining the spawn to the current worker, this function is able to remove the Send
46+
/// constraint from the future (and its return type), allowing tasks to share data using
47+
/// lighter-weight mechanimsms, such as `Rc` and `Rc<RefCell<T>>`, or `&'static RefCell<T>`.
48+
///
49+
/// To be able to use tasks running on different workers, sharing must be done with types such as
50+
/// `Arc`, and `Arc<Mutex<T>>`, or `&'static Mutex<T>`.
51+
///
52+
/// It is important, when using RefCell, that a borrow from the cell not be carried across an await
53+
/// boundary, or RefCell's runtime multi-borrow check can cause a panic.
4754
///
4855
/// # Panics
4956
/// If this is called other than from a worker task running on a work thread, it will panic.
@@ -56,7 +63,7 @@ where
5663
}
5764

5865
/// Yield the current thread, returning it to the work queue to be run after other work on that
59-
/// queue. (This has to be called `yield_now` in Rust, because `yield` is a keyword.
66+
/// queue. (This has to be called `yield_now` in Rust, because `yield` is a keyword.)
6067
pub fn yield_now() -> impl Future<Output = ()> {
6168
YieldNow { waited: false }
6269
}

zephyr/src/kio/sync.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> {
5656
_nosend: PhantomData<UnsafeCell<()>>,
5757
}
5858

59-
// unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
6059
unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
6160

6261
impl<T> Mutex<T> {

zephyr/src/work.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
//! WORKER_STACK: ThreadStack<2048>;
134134
//! }
135135
//! // ...
136-
//! let main_worker = Box::new(j
136+
//! let main_worker = Box::new(
137137
//! WorkQueueBuilder::new()
138138
//! .set_priority(2).
139139
//! .set_name(c"mainloop")
@@ -309,7 +309,7 @@ impl WorkQueueBuilder {
309309
/// // Leak a work queue in a Box.
310310
/// let wq = Box::new(WorkQueueBuilder::new().start(...));
311311
/// let _ = Box::leak(wq);
312-
///
312+
/// ```
313313
pub struct WorkQueue {
314314
#[allow(dead_code)]
315315
item: Fixed<k_work_q>,
@@ -335,7 +335,7 @@ impl Drop for WorkQueue {
335335
/// The work queue is protected with a sync Mutex (which uses an underlying Zephyr mutex). It is,
336336
/// in general, not a good idea to use a mutex in a work queue, as deadlock can happen. So it is
337337
/// important to both never .await while holding the lock, as well as to make sure operations within
338-
/// it are relatively fast. In this case, `jnsert` and `get` on the SimpleTls are reasonably fast.
338+
/// it are relatively fast. In this case, `insert` and `get` on the SimpleTls are reasonably fast.
339339
/// `insert` is usually done just at startup as well.
340340
///
341341
/// This is a little bit messy as we don't have a lazy mechanism, so we have to handle this a bit

0 commit comments

Comments
 (0)