Skip to content

Commit

Permalink
fix(driver,poll,iour): use Arc::clone instead of try_clone
Browse files Browse the repository at this point in the history
  • Loading branch information
Berrysoft committed Oct 20, 2024
1 parent 39082ce commit cac6507
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions compio-driver/src/iour/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@ fn timespec(duration: std::time::Duration) -> Timespec {

#[derive(Debug)]
struct Notifier {
fd: OwnedFd,
fd: Arc<OwnedFd>,
}

impl Notifier {
/// Create a new notifier.
fn new() -> io::Result<Self> {
let fd = syscall!(libc::eventfd(0, libc::EFD_CLOEXEC | libc::EFD_NONBLOCK))?;
let fd = unsafe { OwnedFd::from_raw_fd(fd) };
Ok(Self { fd })
Ok(Self { fd: Arc::new(fd) })
}

pub fn clear(&self) -> io::Result<()> {
Expand All @@ -342,7 +342,7 @@ impl Notifier {
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
Ok(NotifyHandle::new(self.fd.try_clone()?))
Ok(NotifyHandle::new(self.fd.clone()))
}
}

Expand All @@ -354,11 +354,11 @@ impl AsRawFd for Notifier {

/// A notify handle to the inner driver.
pub struct NotifyHandle {
fd: OwnedFd,
fd: Arc<OwnedFd>,
}

impl NotifyHandle {
pub(crate) fn new(fd: OwnedFd) -> Self {
pub(crate) fn new(fd: Arc<OwnedFd>) -> Self {
Self { fd }
}

Expand Down
12 changes: 6 additions & 6 deletions compio-driver/src/poll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ fn entry_cancelled(user_data: usize) -> Entry {

struct Notifier {
notify_reader: os_pipe::PipeReader,
notify_writer: os_pipe::PipeWriter,
notify_writer: Arc<os_pipe::PipeWriter>,
}

impl Notifier {
Expand All @@ -343,12 +343,12 @@ impl Notifier {

Ok(Self {
notify_reader,
notify_writer,
notify_writer: Arc::new(notify_writer),
})
}

pub fn handle(&self) -> io::Result<NotifyHandle> {
Ok(NotifyHandle::new(self.notify_writer.try_clone()?))
Ok(NotifyHandle::new(self.notify_writer.clone()))
}

pub fn clear(&self) -> io::Result<()> {
Expand All @@ -367,16 +367,16 @@ impl Notifier {

/// A notify handle to the inner driver.
pub struct NotifyHandle {
sender: os_pipe::PipeWriter,
sender: Arc<os_pipe::PipeWriter>,
}

impl NotifyHandle {
fn new(sender: os_pipe::PipeWriter) -> Self {
fn new(sender: Arc<os_pipe::PipeWriter>) -> Self {
Self { sender }
}

/// Notify the inner driver.
pub fn notify(&self) -> io::Result<()> {
(&self.sender).write_all(&[1u8])
(&*self.sender).write_all(&[1u8])
}
}

0 comments on commit cac6507

Please sign in to comment.