1- use crate :: runtime:: scheduler:: {
2- drop_hook:: DropHook , local_queue:: LocalQueue , send_wrapper:: SendWrapper ,
3- } ;
1+ use std:: { cell:: RefCell , future:: Future , marker:: PhantomData , rc:: Rc , sync:: Arc , task:: Waker } ;
2+
43use async_task:: { Runnable , Task } ;
54use compio_driver:: NotifyHandle ;
65use crossbeam_queue:: SegQueue ;
76use slab:: Slab ;
8- use std:: { cell:: RefCell , future:: Future , marker:: PhantomData , rc:: Rc , sync:: Arc , task:: Waker } ;
7+
8+ use crate :: runtime:: scheduler:: {
9+ drop_hook:: DropHook , local_queue:: LocalQueue , send_wrapper:: SendWrapper ,
10+ } ;
911
1012mod drop_hook;
1113mod local_queue;
@@ -28,8 +30,8 @@ impl TaskQueue {
2830
2931 /// Pushes a `Runnable` task to the appropriate queue.
3032 ///
31- /// If the current thread is the same as the creator thread, push to the local queue.
32- /// Otherwise, push to the sync queue.
33+ /// If the current thread is the same as the creator thread, push to the
34+ /// local queue. Otherwise, push to the sync queue.
3335 fn push ( & self , runnable : Runnable , notify : & NotifyHandle ) {
3436 if let Some ( local_queue) = self . local_queue . get ( ) {
3537 local_queue. push ( runnable) ;
@@ -41,7 +43,8 @@ impl TaskQueue {
4143 }
4244 }
4345
44- /// Pops at most one task from each queue and returns them as `(local_task, sync_task)`.
46+ /// Pops at most one task from each queue and returns them as `(local_task,
47+ /// sync_task)`.
4548 ///
4649 /// # Safety
4750 ///
@@ -52,7 +55,8 @@ impl TaskQueue {
5255
5356 let local_task = local_queue. pop ( ) ;
5457
55- // Perform an empty check as a fast path, since `SegQueue::pop()` is more expensive.
58+ // Perform an empty check as a fast path, since `SegQueue::pop()` is more
59+ // expensive.
5660 let sync_task = if self . sync_queue . is_empty ( ) {
5761 None
5862 } else {
@@ -145,13 +149,15 @@ impl Scheduler {
145149 } ;
146150
147151 let schedule = {
148- // The schedule closure is managed by the `Waker` and may be dropped on another thread,
149- // so use `Weak` to ensure the `TaskQueue` is always dropped on the creator thread.
152+ // The schedule closure is managed by the `Waker` and may be dropped on another
153+ // thread, so use `Weak` to ensure the `TaskQueue` is always dropped
154+ // on the creator thread.
150155 let task_queue = Arc :: downgrade ( & self . task_queue ) ;
151156
152157 move |runnable| {
153- // The `upgrade()` never fails because all tasks are dropped when the `Scheduler` is dropped,
154- // if a `Waker` is used after that, the schedule closure will never be called.
158+ // The `upgrade()` never fails because all tasks are dropped when the
159+ // `Scheduler` is dropped, if a `Waker` is used after that, the
160+ // schedule closure will never be called.
155161 task_queue. upgrade ( ) . unwrap ( ) . push ( runnable, & notify) ;
156162 }
157163 } ;
@@ -216,8 +222,9 @@ impl Scheduler {
216222 // Then drop all scheduled tasks, which will drop all futures.
217223 //
218224 // SAFETY:
219- // Since spawned tasks are not required to be `Send`, they must always be dropped
220- // on the same thread. Because `Scheduler` is `!Send` and `!Sync`, this is safe.
225+ // Since spawned tasks are not required to be `Send`, they must always be
226+ // dropped on the same thread. Because `Scheduler` is `!Send` and
227+ // `!Sync`, this is safe.
221228 //
222229 // This method is only called on `TaskQueue`'s creator thread
223230 // because `Scheduler` is `!Send` and `!Sync`.
0 commit comments