-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Submit trait and add Link struct for linked operations
- Loading branch information
Showing
19 changed files
with
174 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use pin_project_lite::pin_project; | ||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll}, | ||
}; | ||
|
||
use crate::{OneshotOutputTransform, Submit, UnsubmittedOneshot}; | ||
|
||
pub struct Link<D, N> { | ||
data: D, | ||
next: N, | ||
} | ||
|
||
impl<D, N> Link<D, N> { | ||
pub fn new(data: D, next: N) -> Self { | ||
Self { data, next } | ||
} | ||
} | ||
|
||
impl<D, N> Submit for Link<D, N> | ||
where | ||
D: Submit, | ||
N: Submit, | ||
{ | ||
type Output = LinkedInflightOneshot<D::Output, N::Output>; | ||
|
||
fn submit(self) -> Self::Output { | ||
LinkedInflightOneshot { | ||
data: self.data.submit(), | ||
next: Some(self.next.submit()), | ||
} | ||
} | ||
} | ||
|
||
impl<D1, T1: OneshotOutputTransform<StoredData = D1>, N> Link<UnsubmittedOneshot<D1, T1>, N> { | ||
pub fn link<D2, T2: OneshotOutputTransform<StoredData = D2>>( | ||
self, | ||
other: UnsubmittedOneshot<D2, T2>, | ||
) -> Link<UnsubmittedOneshot<D1, T1>, Link<N, UnsubmittedOneshot<D2, T2>>> { | ||
Link { | ||
data: self.data.set_flags(io_uring::squeue::Flags::IO_LINK), | ||
next: Link { | ||
data: self.next, | ||
next: other, | ||
}, | ||
} | ||
} | ||
|
||
pub fn hard_link<D2, T2: OneshotOutputTransform<StoredData = D2>>( | ||
self, | ||
other: UnsubmittedOneshot<D2, T2>, | ||
) -> Link<UnsubmittedOneshot<D1, T1>, Link<N, UnsubmittedOneshot<D2, T2>>> { | ||
Link { | ||
data: self.data.set_flags(io_uring::squeue::Flags::IO_LINK), | ||
next: Link { | ||
data: self.next, | ||
next: other, | ||
}, | ||
} | ||
} | ||
} | ||
|
||
pin_project! { | ||
pub struct LinkedInflightOneshot<D, N> { | ||
#[pin] | ||
data: D, | ||
next: Option<N>, | ||
} | ||
} | ||
|
||
impl<D, N> Future for LinkedInflightOneshot<D, N> | ||
where | ||
D: Future, | ||
{ | ||
type Output = (D::Output, N); | ||
|
||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
let this = self.project(); | ||
|
||
let output = ready!(this.data.poll(cx)); | ||
let next = this.next.take().unwrap(); | ||
|
||
Poll::Ready((output, next)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.