1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//! Provides a [`NopSubmitter`] which can be used to submit nop operations to
//! the ring. This is mainly useful for benchmarking Glommio.
use std::{
io,
rc::{Rc, Weak},
};
use crate::{parking::Reactor, Local};
/// Submit no-op operations to io_uring.
///
/// This is mainly useful for benchmarking Glommio.
#[derive(Debug)]
pub struct NopSubmitter {
reactor: Weak<Reactor>,
}
impl NopSubmitter {
/// Construct a new [`NopSubmitter`].
pub fn new() -> Self {
Self::default()
}
/// Submit a no-op io_uring operation, and wait for completion.
pub async fn run_nop(&self) -> io::Result<()> {
let reactor = self.reactor.upgrade().unwrap();
let source = reactor.nop();
source.collect_rw().await?;
Ok(())
}
}
impl Default for NopSubmitter {
fn default() -> Self {
let reactor = Local::get_reactor();
let reactor = Rc::downgrade(&reactor);
Self { reactor }
}
}