Skip to content

Commit

Permalink
Use extract_if polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
ryoqun committed Jun 9, 2024
1 parent 6ca2726 commit 05f5a25
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 17 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ trees = "0.4.2"
tungstenite = "0.20.1"
uriparse = "0.6.4"
url = "2.5.0"
vec_extract_if_polyfill = "0.1.0"
wasm-bindgen = "0.2"
winapi = "0.3.8"
winreg = "0.50"
Expand Down
7 changes: 7 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions unified-scheduler-pool/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ solana-program-runtime = { workspace = true }
solana-runtime = { workspace = true }
solana-sdk = { workspace = true }
solana-unified-scheduler-logic = { workspace = true }
vec_extract_if_polyfill = { workspace = true }

[dev-dependencies]
assert_matches = { workspace = true }
Expand Down
28 changes: 11 additions & 17 deletions unified-scheduler-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ use {
thread::{self, sleep, JoinHandle},
time::{Duration, Instant},
},
vec_extract_if_polyfill::MakeExtractIf,
};

mod sleepless_testing;
Expand Down Expand Up @@ -171,29 +172,22 @@ where
};

let idle_inner_count = {
let Ok(mut scheduler_inners) = scheduler_pool.scheduler_inners.lock() else {
break;
};
let mut inners = mem::take(&mut *scheduler_inners);
drop(scheduler_inners);

let now = Instant::now();
let old_inner_count = inners.len();
// retain could take long time because it's dropping schedulers!
inners.retain(|(_inner, pooled_at)| {
now.duration_since(*pooled_at) <= max_pooling_duration
});
let new_inner_count = inners.len();

let Ok(mut scheduler_inners) = scheduler_pool.scheduler_inners.lock() else {
break;
};
scheduler_inners.extend(inners);
// I want to use the fancy ::extract_if() no matter what....
#[allow(unstable_name_collisions)]
let idle_inners = scheduler_inners
.extract_if(|(_inner, pooled_at)| {
now.duration_since(*pooled_at) > max_pooling_duration
})
.collect::<Vec<_>>();
drop(scheduler_inners);

old_inner_count
.checked_sub(new_inner_count)
.expect("new_inner_count isn't larger")
let idle_inner_count = idle_inners.len();
drop(idle_inners);
idle_inner_count
};

let trashed_inner_count = {
Expand Down

0 comments on commit 05f5a25

Please sign in to comment.