diff --git a/core/io/mod.rs b/core/io/mod.rs index e5f4a74bf..0698df9c6 100644 --- a/core/io/mod.rs +++ b/core/io/mod.rs @@ -3,7 +3,6 @@ use crate::storage::sqlite3_ondisk::WAL_FRAME_HEADER_SIZE; use crate::{BufferPool, CompletionError, Result}; use bitflags::bitflags; use cfg_block::cfg_block; -use parking_lot::Once; use std::cell::RefCell; use std::fmt; use std::ptr::NonNull; @@ -143,8 +142,6 @@ struct CompletionInner { // Thread safe with OnceLock result: std::sync::OnceLock>, needs_link: bool, - /// before calling callback we check if done is true - done: Once, /// Optional parent group this completion belongs to parent: OnceLock>, } @@ -298,7 +295,6 @@ impl Completion { completion_type, result: OnceLock::new(), needs_link: false, - done: Once::new(), parent: OnceLock::new(), }), } @@ -310,7 +306,6 @@ impl Completion { completion_type, result: OnceLock::new(), needs_link: true, - done: Once::new(), parent: OnceLock::new(), }), } @@ -420,7 +415,7 @@ impl Completion { } fn callback(&self, result: Result) { - self.inner.done.call_once(|| { + self.inner.result.get_or_init(|| { match &self.inner.completion_type { CompletionType::Read(r) => r.callback(result), CompletionType::Write(w) => w.callback(result), @@ -428,10 +423,6 @@ impl Completion { CompletionType::Truncate(t) => t.callback(result), CompletionType::Group(g) => g.callback(result), }; - self.inner - .result - .set(result.err()) - .expect("result must be set only once"); if let Some(group) = self.inner.parent.get() { // Capture first error in group @@ -447,6 +438,8 @@ impl Completion { } // TODO: remove self from parent group } + + result.err() }); } @@ -459,15 +452,6 @@ impl Completion { } } - /// only call this method if you are sure that the completion is - /// a WriteCompletion, panics otherwise - pub fn as_write(&self) -> &WriteCompletion { - match self.inner.completion_type { - CompletionType::Write(ref w) => w, - _ => unreachable!(), - } - } - /// Link this completion to a group completion (internal use only) fn link_internal(&mut self, group: &Completion) { let group_inner = match &group.inner.completion_type {