8000 Replace the local worker queues with st3's by james7132 · Pull Request #115 · smol-rs/async-executor · GitHub
[go: up one dir, main page]

Skip to content

Replace the local worker queues with st3's #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add back in the self-stealing avoidance
  • Loading branch information
james7132 committed Apr 22, 2024
commit 0579b9ebd36ef9c2f1ed52c38d664c11b1fbb2f3
9 changes: 7 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
html_logo_url = "https://raw.githubusercontent.com/smol-rs/smol/master/assets/images/logo_fullsize_transparent.png"
)]

use st3::fifo::{Stealer, Worker};
use std::fmt;
use std::marker::PhantomData;
use std::panic::{RefUnwindSafe, UnwindSafe};
use std::rc::Rc;
use std::sync::atomic::{AtomicBool, AtomicPtr, Ordering};
use std::sync::{Arc, Mutex, RwLock, TryLockError};
use std::task::{Poll, Waker};
use st3::fifo::{Worker, Stealer};

use async_task::{Builder, Runnable};
use concurrent_queue::ConcurrentQueue;
Expand Down Expand Up @@ -983,6 +983,10 @@ impl Runner<'_> {
.skip(start)
.take(n);

// Remove this runner's local queue.
let local_stealer = self.local.stealer_ref();
let iter = iter.filter(|local| !core::ptr::eq(*local, local_stealer));

// Try stealing from each local queue in the list.
for local in iter {
let count_fn = |remaining| remaining / 2;
Expand Down Expand Up @@ -1028,9 +1032,10 @@ impl Drop for Runner<'_> {
fn steal<T>(src: &ConcurrentQueue<T>, dest: &Worker<T>) {
// Half of `src`'s length rounded up.
let mut count = (src.len() + 1) / 2;
count = count.min(dest.spare_capacity());

if count > 0 {
count = count.min(dest.spare_capacity());

// Steal tasks.
for t in src.try_iter().take(count) {
assert!(dest.push(t).is_ok());
Expand Down
0