File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change 42
42
/// Arrange to have the given future run on the current worker thread. The resulting `JoinHandle`
43
43
/// has `join` and `join_async` methods that can be used to wait for the given thread.
44
44
///
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.
47
54
///
48
55
/// # Panics
49
56
/// If this is called other than from a worker task running on a work thread, it will panic.
56
63
}
57
64
58
65
/// 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.)
60
67
pub fn yield_now ( ) -> impl Future < Output = ( ) > {
61
68
YieldNow { waited : false }
62
69
}
Original file line number Diff line number Diff line change @@ -56,7 +56,6 @@ pub struct MutexGuard<'a, T: ?Sized + 'a> {
56
56
_nosend : PhantomData < UnsafeCell < ( ) > > ,
57
57
}
58
58
59
- // unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
60
59
unsafe impl < T : ?Sized + Sync > Sync for MutexGuard < ' _ , T > { }
61
60
62
61
impl < T > Mutex < T > {
Original file line number Diff line number Diff line change 133
133
//! WORKER_STACK: ThreadStack<2048>;
134
134
//! }
135
135
//! // ...
136
- //! let main_worker = Box::new(j
136
+ //! let main_worker = Box::new(
137
137
//! WorkQueueBuilder::new()
138
138
//! .set_priority(2).
139
139
//! .set_name(c"mainloop")
@@ -309,7 +309,7 @@ impl WorkQueueBuilder {
309
309
/// // Leak a work queue in a Box.
310
310
/// let wq = Box::new(WorkQueueBuilder::new().start(...));
311
311
/// let _ = Box::leak(wq);
312
- ///
312
+ /// ```
313
313
pub struct WorkQueue {
314
314
#[ allow( dead_code) ]
315
315
item : Fixed < k_work_q > ,
@@ -335,7 +335,7 @@ impl Drop for WorkQueue {
335
335
/// The work queue is protected with a sync Mutex (which uses an underlying Zephyr mutex). It is,
336
336
/// in general, not a good idea to use a mutex in a work queue, as deadlock can happen. So it is
337
337
/// 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.
339
339
/// `insert` is usually done just at startup as well.
340
340
///
341
341
/// This is a little bit messy as we don't have a lazy mechanism, so we have to handle this a bit
You can’t perform that action at this time.
0 commit comments