forked from google/OpenSK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request google#60 from gendx/fix-dynamic-deferred-call
Import bugfix from tock/tock#1636 as a patch.
- Loading branch information
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
diff --git a/kernel/src/common/dynamic_deferred_call.rs b/kernel/src/common/dynamic_deferred_call.rs | ||
index 53f5143d..ca349972 100644 | ||
--- a/kernel/src/common/dynamic_deferred_call.rs | ||
+++ b/kernel/src/common/dynamic_deferred_call.rs | ||
@@ -226,23 +226,25 @@ impl DynamicDeferredCall { | ||
/// `call_global_instance_while`. | ||
pub(self) fn call_while<F: Fn() -> bool>(&self, f: F) { | ||
if self.call_pending.get() { | ||
- // Reset call_pending here, as it may be set again in the deferred calls | ||
- self.call_pending.set(false); | ||
+ for (i, client_state) in self.client_states.iter().enumerate() { | ||
+ if !f() { | ||
+ break; | ||
+ } | ||
+ if client_state.scheduled.get() { | ||
+ client_state.client.map(|client| { | ||
+ client_state.scheduled.set(false); | ||
+ client.call(DeferredCallHandle(i)); | ||
+ }); | ||
+ } | ||
+ } | ||
|
||
- self.client_states | ||
- .iter() | ||
- .enumerate() | ||
- .filter(|(_i, client_state)| client_state.scheduled.get()) | ||
- .filter_map(|(i, client_state)| { | ||
- client_state | ||
- .client | ||
- .map(|c| (i, &client_state.scheduled, *c)) | ||
- }) | ||
- .take_while(|_| f()) | ||
- .for_each(|(i, call_reqd, client)| { | ||
- call_reqd.set(false); | ||
- client.call(DeferredCallHandle(i)); | ||
- }); | ||
+ // Recompute call_pending here, as some deferred calls may have been skipped due to the | ||
+ // `f` predicate becoming false. | ||
+ self.call_pending.set( | ||
+ self.client_states | ||
+ .iter() | ||
+ .any(|client_state| client_state.scheduled.get()), | ||
+ ); | ||
} | ||
} | ||
} |