Skip to content

Commit

Permalink
control: (rpc) try spinning until all futures in the batch resolve as…
Browse files Browse the repository at this point in the history
… our reset strategy

re: #48
  • Loading branch information
rrbutani committed Mar 10, 2020
1 parent f97b9b1 commit 4e7d28a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
17 changes: 16 additions & 1 deletion baseline-sim/src/sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,22 @@ where
fn reset(&mut self) {
self.state = State::Paused;
InstructionInterpreter::reset(&mut self.interp);
self.shared_state.as_ref().map(|s| s.reset());
self.state = State::Paused;

// // As mentioned in control/rpc/controller.rs: For now, we're handling
// // this by having the controller block until all current futures resolve
// // themselves. See the comment in rpc/futures.rs on
// // `EventFutureSharedState::reset` for more details.
// //
// // Real implementors of `Control::reset` should call pause before
// // calling reset! Otherwise this spin lock will never exit.
// if let Some(shared_state) = self.shared_state.as_ref() {
// while !shared_state.is_clean() {
// core::sync::atomic::spin_loop_hint();
// }

// shared_state.reset();
// }
}

fn get_error(&self) -> Option<Error> {
Expand Down
11 changes: 10 additions & 1 deletion traits/src/control/rpc/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,16 @@ where
fn reset(&mut self) {
// Drop all pending futures:
// (if one of these futures is polled again, bad bad things will happen; TODO)
self.shared_state.reset();

// For now, we're handling this by having the controller block until all
// current futures resolve themselves. See the comment in rpc/futures.rs
// on `EventFutureSharedState::reset` for more details.
//
// Real implementors of `Control::reset` should call pause before
// calling reset! Otherwise this spin lock will never exit.
// while !self.shared_state.is_clean() { core::sync::atomic::spin_loop_hint(); }

// self.shared_state.reset();

ctrl!(self, Reset, R::Reset)
}
Expand Down
4 changes: 3 additions & 1 deletion traits/src/control/rpc/futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ impl SharedStateState {
}

fn reset(&mut self) {
*self = SharedStateState::Dormant; // TODO: currently pending futures!
assert!(self.is_clean(), "Tried to reset before all Futures resolved!");

*self = SharedStateState::Dormant;
}
}

Expand Down

0 comments on commit 4e7d28a

Please sign in to comment.