@@ -32,7 +32,7 @@ static VTABLE: RawWakerVTable = {
32
32
wake_by_ref ( p)
33
33
}
34
34
unsafe fn wake_by_ref ( p : * const ( ) ) {
35
- ( * ( p as * const AtomicBool ) ) . store ( true , Ordering :: Relaxed )
35
+ ( * ( p as * const AtomicBool ) ) . store ( true , Ordering :: Release )
36
36
}
37
37
unsafe fn drop ( _: * const ( ) ) {
38
38
// no-op
@@ -66,9 +66,12 @@ impl Executor {
66
66
let waker =
67
67
unsafe { Waker :: from_raw ( RawWaker :: new ( & ready as * const _ as * const _ , & VTABLE ) ) } ;
68
68
let val = loop {
69
+ let mut task_woken = false ;
70
+
69
71
// advance the main task
70
- if ready. load ( Ordering :: Relaxed ) {
71
- ready. store ( false , Ordering :: Relaxed ) ;
72
+ if ready. load ( Ordering :: Acquire ) {
73
+ task_woken = true ;
74
+ ready. store ( false , Ordering :: Release ) ;
72
75
73
76
let mut cx = Context :: from_waker ( & waker) ;
74
77
if let Poll :: Ready ( val) = f. as_mut ( ) . poll ( & mut cx) {
@@ -87,9 +90,11 @@ impl Executor {
87
90
// interrupt handlers (the only source of 'race conditions' (!= data races)) are
88
91
// "oneshot": they'll issue a `wake` and then disable themselves to not run again
89
92
// until the woken task has made more work
90
- if task. ready . load ( Ordering :: Relaxed ) {
93
+ if task. ready . load ( Ordering :: Acquire ) {
94
+ task_woken = true ;
95
+
91
96
// we are about to service the task so switch the `ready` flag to `false`
92
- task. ready . store ( false , Ordering :: Relaxed ) ;
97
+ task. ready . store ( false , Ordering :: Release ) ;
93
98
94
99
// NOTE we never deallocate tasks so `&ready` is always pointing to
95
100
// allocated memory (`&'static AtomicBool`)
@@ -108,6 +113,11 @@ impl Executor {
108
113
}
109
114
}
110
115
116
+ if task_woken {
117
+ // If at least one task was woken up, do not sleep, try again
118
+ continue ;
119
+ }
120
+
111
121
// try to sleep; this will be a no-op if any of the previous tasks generated a SEV or an
112
122
// interrupt ran (regardless of whether it generated a wake-up or not)
113
123
asm:: wfe ( ) ;
0 commit comments