Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
Clean up wait_for_* fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Oct 28, 2023
1 parent cf676d3 commit 88dcdc2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
2 changes: 1 addition & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4193,7 +4193,7 @@ impl Bank {
) {
// This is needed because recent_blockhash updates necessitate synchronizations for
// consistent tx check_age handling.
BankWithScheduler::wait_for_reusable_scheduler(self, scheduler);
BankWithScheduler::wait_for_paused_scheduler(self, scheduler);

// Only acquire the write lock for the blockhash queue on block boundaries because
// readers can starve this write lock acquisition and ticks would be slowed down too
Expand Down
41 changes: 21 additions & 20 deletions runtime/src/installed_scheduler_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,12 +299,23 @@ impl BankWithScheduler {

#[must_use]
pub fn wait_for_completed_scheduler(&self) -> Option<ResultWithTimings> {
self.inner
.wait_for_scheduler(WaitReason::TerminatedToFreeze)
BankWithSchedulerInner::wait_for_scheduler(
&self.inner.bank,
&self.inner.scheduler,
WaitReason::TerminatedToFreeze,
)
}

pub(crate) fn wait_for_reusable_scheduler(bank: &Bank, scheduler: &InstalledSchedulerRwLock) {
BankWithSchedulerInner::wait_for_reusable_scheduler(bank, scheduler);
pub(crate) fn wait_for_paused_scheduler(bank: &Bank, scheduler: &InstalledSchedulerRwLock) {
let maybe_result_with_timings = BankWithSchedulerInner::wait_for_scheduler(
bank,
scheduler,
WaitReason::PausedForRecentBlockhash,
);
assert!(
maybe_result_with_timings.is_none(),
"Premature result was returned from scheduler after paused"
);
}

// take needless &mut only to communicate its semantic mutability to humans...
Expand Down Expand Up @@ -338,12 +349,7 @@ impl BankWithScheduler {

impl BankWithSchedulerInner {
#[must_use]
fn wait_for_scheduler(&self, reason: WaitReason) -> Option<ResultWithTimings> {
Self::do_wait_for_scheduler(&self.bank, &self.scheduler, reason)
}

#[must_use]
fn do_wait_for_scheduler(
fn wait_for_scheduler(
bank: &Bank,
scheduler: &InstalledSchedulerRwLock,
reason: WaitReason,
Expand Down Expand Up @@ -379,17 +385,12 @@ impl BankWithSchedulerInner {

#[must_use]
fn wait_for_completed_scheduler_from_drop(&self) -> Option<Result<()>> {
let maybe_result_with_timings = self.wait_for_scheduler(WaitReason::DroppedFromBankForks);
maybe_result_with_timings.map(|(result, _timings)| result)
}

fn wait_for_reusable_scheduler(bank: &Bank, scheduler: &InstalledSchedulerRwLock) {
let maybe_result_with_timings =
Self::do_wait_for_scheduler(bank, scheduler, WaitReason::PausedForRecentBlockhash);
assert!(
maybe_result_with_timings.is_none(),
"Premature result was returned from scheduler after paused"
let maybe_result_with_timings = Self::wait_for_scheduler(
&self.bank,
&self.scheduler,
WaitReason::DroppedFromBankForks,
);
maybe_result_with_timings.map(|(result, _timings)| result)
}

fn drop_scheduler(&self) {
Expand Down
2 changes: 1 addition & 1 deletion scheduler-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,7 @@ mod tests {

fn wait_for_termination(&mut self, reason: &WaitReason) -> Option<ResultWithTimings> {
if TRIGGER_RACE_CONDITION && matches!(reason, WaitReason::PausedForRecentBlockhash) {
// this is equivalent to NOT calling wait_for_reusable_scheduler() in
// this is equivalent to NOT calling wait_for_paused_scheduler() in
// register_recent_blockhash().
return None;
}
Expand Down

0 comments on commit 88dcdc2

Please sign in to comment.