diff --git a/src/io_uring/ops/async_cancel.rs b/src/io_uring/ops/async_cancel.rs index 4d26dca7..d322fd3b 100644 --- a/src/io_uring/ops/async_cancel.rs +++ b/src/io_uring/ops/async_cancel.rs @@ -6,33 +6,28 @@ use { }, utils::errorfmt::ErrorFmt, }, - std::cell::Cell, uapi::c, }; +#[derive(Default)] pub struct AsyncCancelTask { - id: Cell, - target: Cell, + id: u64, + target: u64, } impl IoUringData { pub fn cancel_task_in_kernel(&self, target: u64) { - let task = self.cached_cancels.pop().unwrap_or_else(|| { - Box::new(AsyncCancelTask { - id: Cell::new(0), - target: Cell::new(0), - }) - }); let id = self.id_raw(); - task.id.set(id); - task.target.set(target); + let mut task = self.cached_cancels.pop().unwrap_or_default(); + task.id = id; + task.target = target; self.schedule(task); } } unsafe impl Task for AsyncCancelTask { fn id(&self) -> u64 { - self.id.get() + self.id } fn complete(self: Box, ring: &IoUringData, res: i32) { @@ -46,7 +41,7 @@ unsafe impl Task for AsyncCancelTask { fn encode(&self, sqe: &mut io_uring_sqe) { sqe.opcode = IORING_OP_ASYNC_CANCEL; - sqe.u2.addr = self.target.get(); + sqe.u2.addr = self.target; } fn is_cancel(&self) -> bool { diff --git a/src/io_uring/ops/poll.rs b/src/io_uring/ops/poll.rs index e6f266a3..c10f0893 100644 --- a/src/io_uring/ops/poll.rs +++ b/src/io_uring/ops/poll.rs @@ -5,10 +5,7 @@ use { sys::{io_uring_sqe, IORING_OP_POLL_ADD}, IoUring, IoUringData, IoUringError, Task, TaskResultExt, }, - std::{ - cell::{Cell, RefCell}, - rc::Rc, - }, + std::rc::Rc, uapi::{c, OwnedFd}, }; @@ -18,12 +15,13 @@ impl IoUring { let id = self.ring.id(); let pr = self.ring.pending_results.acquire(); { - let pw = self.ring.cached_polls.pop().unwrap_or_default(); - pw.id.set(id.id); - *pw.data.borrow_mut() = Some(Data { + let mut pw = self.ring.cached_polls.pop().unwrap_or_default(); + pw.id = id.id; + pw.fd = fd.raw() as _; + pw.events = events as _; + pw.data = Some(Data { pr: pr.clone(), - fd: fd.clone(), - events: events as _, + _fd: fd.clone(), }); self.ring.schedule(pw); } @@ -41,34 +39,32 @@ impl IoUring { struct Data { pr: PendingResult, - fd: Rc, - events: u16, + _fd: Rc, } #[derive(Default)] pub struct PollTask { - id: Cell, - data: RefCell>, + id: u64, + events: u16, + fd: i32, + data: Option, } unsafe impl Task for PollTask { fn id(&self) -> u64 { - self.id.get() + self.id } - fn complete(self: Box, ring: &IoUringData, res: i32) { - let data = self.data.borrow_mut().take(); - if let Some(data) = data { + fn complete(mut self: Box, ring: &IoUringData, res: i32) { + if let Some(data) = self.data.take() { data.pr.complete(res); } ring.cached_polls.push(self); } fn encode(&self, sqe: &mut io_uring_sqe) { - let data = self.data.borrow_mut(); - let data = data.as_ref().unwrap(); sqe.opcode = IORING_OP_POLL_ADD; - sqe.fd = data.fd.raw(); - sqe.u3.poll_events = data.events; + sqe.fd = self.fd; + sqe.u3.poll_events = self.events; } } diff --git a/src/io_uring/ops/recvmsg.rs b/src/io_uring/ops/recvmsg.rs index aaa4c864..c1546cbc 100644 --- a/src/io_uring/ops/recvmsg.rs +++ b/src/io_uring/ops/recvmsg.rs @@ -124,7 +124,7 @@ unsafe impl Task for RecvmsgTask { fn encode(&self, sqe: &mut io_uring_sqe) { sqe.opcode = IORING_OP_RECVMSG; - sqe.fd = self.fd; + sqe.fd = self.fd as _; sqe.u2.addr = &self.msghdr as *const _ as _; sqe.u3.msg_flags = c::MSG_CMSG_CLOEXEC as _; } diff --git a/src/io_uring/ops/write.rs b/src/io_uring/ops/write.rs index 23e1b82d..6453dc25 100644 --- a/src/io_uring/ops/write.rs +++ b/src/io_uring/ops/write.rs @@ -10,7 +10,7 @@ use { utils::buf::Buf, }, std::rc::Rc, - uapi::OwnedFd, + uapi::{c, OwnedFd}, }; impl IoUring { @@ -27,9 +27,12 @@ impl IoUring { let mut pw = self.ring.cached_writes.pop().unwrap_or_default(); pw.id = id.id; pw.has_timeout = timeout.is_some(); + pw.fd = fd.raw(); + pw.buf = buf.as_ptr() as _; + pw.len = buf.len(); pw.data = Some(WriteTaskData { - fd: fd.clone(), - buf, + _fd: fd.clone(), + _buf: buf, res: pr.clone(), }); self.ring.schedule(pw); @@ -42,8 +45,8 @@ impl IoUring { } struct WriteTaskData { - fd: Rc, - buf: Buf, + _fd: Rc, + _buf: Buf, res: PendingResult, } @@ -51,6 +54,9 @@ struct WriteTaskData { pub struct WriteTask { id: u64, has_timeout: bool, + fd: c::c_int, + buf: usize, + len: usize, data: Option, } @@ -63,17 +69,16 @@ unsafe impl Task for WriteTask { if let Some(data) = self.data.take() { data.res.complete(res); } - ring.clone().cached_writes.push(self); + ring.cached_writes.push(self); } fn encode(&self, sqe: &mut io_uring_sqe) { - let data = self.data.as_ref().unwrap(); sqe.opcode = IORING_OP_WRITE; - sqe.fd = data.fd.raw(); + sqe.fd = self.fd as _; sqe.u1.off = !0; - sqe.u2.addr = data.buf.as_ptr() as _; + sqe.u2.addr = self.buf as _; sqe.u3.rw_flags = 0; - sqe.len = data.buf.len() as _; + sqe.len = self.len as _; } fn has_timeout(&self) -> bool {