From 262799dfec73e1dc8b7222badb07ed9987747338 Mon Sep 17 00:00:00 2001 From: Nazar Mokrynskyi Date: Sat, 14 Oct 2023 09:01:47 +0300 Subject: [PATCH] Use tokio's `yield_now` instead of manually written future --- .../src/plotting.rs | 33 ++----------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/crates/subspace-farmer-components/src/plotting.rs b/crates/subspace-farmer-components/src/plotting.rs index cf64f72d34..b218d2c612 100644 --- a/crates/subspace-farmer-components/src/plotting.rs +++ b/crates/subspace-farmer-components/src/plotting.rs @@ -12,12 +12,9 @@ use futures::stream::FuturesUnordered; use futures::StreamExt; use parity_scale_codec::Encode; use std::error::Error; -use std::future::Future; use std::mem; -use std::pin::Pin; use std::simd::Simd; use std::sync::Arc; -use std::task::{Context, Poll}; use std::time::Duration; use subspace_core_primitives::crypto::kzg::Kzg; use subspace_core_primitives::crypto::{blake3_hash, blake3_hash_parallel, Scalar}; @@ -29,6 +26,7 @@ use subspace_erasure_coding::ErasureCoding; use subspace_proof_of_space::{Quality, Table, TableGenerator}; use thiserror::Error; use tokio::sync::Semaphore; +use tokio::task::yield_now; use tracing::{debug, trace, warn}; const RECONSTRUCTION_CONCURRENCY_LIMIT: usize = 1; @@ -195,33 +193,6 @@ where pub table_generator: &'a mut PosTable::Generator, } -/// A future that will always `yield` on the first call of `poll` but schedules the current task for -/// re-execution. -/// -/// This is done by getting the waker and calling `wake_by_ref` followed by returning `Pending`. The -/// next time the `poll` is called, it will return `Ready`. -struct Yield(bool); - -impl Yield { - fn new() -> Self { - Self(false) - } -} - -impl Future for Yield { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { - if !self.0 { - self.0 = true; - cx.waker().wake_by_ref(); - Poll::Pending - } else { - Poll::Ready(()) - } - } -} - /// Plot a single sector. /// /// NOTE: Even though this function is async, it has blocking code inside and must be running in a @@ -423,7 +394,7 @@ where }); // Give a chance to interrupt plotting if necessary in between pieces - Yield::new().await + yield_now().await } sector_output.resize(sector_size, 0);