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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
mod squeue;
mod cqueue;
use std::io;
use std::sync::atomic;
use crate::util::unsync_load;
pub use squeue::SubmissionQueue;
pub use cqueue::CompletionQueue;
pub struct IoUring {
ring: crate::IoUring,
mark: atomic::AtomicU32,
}
unsafe impl Send for IoUring {}
unsafe impl Sync for IoUring {}
impl IoUring {
pub fn new(ring: crate::IoUring) -> IoUring {
let mark = unsafe { unsync_load(ring.sq.tail) };
IoUring {
ring,
mark: atomic::AtomicU32::new(mark)
}
}
pub unsafe fn enter(&self, to_submit: u32, min_complete: u32, flag: u32, sig: Option<&libc::sigset_t>)
-> io::Result<usize>
{
self.ring.enter(to_submit, min_complete, flag, sig)
}
pub fn submit(&self) -> io::Result<usize> {
self.ring.submit()
}
pub fn submit_and_wait(&self, want: usize) -> io::Result<usize> {
self.ring.submit_and_wait(want)
}
pub fn submission(&self) -> SubmissionQueue<'_> {
SubmissionQueue {
queue: &self.ring.sq,
mark: &self.mark,
ring_mask: unsafe { self.ring.sq.ring_mask.read_volatile() },
ring_entries: unsafe { self.ring.sq.ring_entries.read_volatile() },
}
}
pub fn completion(&self) -> CompletionQueue<'_> {
CompletionQueue {
queue: &self.ring.cq,
ring_mask: unsafe { self.ring.cq.ring_mask.read_volatile() },
ring_entries: unsafe { self.ring.cq.ring_entries.read_volatile() }
}
}
pub fn into_inner(self) -> crate::IoUring {
self.ring
}
}