Skip to content
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

runtime: move the task out of the lifo_slot in block_in_place #6596

Merged
Merged
Changes from all commits
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
10 changes: 9 additions & 1 deletion tokio/src/runtime/scheduler/multi_thread/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,19 @@ where
let cx = maybe_cx.expect("no .is_some() == false cases above should lead here");

// Get the worker core. If none is set, then blocking is fine!
let core = match cx.core.borrow_mut().take() {
let mut core = match cx.core.borrow_mut().take() {
Some(core) => core,
None => return Ok(()),
};

// If we heavily call `spawn_blocking`, there might be no available thread to
// run this core. Except for the task in the lifo_slot, all tasks can be
// stolen, so we move the task out of the lifo_slot to the run_queue.
if let Some(task) = core.lifo_slot.take() {
core.run_queue
.push_back_or_overflow(task, &*cx.worker.handle, &mut core.stats);
}

// We are taking the core from the context and sending it to another
// thread.
take_core = true;
Expand Down
Loading